Data Logger - Temperature, Humidity and Light Level
 Show and Tell   Started by Daniel Alich   2017-04-17 19:09:51 -04:00   Comments: 1    Viewed: 300

  1. Daniel Alich
    Daniel Alich Member Staff Member
     
    Here is a fun little project we desgined with the 2017 Eclipse in mind.  This project will act as a monitor and data recorder for Temperature, Humidity and light level and report a reading every 5 seconds.
     
    The data will be relayed back you you computer via the USB cable and into the serial mointor.  Data can easily be copied and pasted into a spreadsheet for a cool graph of the events.

    Wiring instructions and information for setting the clock are included in the code.  This project can easily be built on the DuinoKit Jr. or DuinoKit Essentials.

    252_1503076001_Eclipse Monitor_bb.png

    252_1503076013_Screenshot from 2017-08-1


    252_1503076028_sample_data.png


    /***************************

    | |

    | Eclipse Monitor |

    | by Isaac A. |

    | |

    | Wiring Guide: |

    | Arduino A4 --> RTC SDA |

    | Arduino A5 --> RTC SCL |

    | Arduino A7 --> CDS Cell |

    | Arduino D2 --> LCD D7 |

    | Arduino D3 --> LCD D6 |

    | Arduino D4 --> LCD D5 |

    | Arduino D5 --> LCD D4 |

    | Arduino D11 --> LCD E |

    | Arduino D12 --> LCD RS |

    | All VCC --> Arduino 5V |

    | All GND --> Arduino GND |

    | |

    | The Arduino outputs data |

    | to the serial monitor |

    | in CSV format, and can |

    | be used in Excel. |

    | |

    | You may need to adjust |

    | your real-time clock. |

    | |

    ****************************/

     

    #include

    #include "dht.h"

    #include

    #include "RTClib.h"

     

    #define DHTPIN 8

    dht DHT;

     

    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

     

    #define CDSPIN A7

    int cdsval;

     

    RTC_DS1307 rtc;

    char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

     

    void setup() {

    lcd.begin(16, 2);

    Serial.begin(9600);

     

    if(!rtc.begin()) {

    Serial.println("Couldn't find RTC");

    while (1);

    }

     

    if(!rtc.isrunning()) {

    Serial.println("RTC is NOT running!");

    //Following line sets the RTC to the date & time this sketch was compiled
    //Remove the "//" in front of the following line, upload, then replace "//" and upload again.
    //This will set the clock moodule for the current computer and then retain currentl time when restarted.

    //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

    }

     

    //Printing CSV Headers

    Serial.println("Time,Humidity,Temperature,Light Level");

    }

     

    void loop() {

    int chk = DHT.read11(DHTPIN);

    switch (chk) {

    case DHTLIB_OK:

    break;

    case DHTLIB_ERROR_CHECKSUM:

    Serial.println("DHT: Checksum error");

    break;

    case DHTLIB_ERROR_TIMEOUT:

    Serial.println("DHT: Time out error");

    break;

    case DHTLIB_ERROR_CONNECT:

    Serial.println("DHT: Connect error");

    break;

    case DHTLIB_ERROR_ACK_L:

    Serial.println("DHT: Ack Low error");

    break;

    case DHTLIB_ERROR_ACK_H:

    Serial.println("DHT: Ack High error");

    break;

    default:

    Serial.println("DHT: Unknown error");

    break;

    }

    float t = DHT.temperature;

    int h = DHT.humidity;

    t = t * 9 / 5 + 32; //Convert to C to F

     

    cdsval = analogRead(CDSPIN);

     

    DateTime now = rtc.now();

     

    if (isnan(t) || isnan(h)) {

    lcd.setCursor(0, 0);

    lcd.print("Failed to read from DHT");

    } else {

    //LCD Logging

    lcd.clear();

    lcd.setCursor(0, 0);

    lcd.print("H: ");

    lcd.print(h);

    lcd.print("%");

    lcd.print(" " + String(now.hour()) + ":" + String(now.minute()) + ":" + String(now.second()));

    lcd.setCursor(0, 1);

    lcd.print("T: ");

    lcd.print(t, 1);

    lcd.print("F");

    lcd.print(" ");

    lcd.print("L: ");

    lcd.print(cdsval);

     

    //Serial Logging

    Serial.print(now.day(), DEC);

    Serial.print('/');

    Serial.print(now.month(), DEC);

    Serial.print('/');

    Serial.print(now.year(), DEC);

    Serial.print(' ');

    Serial.print(now.hour(), DEC);

    Serial.print(':');

    Serial.print(now.minute(), DEC);

    Serial.print(':');

    Serial.print(now.second(), DEC);

    Serial.println("," + String(h) + "," + String(t) + "," + String(cdsval));

    }

    delay(1000);

    }



    Daniel Alich, 2017-04-17 19:09:51 -04:00
  2. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!
Help!