1. Introduction
Monitoring environmental conditions like temperature and humidity is essential in modern applications such as smart homes, agriculture, weather stations, and industrial automation.
In this advanced IoT project, this is a complete monitoring and data logging system using:
- ESP8266 NodeMCU (WiFi-enabled controller)
- DHT22 (high accuracy sensor)
- 16x2 I2C LCD display (minimal wiring)
- SD card module (local storage)
- Cloud platform for remote monitoring
The system continuously reads data, displays it on the LCD, stores it in an SD card, and uploads it to the cloud for real-time monitoring from anywhere.
2. Components
- ESP8266 NodeMCU
- DHT22
- 16x2 LCD with I2C module
- SD Card Module
- Micro SD Card (FAT32 formatted)
- 10kΩ Resistor
- Breadboard
- Jumper Wires
- USB Cable
3. Circuit and Connections
Circuit Diagram
🔌 Pin Connections
🌡️ DHT22 Connections
| DHT22 Pin | ESP8266 |
|---|---|
| VCC | 3.3V |
| GND | GND |
| DATA | D4 (GPIO2) |
👉 Use 10kΩ resistor between VCC and DATA
📟 I2C LCD Connections
| LCD Pin | ESP8266 |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SDA | D2 (GPIO4) |
| SCL | D1 (GPIO5) |
💾 SD Card Module Connections (SPI)
| SD Module | ESP8266 |
|---|---|
| VCC | 3.3V ⚠️ |
| GND | GND |
| CS | D8 (GPIO15) |
| SCK | D5 (GPIO14) |
| MOSI | D7 (GPIO13) |
| MISO | D6 (GPIO12) |
4. Detailed Step By Step Circuit Working
- The DHT22 sensor measures temperature and humidity.
- ESP8266 reads sensor data every cycle.
- Data is displayed on the LCD screen.
- Data is saved in SD card as a text file.
- ESP8266 connects to WiFi network.
- Data is sent to cloud using API request.
- Cloud stores data and displays graphs.
👉 Even if WiFi fails, SD card continues logging (very important feature)
5. Cloud Setup (ThingSpeak – Full Details)
Platform used:
👉 ThingSpeak
🪜 Step 1: Create Account
- Open https://thingspeak.com
- Sign up → Verify email → Login
🪜 Step 2: Create Channel
- Click New Channel
Fill:
- Name: DHT22 Data Logger
- Field 1: Temperature
- Field 2: Humidity
✔ Enable both fields
✔ Click Save
🪜 Step 3: Get API Key
- Go to API Keys tab
- Copy Write API Key
📊 Output
6. Libraries to be Included
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
7. Code
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN D4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";
String apiKey = "YOUR_WRITE_API_KEY";
const char* server = "api.thingspeak.com";
WiFiClient client;
void setup() {
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.print("System Starting");
dht.begin();
if (!SD.begin(D8)) {
lcd.clear();
lcd.print("SD Failed");
while(1);
}
lcd.clear();
lcd.print("SD OK");
WiFi.begin(ssid, password);
lcd.setCursor(0,1);
lcd.print("Connecting WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
lcd.clear();
lcd.print("WiFi Connected");
delay(2000);
}
void loop() {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
if (isnan(temp) || isnan(hum)) {
lcd.clear();
lcd.print("Sensor Error");
return;
}
// LCD Display
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp:");
lcd.print(temp);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Hum:");
lcd.print(hum);
lcd.print("%");
// SD Card Logging
File file = SD.open("data.txt", FILE_WRITE);
if (file) {
file.print("Temp=");
file.print(temp);
file.print(", Hum=");
file.println(hum);
file.close();
}
// ThingSpeak Upload
if (client.connect(server, 80)) {
String url = "/update?api_key=" + apiKey +
"&field1=" + String(temp) +
"&field2=" + String(hum);
client.print("GET " + url + " HTTP/1.1\r\n" +
"Host: " + server + "\r\n" +
"Connection: close\r\n\r\n");
}
client.stop();
delay(15000);
}
8. Detailed Step By Step Code Working
ESP8266WiFi.h→ WiFi connectionDHT.h→ Sensor readingLiquidCrystal_I2C.h→ LCD displaySD.h→ SD card storageclient.connect()→ Sends data to clouddelay(15000)→ Required by ThingSpeak
9. Tips
- Use 3.3V supply only
- Format SD card as FAT32
- Keep delay ≥ 15 seconds
- Use DHT22 for better accuracy
- Check LCD address (0x27 or 0x3F)
10. Uses
- Weather Monitoring Systems
- Smart Agriculture
- Industrial Data Logging
- IoT Projects
- Research Applications
11. Conclusion
This project demonstrates a complete IoT data logging system using ESP8266, combining real-time display, local storage, and cloud monitoring. It ensures reliability, accuracy, and remote accessibility.
12. ⚠️ Common Mistakes (VERY IMPORTANT)
❌ Wrong API Key → no cloud data
❌ No delay → ThingSpeak rejects data (min 15 sec required)
❌ SD card not initialized → logging fails
❌ Using 5V directly on ESP8266 → damage
Note: You can check the below link for basic version of "Temperature and Humidity Monitoring"
https://simplebasicelectronics.blogspot.com/2026/04/arduino-temperature-humidity-dht22-lcd.html