This a domestic weather station that measures temperature, humidity and light and stores the data in a .csv file in SD card.
Dependencies: DS1302 SDFileSystem mbed
Fork of temp_humid_light_time_DS1302_LM35_DHT11_LDR by
Revision 2:02668481aebc, committed 2016-03-27
- Comitter:
- nivmukka
- Date:
- Sun Mar 27 04:18:07 2016 +0000
- Parent:
- 1:4b3e952a1406
- Commit message:
- Domestic weather station that measures temperature, humidity and light.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4b3e952a1406 -r 02668481aebc main.cpp --- a/main.cpp Thu Jul 24 18:44:48 2014 +0000 +++ b/main.cpp Sun Mar 27 04:18:07 2016 +0000 @@ -20,73 +20,78 @@ DHT sensor(PTB20,DHT11); // Use the DHT11 sensor, on pin DS1302 clk(SCLK, IO, PTB18); // ports for the DS1302 time keeper -int main() { +int main() +{ // the 6 lines below are for the time keeper chip #ifdef INITIAL_RUN clk.set_time(1406017928); #endif - char storedByte = clk.recallByte(0); - //printf("\r\nStored byte was %d, now increasing by one\r\n", storedByte); + char storedByte = clk.recallByte(0); clk.storeByte(0, storedByte + 1); - // - + int err; wait(1); // wait 1 second for DHT11 to stabilyze - //printf("Hello World!\n"); mkdir("/sd/dados", 0777); FILE *fp = fopen("/sd/dados/data004.csv", "a"); - if(fp == NULL) { + if(fp == NULL) + { error("Could not open file for write\n"); - RedLed= 0; - - } - fprintf(fp, "%s\r,", "--------------"); + RedLed= 0; + } + + fprintf(fp, "%s,", "--------------\n"); fclose(fp); - while (1) { + while (1) + { - Blueled= 1; - RedLed= 1; - GreenLed= 1; + Blueled= 1; + RedLed= 1; + GreenLed= 1; - if (count < 5000000){ //around 10 seconds before it reaches the count of 12000000 - count++; - } else{ - // -------------------------- - - err = sensor.readData(); - if (err == 0) { - GreenLed= 0; - printf("Temperature is %4.2f \r\n",sensor.ReadTemperature(CELCIUS)); - //printf("Temperature is %4.2f F \r\n",sensor.ReadTemperature(FARENHEIT)); - //printf("Temperature is %4.2f K \r\n",sensor.ReadTemperature(KELVIN)); - printf("Humidity is %4.2f \r\n",sensor.ReadHumidity()); - //printf("Dew point is %4.2f \r\n",sensor.CalcdewPoint(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); - //printf("Dew point (fast) is %4.2f \r\n",sensor.CalcdewPointFast(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); + if (count < 5000000) //around 10 seconds before it reaches the count of 12000000 + { + count++; + } + else + { + err = sensor.readData(); + if (err == 0) + { + GreenLed= 0; + printf("\r\nTemperature in celsius is %4.2f C \r\n",sensor.ReadTemperature(CELCIUS)); + printf("Temperature in farenheit is %4.2f F \r\n",sensor.ReadTemperature(FARENHEIT)); + printf("Temperature in kelvin is %4.2f K \r\n",sensor.ReadTemperature(KELVIN)); + printf("Humidity is %4.2f \r\n",sensor.ReadHumidity()); + printf("Dew point is %4.2f \r\n",sensor.CalcdewPoint(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); + printf("Dew point (fast) is %4.2f \r\n",sensor.CalcdewPointFast(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); + } + else + { + printf("\nErr %i \r\n",err); + } + + FILE *fp = fopen("/sd/dados/data004.csv", "a"); - } else - printf("\r\nErr %i \n",err); - - // ---------------------------- - FILE *fp = fopen("/sd/dados/data004.csv", "a"); - if(fp == NULL) { - error("Could not open file for write\n"); - - } + if(fp == NULL) + { + error("Could not open file for write\n"); + } - ldrcalc= LDR.read(); - 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,%f", ctime(&seconds), 333.333*LM35.read(), SolarPanel.read(), sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity(), ldrcalc); - fclose(fp); - //printf("Goodbye World!\n"); - count=0; - Blueled= 0; + ldrcalc= LDR.read(); + 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,%f", ctime(&seconds), 333.333*LM35.read(), SolarPanel.read(), sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity(), ldrcalc); + fclose(fp); + printf("\n--------------------------------------------------\n"); + + count=0; + Blueled= 0; + } } - } - } \ No newline at end of file + } \ No newline at end of file