Datalogger that reads temperature, humidity and light level every couple of seconds, and store the data in a microSD card (.CSV file).

Dependencies:   DS1302 SDFileSystem mbed

Fork of temp_humid_time_DS1302_LM35_DHT11 by Clovis Fritzen

This is a weather station/datalogger using a Freescale FRDM-K64F dev board, a LM35 (temperature sensor), a DHT11 (temperature and humidity sensor), a DS1302 (timekeeper module) and a LDR (light level sensor). All the data is periodically stored on a microSDHC card; The acquisition period is adjustable via software (by setting the value of a counter).

There is also (commented) code for sending all these information via serial to a terminal on PC.

Full explanation, details and schematics can be found here: http://embedded-clovis.blogspot.ca/2014/07/temperature-datalogger-with-arm-cortex.html

Files at this revision

API Documentation at this revision

Comitter:
Clovis
Date:
Thu Jul 24 18:44:48 2014 +0000
Parent:
0:8f0934e41a57
Commit message:
Initial release for the FRDM-K64F group

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8f0934e41a57 -r 4b3e952a1406 main.cpp
--- a/main.cpp	Fri Jul 04 08:08:38 2014 +0000
+++ b/main.cpp	Thu Jul 24 18:44:48 2014 +0000
@@ -11,6 +11,7 @@
 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); //MOSI, MISO, SCLK, SSEL. (SD Card) Tested on K64F, correct pins.
 AnalogIn LM35(PTB2);
 AnalogIn LDR(PTB3);
+AnalogIn SolarPanel(PTB10);
 int count=0;
 float ldrcalc= 0.00;
 DigitalOut RedLed(LED1); // Error indication
@@ -22,7 +23,7 @@
 int main() {
     // the 6 lines below are for the time keeper chip
     #ifdef INITIAL_RUN
-    clk.set_time(1403949720);
+    clk.set_time(1406017928);
     #endif
     
     char storedByte = clk.recallByte(0);
@@ -37,19 +38,22 @@
  
     mkdir("/sd/dados", 0777);
     
-    FILE *fp = fopen("/sd/dados/data001.csv", "w");
+    FILE *fp = fopen("/sd/dados/data004.csv", "a");
     if(fp == NULL) {
         error("Could not open file for write\n");
         RedLed= 0;
         
         }
+        fprintf(fp, "%s\r,", "--------------"); 
+    fclose(fp);  
+    
     while (1) {
     
     Blueled= 1;
     RedLed= 1;
     GreenLed= 1;
     
-   if (count < 12000000){
+   if (count < 5000000){ //around 10 seconds before it reaches the count of 12000000
         count++;
         } else{  
         // --------------------------
@@ -68,17 +72,17 @@
             printf("\r\nErr %i \n",err);
             
         // ----------------------------  
-    FILE *fp = fopen("/sd/dados/data001.csv", "a");
+    FILE *fp = fopen("/sd/dados/data004.csv", "a");
     if(fp == NULL) {
         error("Could not open file for write\n");
         
        }
     
     ldrcalc= LDR.read();
-    ldrcalc= (1/ldrcalc)-1;
+    ldrcalc= (1/ldrcalc)-1; //Transforms the LDR value into a 0-5 signal (integer)
     time_t seconds = clk.time(NULL);
     //fprintf(fp, "%s\r,%f,%f,%f\n", "LM35", "DHT11", "Humid", "Month", "Day", "Hour", "Year");
-    fprintf(fp, "%s\r,%f,%f,%f,%f", ctime(&seconds), 333.333*LM35.read(), sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity(), ldrcalc); 
+    fprintf(fp, "%s\r,%f,%f,%f,%f,%f", ctime(&seconds), 333.333*LM35.read(), SolarPanel.read(), sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity(), ldrcalc); 
     fclose(fp);  
     //printf("Goodbye World!\n");
     count=0;