ESP8266 IoT Data Logger: SD Card & ThingSpeak

 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.

This project is an advanced IoT version of temperature and humidity monitoring.
Unlike basic Arduino projects, the ESP8266 allows wireless data transmission and cloud storage, enabling real-time monitoring from anywhere.

If you are a beginner, start with the basic version here: 
https://simplebasicelectronics.blogspot.com/2026/04/arduino-temperature-humidity-dht22-lcd.html


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 PinESP8266
VCC3.3V
GNDGND
DATAD4 (GPIO2)

👉 Use 10kΩ resistor between VCC and DATA


📟 I2C LCD Connections

LCD PinESP8266
VCC3.3V
GNDGND
SDAD2 (GPIO4)
SCLD1 (GPIO5)

💾 SD Card Module Connections (SPI)

SD ModuleESP8266
VCC3.3V ⚠️
GNDGND
CSD8 (GPIO15)
SCKD5 (GPIO14)
MOSID7 (GPIO13)
MISOD6 (GPIO12)

4. Detailed Step By Step Circuit Working

  1. The DHT22 sensor measures temperature and humidity.
  2. ESP8266 reads sensor data every cycle.
  3. Data is displayed on the LCD screen.
  4. Data is saved in SD card as a text file.
  5. ESP8266 connects to WiFi network.
  6. Data is sent to cloud using API request.
  7. 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


🪜 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 connection
  • DHT.h → Sensor reading
  • LiquidCrystal_I2C.h → LCD display
  • SD.h → SD card storage
  • client.connect() → Sends data to cloud
  • delay(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

തുടക്കക്കാർക്കായി ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.