How to Build an Arduino Temperature & Humidity Data Logger
Introduction
Have you ever wondered how weather stations record daily temperature and humidity? With an Arduino data logger, you can build your own version right at home. This simple yet powerful project is perfect for students, hobbyists, and engineers in Lahore, Pakistan, looking for affordable final year projects or IoT-based automation systems.
Data logging plays a vital role in industrial automation, agriculture, and smart home projects. By using Arduino Uno, a DHT11 sensor, and an SD card module, you can measure and store environmental data automatically.
Understanding the Concept
A data logger is an electronic device that records data over time through sensors. The Arduino reads values from the DHT11 temperature and humidity sensor and stores them on an SD card for later analysis.
This project teaches key concepts in electronics engineering, IoT, and embedded systems, making it one of the best engineering projects for students in Lahore and across Pakistan.
Required Components
To make this Arduino temperature and humidity logger, you’ll need:
- Arduino UNO (Rs 1,200)
- DHT11 Sensor (Rs 215)
- SD Card Module — available on order, message us on WhatsApp
- Breadboard (Rs 250)
- Jumper Wires (Rs 180)
- USB Cable / Power Supply
All of these parts are available at Hall Road electronics market, or you can purchase them from QKZee Technologies at the best prices in Lahore.
Component Overview
DHT11 Sensor: Measures temperature and humidity using digital output.
Arduino Uno: The main microcontroller that processes and logs data.
SD Card Module: Stores data from Arduino onto a micro SD card.
These components make this project ideal for student projects, DIY electronics, and automation systems. For the full sensor comparison, see our best Arduino sensors guide.
Circuit Diagram and Connections
Connect your components as follows:
DHT11 Sensor:
- VCC → 5V
- GND → GND
- DATA → Digital Pin 2
SD Card Module:
- VCC → 5V
- GND → GND
- MISO → Pin 12
- MOSI → Pin 11
- SCK → Pin 13
- CS → Pin 10
Ensure that your breadboard connections are firm. Many beginners face issues because of loose wiring.

Arduino Code for Data Logging
The core part of this project is the code that reads sensor data and stores it.
This script logs temperature and humidity data to the SD card every 2 seconds.
#include <DHT.h>
#include <SD.h>
#include <SPI.h>
#define DHTPIN 2 // DHT11 DATA pin
#define DHTTYPE DHT11
#define SD_CS_PIN 10 // SD card module CS pin
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
// Start the SD card — HALT with a clear error if it fails
if (!SD.begin(SD_CS_PIN)) {
Serial.println("SD card failed! Check the wiring and the card.");
while (1); // stop here — do not log into thin air
}
Serial.println("SD card ready.");
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Skip this round if the sensor gives a bad reading
if (isnan(humidity) || isnan(temperature)) {
Serial.println("DHT11 read failed — check the wiring.");
delay(2000);
return;
}
// Write one line to datalog.txt
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.print("Temperature: ");
dataFile.print(temperature);
dataFile.print(" C, Humidity: ");
dataFile.print(humidity);
dataFile.println(" %");
dataFile.close();
} else {
Serial.println("Could not open datalog.txt!");
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" C, Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000); // log every 2 seconds
}A note on the error handling: the old version of this code had no check on SD.begin() — if the card was missing or wired wrong, the sketch would run silently and log nothing. This version stops with a clear serial message instead, so you know immediately what is wrong.
Testing the Logger
After uploading the code, open the Serial Monitor in Arduino IDE. You’ll see temperature and humidity readings in real-time. Check your SD card on a computer, and you’ll find a file named datalog.txt containing recorded data.
Applications of Arduino Data Logger
- Weather monitoring systems
- Greenhouse automation
- Smart agriculture projects
- Industrial environment monitoring
- School and university projects
The same DHT11 + SD card pattern is used in our ESP32 health monitoring patch and our ESP8266 IoT soil test station — both send their readings to ThingSpeak instead of an SD card.
Possible Improvements
Want to make it more advanced? Try these upgrades:
- Add an LCD or OLED (Rs 660) to display live data.
- Send readings to ThingSpeak IoT or Firebase.
- Use DHT22 or BME280 sensors for higher accuracy — both available on order, message us on WhatsApp.
These improvements turn your project into a professional IoT solution.
Benefits for Students
This project is widely recommended for final year projects in electronics engineering. Students can consult QKZee Technologies Lahore for consultation services and professional project development at the best price in Pakistan.
Where to Get Components in Lahore
Head to Hall Road electronics market or visit QKZee Technologies for genuine Arduino components, sensors, and SD modules. You’ll find the best price for student projects in Lahore Pakistan, along with technical support for university projects.
Price Estimation
| Component | Price (PKR) |
|---|---|
| Arduino UNO | Rs 1,200 |
| DHT11 Sensor | Rs 215 |
| SD Card Module | Available on order |
| Breadboard | Rs 250 |
| Jumper Wires | Rs 180 |
| Total (without SD module) | Rs 1,845 |
Affordable and effective — ideal for engineering students in Lahore.
Tips for Final Year Projects
- Customize your code and interface for uniqueness.
- Use proper documentation and circuit diagrams.
- Add a display or IoT connectivity for extra marks.
Conclusion
Building an Arduino-based temperature and humidity data logger helps you understand sensors, microcontrollers, and data management. It’s a simple yet powerful Arduino project that can be expanded into a professional IoT application.
Whether you’re a student in Lahore or anywhere in Pakistan, this project provides hands-on experience in electronics engineering and automation.
Still Stuck?
If datalog.txt is empty, the SD card won’t initialise, or the DHT11 gives strange readings, message us on WhatsApp and we’ll help you debug it — or watch the build on our YouTube channel.
Frequently Asked Questions
Q1: How long can the logger run on one SD card?
A very long time. Each reading is one short line of text (about 40 bytes), logged every 2 seconds — roughly 1.7 MB per day. Even a small 1 GB card holds more than a year of readings. The battery or power supply runs out long before the card fills up.
Q2: Why is my datalog.txt empty even though the code uploaded fine?
Almost always the SD card: either the card is not formatted as FAT32, the CS pin is wrong, or the wiring is loose. This version of the code stops with “SD card failed!” on the serial monitor if the card cannot start — check that message first, then re-seat the card and check the CS → D10 wire.
Q3: Should I use a DHT11 or a DHT22?
The DHT11 is cheaper and fine for room-temperature logging (±2 °C, ±5% humidity). The DHT22 is more accurate (±0.5 °C, ±2% humidity) and reads a wider range, but costs more. For a student project the DHT11 is enough; for a greenhouse or a weather station, use the DHT22.
Q4: How often should I log a reading?
Every 2 seconds is good for testing, but for a real deployment it wastes card space and power. Temperature and humidity change slowly — logging every 1–5 minutes is plenty for a weather station or a greenhouse. Change the delay(2000) at the end of the loop to delay(60000) for once a minute.
Q5: Can the logger run on a battery?
Yes. A 9V battery or a power bank through the USB port works, but the Uno draws around 50 mA even when idle, so a 9V battery lasts only a few hours. For a long deployment, use a power bank, a 12V adapter, or put the Arduino to sleep between readings.






