Table of Contents
Creating a digital temperature and humidity data logger is an excellent project for students and hobbyists interested in environmental monitoring. This guide provides step-by-step instructions to build a reliable data logger using accessible components and simple programming techniques.
Materials Needed
- Microcontroller (e.g., Arduino Uno)
- DHT22 Temperature and Humidity Sensor
- SD Card Module and Micro SD Card
- Jumper wires
- Breadboard
- Power supply (USB or battery)
Building the Circuit
Connect the DHT22 sensor to the Arduino:
- VCC to 5V power
- GND to ground
- Data pin to digital pin 2
Connect the SD card module:
- VCC to 5V
- GND to ground
- CS to digital pin 10
- SDI to digital pin 11
- SCK to digital pin 13
Programming the Data Logger
Use the Arduino IDE to upload code that reads data from the DHT22 sensor and writes it to the SD card. Here’s a simple example:
#include <DHT.h>
#include <SPI.h>
#include <SD.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#define chipSelect 10
DHT dht(DHTPIN, DHTTYPE);
File dataFile;
void setup() {
Serial.begin(9600);
dht.begin();
if (!SD.begin(chipSelect)) {
Serial.println("SD card initialization failed!");
return;
}
dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.println("Temperature,Humidity");
dataFile.close();
}
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.print(temperature);
dataFile.print(",");
dataFile.println(humidity);
dataFile.close();
}
delay(2000);
}
Collecting and Analyzing Data
After uploading the code, power the device and start collecting data. The sensor will record temperature and humidity every two seconds, saving it to the SD card. You can remove the SD card and analyze the data using spreadsheet software like Excel or Google Sheets.
Conclusion
Building a digital temperature and humidity data logger is a practical way to learn about sensors, data collection, and programming. This project can be expanded with features like wireless data transmission or real-time display, making it a versatile tool for environmental monitoring.