Devices & Components
Arduino Mega 2560 Rev3
DHT11 Temperature & Humidity Sensor (4 pins)
Project description
Code
temerature_logger
arduino
1#include <dht11.h> 2#include <EEPROM.h> 3 4#define DHT11PIN 4 5 6dht11 DHT11; 7unsigned int address = 0; //variable to iterate through the addresses of the EEPROM 8unsigned int delaytime = 1; //delay between readings in seconds 9 10void setup(){ 11 delay(1000); 12 Serial.begin(9600); 13 14 unsigned int i = 0; 15 while(EEPROM.read(1023) >= i){ //this loop prints the saved data from the EEPROM 16 Serial.print("Time: "); 17 Serial.print((i * delaytime/2)/60); 18 Serial.println(" min."); 19 Serial.print("Temperature: "); 20 Serial.println(EEPROM.read(i)); 21 ++i; 22 Serial.print("Humidity: "); 23 Serial.print(EEPROM.read(i)); 24 Serial.println("%"); 25 ++i; 26 Serial.println(); 27 28 delay(100); 29 } 30 31// while(EEPROM.read(1023) >= i){ //this loop plots the saved data from the EEPROM 32// Serial.print(EEPROM.read(i)); 33// Serial.print(" "); 34// Serial.println(EEPROM.read(i+1)); 35// ++i; 36// ++i; 37// 38// delay(100); 39// } 40 41 delay(20000); //this delay will give you 20 seconds before the new data is written to the EEPROM 42 //if you want to keep the old data you have to reset the board before the delay is over 43} 44 45 46 47void loop(){ 48 delay(delaytime*1000 - 10); //delay between the readings 49 50 int chk = DHT11.read(DHT11PIN); 51 EEPROM.update(address, DHT11.temperature); //the temperature reading is written to the EEPROM 52 ++address; 53 delay(10); 54 EEPROM.update(address, DHT11.humidity); //the humidity reading is written to the EEPROM 55 ++address; 56 57 EEPROM.write(1023, address); 58}
Downloadable files
Schematics
Schematics

Schematics
Schematics

Comments
Only logged in users can leave comments