// Excel datalogger using Arduino and DHT22 sensor
#include // Include DHT library code
#define DHTPIN 2 // DHT22 data pin is connected to Arduino pin 2
#define DHTTYPE DHT22 // DHT22 sensor is used
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT library
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
dht.begin(); // Initialize the DHT library
Serial.println("CLEARDATA"); // Clear all Excel sheet data
// Label columns: A for date, B for time, C for temperature and D for humidity
Serial.println("LABEL,Date,Time,Temperature,Humidity");
}
void loop() {
Serial.print("DATA,DATE,TIME,"); // Write date and time on row A and row B respectively
Serial.print(dht.readTemperature()); // Read temperature from sensor and send its value to Excel
Serial.print(","); // Move to next column
Serial.print(dht.readHumidity()); // Read humidity from sensor and send its value to Excel
Serial.println(","); // Move to next column and start new row
delay(1000); // Wait 1 second
}
RickyChen