Arduino UNO Smart Home Automation System with Flame & IR Sensors
Fire detection, motion-triggered automation, climate monitoring and OLED display — all in one Arduino UNO project. Full code, wiring, diagram.json & simulation.
Project Overview
This project turns an Arduino UNO into a multi-sensor smart home hub that runs continuously, monitoring four distinct home safety and comfort parameters simultaneously. All sensor data is displayed on a 0.96" SSD1306 OLED screen, while automated outputs (buzzer, LEDs, motors) respond in real time to sensor events.
OLED Dashboard
Live 5-line display: Temp · Humidity · Flame status · IR1 motion · IR2 motion.
I2C Bus
OLED connects via I2C (SDA/SCL) — freeing up digital pins for sensors and outputs.
Event-Driven
Alarm triggers instantly on sensor input with no delay — 1-second loop refresh for display.
Expandable
Add ESP8266 for Wi-Fi alerts, GSM for SMS, or relay module to control AC appliances.
Components List
Adafruit GFX Library · Adafruit SSD1306 · DHT sensor library by Adafruit.Wiring Diagram
Full Pin Reference
| Module | Module Pin | Arduino Pin | Notes |
|---|---|---|---|
| SSD1306 OLED | SDA | A4 | I2C data |
| SSD1306 OLED | SCL | A5 | I2C clock |
| SSD1306 OLED | VCC | 5V | Addr: 0x3C or 0x3D |
| DHT11 | DATA | D10 | Add 10kΩ pull-up to 5V |
| Flame Sensor | OUT | D9 | Active LOW (LOW = fire detected) |
| Buzzer | + | D8 | Active buzzer 5V |
| LED 1 + 220Ω | Anode | D7 | IR Sensor 1 zone |
| LED 2 + 220Ω | Anode | D6 | IR Sensor 2 zone |
| L298N IN1 | IN1 | D2 | Motor A direction A |
| L298N IN2 | IN2 | D3 | Motor A direction B |
| L298N IN3 | IN3 | D4 | Motor B direction A |
| L298N IN4 | IN4 | D5 | Motor B direction B |
| IR Sensor 1 | OUT | D11 | Active LOW on motion |
| IR Sensor 2 | OUT | D12 | Active LOW on motion |
== LOW for fire and the ternary irSensorValue ? "No" : "Yes" for display. Always test with Serial Monitor first before trusting LED feedback.How It Works
🌡️ Temperature & Humidity (DHT11 → D10)
The DHT11 single-wire sensor is polled using the Adafruit DHT library. It returns temperature in °C and relative humidity as a float. Both values are printed to the OLED at row 0 and row 10 (y-pixel coordinates). Read failures return NaN — always check with isnan() in production code.
🔥 Flame Detection (Flame Sensor → D9)
The KY-026 / generic flame sensor outputs LOW when it detects IR radiation from fire. The Arduino reads digitalRead(FLAME_SENSOR_PIN) — if LOW, the buzzer is driven HIGH for an instant alarm. The OLED shows "Flame: Yes". When no fire is present the output stays HIGH (normal).
👤 IR Motion Sensing (IR1 → D11, IR2 → D12)
Two IR proximity/motion modules are placed in different rooms or zones. Each outputs LOW when motion is detected. The Arduino immediately turns on the corresponding LED (zone light) using a ternary expression. The OLED shows live motion status for both sensors.
⚙️ Motor / Appliance Control (L298N → D2–D5)
The L298N H-bridge is wired to D2–D5. In the example code both motors run forward continuously. In a real smart home you'd tie motor activation to sensor conditions — for example, run a fan when temperature exceeds a threshold, or activate a door lock motor when an intruder is detected.
📺 OLED Display Layout
| Y Pixel | Content | Source |
|---|---|---|
| 0 | Temp: 28.5 C | DHT11 |
| 10 | Humidity: 65 % | DHT11 |
| 20 | Flame: No / Yes | Flame sensor (LOW = Yes) |
| 30 | IR1: No / Yes | IR Sensor 1 (LOW = Yes) |
| 40 | IR2: No / Yes | IR Sensor 2 (LOW = Yes) |
Interactive OLED Preview
🖥️ Live OLED Simulator — toggle events below
Full Arduino Code
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <DHT.h> // ── OLED Settings ── #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // ── DHT11 ── #define DHTPIN 10 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); // ── Sensor & Output Pins ── #define FLAME_SENSOR_PIN 9 // Active LOW #define BUZZER_PIN 8 #define LED1_PIN 7 // Zone 1 light #define LED2_PIN 6 // Zone 2 light #define IN1_PIN 2 // L298N Motor A #define IN2_PIN 3 #define IN3_PIN 4 // L298N Motor B #define IN4_PIN 5 #define IR_SENSOR1_PIN 11 // Active LOW #define IR_SENSOR2_PIN 12 // Active LOW void setup() { Serial.begin(9600); // OLED init if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); for (;;); // halt } display.display(); delay(2000); display.clearDisplay(); dht.begin(); pinMode(FLAME_SENSOR_PIN, INPUT); pinMode(BUZZER_PIN, OUTPUT); pinMode(LED1_PIN, OUTPUT); pinMode(LED2_PIN, OUTPUT); pinMode(IN1_PIN, OUTPUT); pinMode(IN2_PIN, OUTPUT); pinMode(IN3_PIN, OUTPUT); pinMode(IN4_PIN, OUTPUT); pinMode(IR_SENSOR1_PIN, INPUT); pinMode(IR_SENSOR2_PIN, INPUT); } void loop() { // ── Read sensors ── float humidity = dht.readHumidity(); float temperature = dht.readTemperature(); int flameSensor = digitalRead(FLAME_SENSOR_PIN); int irSensor1 = digitalRead(IR_SENSOR1_PIN); int irSensor2 = digitalRead(IR_SENSOR2_PIN); // ── OLED Display ── display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(0, 0); display.print("Temp: "); display.print(temperature); display.print(" C"); display.setCursor(0, 10); display.print("Humidity: "); display.print(humidity); display.print(" %"); display.setCursor(0, 20); display.print("Flame: "); display.print(flameSensor == LOW ? "YES!" : "No"); display.setCursor(0, 30); display.print("IR1: "); display.print(irSensor1 == LOW ? "Motion" : "Clear"); display.setCursor(0, 40); display.print("IR2: "); display.print(irSensor2 == LOW ? "Motion" : "Clear"); display.display(); // ── Fire Alarm ── digitalWrite(BUZZER_PIN, flameSensor == LOW ? HIGH : LOW); // ── Smart Lighting (IR-triggered) ── digitalWrite(LED1_PIN, irSensor1 == LOW ? HIGH : LOW); digitalWrite(LED2_PIN, irSensor2 == LOW ? HIGH : LOW); // ── Motor Control (example: forward) ── // Change to sensor-conditional for automation digitalWrite(IN1_PIN, HIGH); digitalWrite(IN2_PIN, LOW); digitalWrite(IN3_PIN, HIGH); digitalWrite(IN4_PIN, LOW); // Serial debug output Serial.print("T:"); Serial.print(temperature); Serial.print(" H:"); Serial.print(humidity); Serial.print(" Flame:"); Serial.print(flameSensor); Serial.print(" IR1:"); Serial.print(irSensor1); Serial.print(" IR2:"); Serial.println(irSensor2); delay(1000); }
display.begin(SSD1306_I2C_ADDRESS, OLED_RESET) — this has been corrected to display.begin(SSD1306_SWITCHCAPVCC, 0x3C) which matches the current Adafruit SSD1306 library API.How to Upload the Code
Download from arduino.cc/en/software and install for your OS.
Use a USB-A to USB-B cable. The power LED on the board should light up.
Go to Sketch → Include Library → Manage Libraries. Search and install: Adafruit GFX Library, Adafruit SSD1306, DHT sensor library.
Create a new sketch (File → New), paste the code. Go to Tools → Board → Arduino UNO. Go to Tools → Port and select the COM port (Windows) or /dev/tty... (Mac/Linux).
Click the → Upload button. Wait for "Done uploading". The OLED will display sensor data after 2 seconds.
Open Tools → Serial Monitor, set baud to 9600. You'll see T/H/Flame/IR values every second for debugging.
Online Simulation
▶ Simulate Online — No Hardware Needed
Test flame detection, IR motion and DHT readings in your browser before building the real circuit.
Open Wokwi CirkitDesignerSimulation Steps
| # | Step |
|---|---|
| 1 | Open Wokwi, create new Arduino UNO project, paste diagram.json above. |
| 2 | Paste the code into sketch.ino. Install libraries via Wokwi's Library Manager. |
| 3 | Click ▶ Start Simulation. The OLED will show live sensor readings. |
| 4 | Click the Flame Sensor component — toggle it active. Watch buzzer activate and OLED show "Flame: YES!" |
| 5 | Click IR Sensor 1 — toggle active. LED1 (D7) lights up. OLED shows "IR1: Motion". |
| 6 | Click IR Sensor 2 — LED2 (D6) lights up. OLED shows "IR2: Motion". |
| 7 | Adjust DHT slider temperature above 35°C — observe OLED temp value change. Add conditional motor logic for fan automation. |
| 8 | Open Serial Monitor to see real-time debug output from all sensors simultaneously. |
Applications & Upgrades
Possible Upgrades
GSM Fire Alert
Add SIM800 to send an SMS when flame is detected — instant notification to homeowner anywhere.
ESP8266 Wi-Fi
Push temp/humidity and alerts to Blynk or ThingSpeak for a live IoT dashboard on your phone.
Relay Module
Replace L298N with a 4-channel relay to control real AC appliances (fans, lights, alarms).
Camera Module
Add ESP32-CAM for live video feed triggered by IR motion detection — full security system.
Comments
Post a Comment