NodeMCU ESP8266-Based Smart Environmental Monitoring System with OLED Display
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit integrates various sensors and modules with a NodeMCU V3 ESP8266 microcontroller to monitor environmental parameters such as gas levels, temperature, humidity, and heart rate. The data is displayed on an OLED screen and can be communicated via a GSM module. The circuit also includes a relay and a servo motor for additional control functionalities.
Component List
MQ-2 Gas Sensor
- Description: Detects gas levels in the environment.
- Pins: GND, VCC, ANALOG, Digital
NodeMCU V3 ESP8266
- Description: Microcontroller with Wi-Fi capabilities.
- Pins: A0, GND, VU, S3, S2, S1, SC, S0, SK, 3V3, EN, RST, Vin, D0, D1, D2, D3, D4, D5, D6, D7, D8, RX, TX
OLED 1.3" Display
- Description: Displays data visually.
- Pins: GND, VCC, SCL, SDA
MLX90614 Temperature Sensor
- Description: Measures ambient and object temperatures.
- Pins: SDA, SCL, GND, VIN
DS3231 RTC
- Description: Real-time clock module.
- Pins: 32K, SQW, SCL, SDA, VCC, GND
DHT11 Humidity and Temperature Sensor
- Description: Measures humidity and temperature.
- Pins: VDD, DATA, NULL, GND
SIM800L GSM Module
- Description: GSM module for communication.
- Pins: 5V, GND, VDD, SIM_TXD, SIM_RXD, RST
MAX30102 Heart Rate and Oxygen Sensor
- Description: Measures heart rate and blood oxygen levels.
- Pins: VIN, SCL, SDA, INT, IRQ, RD, GND
1 Channel Relay 5V
- Description: Controls high voltage devices.
- Pins: VCC, GND, IN, NC, COM, NO
Servo (Wokwi Compatible)
- Description: Servo motor for mechanical movement.
- Pins: GND, V+, PWM
Wiring Details
MQ-2 Gas Sensor
- GND: Connected to NodeMCU GND
- VCC: Connected to NodeMCU Vin
- ANALOG: Connected to NodeMCU A0
NodeMCU V3 ESP8266
- A0: Connected to MQ-2 ANALOG
- 3V3: Connected to OLED VCC, DHT11 VDD, MAX30102 VIN, Relay VCC
- GND: Connected to OLED GND, DHT11 GND, MAX30102 GND, Relay GND, MQ-2 GND, MLX90614 GND, DS3231 GND, SIM800L GND, Servo GND
- Vin: Connected to MQ-2 VCC, MLX90614 VIN, DS3231 VCC, SIM800L 5V, Servo V+
- D1: Connected to MAX30102 SCL, MLX90614 SCL, OLED SCL, DS3231 SCL
- D2: Connected to MAX30102 SDA, MLX90614 SDA, OLED SDA, DS3231 SDA
- D4: Connected to DHT11 DATA
- D5: Connected to Servo PWM
- D6: Connected to SIM800L SIM_RXD
- D7: Connected to Relay IN, SIM800L SIM_TXD
OLED 1.3" Display
- GND: Connected to NodeMCU GND
- VCC: Connected to NodeMCU 3V3
- SCL: Connected to NodeMCU D1
- SDA: Connected to NodeMCU D2
MLX90614 Temperature Sensor
- SDA: Connected to NodeMCU D2
- SCL: Connected to NodeMCU D1
- GND: Connected to NodeMCU GND
- VIN: Connected to NodeMCU Vin
DS3231 RTC
- SCL: Connected to NodeMCU D1
- SDA: Connected to NodeMCU D2
- VCC: Connected to NodeMCU Vin
- GND: Connected to NodeMCU GND
DHT11 Humidity and Temperature Sensor
- VDD: Connected to NodeMCU 3V3
- DATA: Connected to NodeMCU D4
- GND: Connected to NodeMCU GND
SIM800L GSM Module
- 5V: Connected to NodeMCU Vin
- GND: Connected to NodeMCU GND
- SIM_TXD: Connected to NodeMCU D7
- SIM_RXD: Connected to NodeMCU D6
MAX30102 Heart Rate and Oxygen Sensor
- VIN: Connected to NodeMCU 3V3
- SCL: Connected to NodeMCU D1
- SDA: Connected to NodeMCU D2
- GND: Connected to NodeMCU GND
1 Channel Relay 5V
- VCC: Connected to NodeMCU 3V3
- GND: Connected to NodeMCU GND
- IN: Connected to NodeMCU D7
Servo (Wokwi Compatible)
- GND: Connected to NodeMCU GND
- V+: Connected to NodeMCU Vin
- PWM: Connected to NodeMCU D5
Documented Code
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_MLX90614.h>
// OLED Display Settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// MLX90614 Sensor
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
// MQ-2 Sensor Pin
#define MQ2_PIN A0
// Thresholds for gas levels
#define GAS_SAFE_THRESHOLD 300
#define GAS_WARNING_THRESHOLD 700
void setup() {
// Initialize Serial Communication
Serial.begin(115200);
// Initialize OLED Display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Corrected initialization
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Loop forever if display initialization fails
}
display.clearDisplay();
display.display();
// Initialize MLX90614
if (!mlx.begin()) {
Serial.println("Error connecting to MLX90614 sensor!");
while (1);
}
// Display Welcome Screen
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("MQ-2 & MLX90614");
display.println("Initializing...");
display.display();
delay(2000);
display.clearDisplay();
}
void loop() {
// Read Analog Value from MQ-2
int gasValue = analogRead(MQ2_PIN);
// Read Temperature from MLX90614
float ambientTemp = mlx.readAmbientTempC();
float objectTemp = mlx.readObjectTempC();
// Print Readings to Serial Monitor
Serial.print("MQ-2 Gas Reading: ");
Serial.println(gasValue);
Serial.print("Ambient Temp: ");
Serial.print(ambientTemp);
Serial.println(" °C");
Serial.print("Object Temp: ");
Serial.print(objectTemp);
Serial.println(" °C");
// Update OLED Display
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Gas & Temp Readings:");
// Display Gas Data
display.setTextSize(1);
display.setCursor(0, 10);
display.print("Gas: ");
display.print(gasValue);
// Display Gas Status
display.setCursor(0, 20);
if (gasValue < GAS_SAFE_THRESHOLD) {
display.println(" (Safe)");
} else if (gasValue < GAS_WARNING_THRESHOLD) {
display.println(" (Warning)");
} else {
display.println(" (Danger!)");
}
// Display Temperature Data
display.setCursor(0, 35);
display.print("Amb Temp: ");
display.print(ambientTemp);
display.println("C");
display.setCursor(0, 45);
display.print("Obj Temp: ");
display.print(objectTemp);
display.println("C");
// Refresh Display
display.display();
// Delay before next reading
delay(1000);
}