Arduino Project · Advanced Series
Home Automation
Using Arduino UNO
A complete smart home system combining automatic door control, motion-activated lighting, and temperature-based fan operation — all in one Arduino project.
🏠 Live Smart Home Dashboard — Interactive Demo
Auto Door
Closed · No one detected
—
Room Light
OFF · No motion
PIR: LOW
Temp Fan
OFF · Cool
—°C
Simulated readings — values update every 2 seconds to show system behaviour
1Components Required
Arduino UNO
× 1
HC-SR04 Ultrasonic
× 1 (door sensor)
PIR Sensor
× 1 (motion detect)
LM35 Temp Sensor
× 1 (fan control)
Servo Motor (SG90)
× 1 (door actuator)
DC Motor (Fan)
× 1
LED
× 1 (light sim)
L298N Motor Driver
× 1 (optional)
Breadboard
× 1
Jumper Wires
Male-to-Male
Power Supply
5V/9V external
2How Each Subsystem Works
Automatic Door — HC-SR04 + Servo
Ultrasonic distance detection → Servo motor actuation
HC-SR04 emits ultrasonic pulses and measures the echo return time to calculate distance.
If a person is detected within 40 cm → Servo rotates to 90° → Door opens.
Door remains open for 2 seconds, then checks again.
If still within 40 cm → Stays open 2 more seconds. If clear → Servo returns to 0° (door closes).
Automatic Lighting — PIR Sensor + LED
Passive infrared motion detection → LED on/off
PIR sensor detects infrared radiation changes from moving warm bodies.
If motion detected → PIR output goes HIGH → LED turns ON.
If no motion detected → PIR output goes LOW → LED turns OFF.
Saves electricity with automatic energy management — no manual switching needed.
Temperature Fan Control — LM35 + DC Motor
Analog temperature reading → Motor on/off
LM35 outputs 10 mV per °C — Arduino reads this via analog pin and calculates temperature.
If temperature > 20°C → DC motor (fan) turns ON automatically.
If temperature ≤ 20°C → Motor remains OFF to conserve power.
Threshold can be adjusted in code to match your environment (e.g., 30°C for Chennai!).
3Circuit Diagram
Dashed lines represent jumper wire connections. All sensors share the 5V and GND rails.
4Wiring Connections
HC-SR04 Ultrasonic Sensor → Arduino
| Sensor Pin | Arduino Pin | Purpose |
|---|---|---|
| VCC | 5V | Power |
| GND | GND | Ground |
| TRIG | D2 | Trigger pulse output |
| ECHO | D3 | Echo return input |
PIR Sensor → Arduino
| Sensor Pin | Arduino Pin | Purpose |
|---|---|---|
| VCC | 5V | Power |
| GND | GND | Ground |
| OUT | D4 | Motion signal (HIGH/LOW) |
LM35 Temperature Sensor → Arduino
| Sensor Pin | Arduino Pin | Purpose |
|---|---|---|
| VCC (+) | 5V | Power |
| GND (−) | GND | Ground |
| OUT (middle) | A0 | Analog voltage (10mV/°C) |
Servo Motor + LED + DC Motor → Arduino
| Component | Arduino Pin | Purpose |
|---|---|---|
| Servo Signal (orange) | D6 | PWM door control |
| LED Anode (+) | D5 | Room light control |
| Motor IN1 | D7 | Fan direction A |
| Motor IN2 | D8 | Fan direction B |
⚠️
Connect the Servo's red wire → 5V and brown/black wire → GND directly. For the DC motor, use an L298N or a 2N2222 NPN transistor to avoid drawing too much current from the Arduino's 5V pin — it can only safely supply ~200mA total.
5Step-by-Step Build Instructions
1
Install the Servo library
In Arduino IDE go to Sketch → Include Library → Manage Libraries. Search for Servo and install it. The
NewPing library is also helpful for the HC-SR04.2
Set up the breadboard power rails
Connect Arduino 5V → red rail and GND → blue rail. All three sensors (HC-SR04, PIR, LM35) will draw power from these rails.
3
Wire the HC-SR04 Ultrasonic Sensor
VCC → 5V rail, GND → GND rail, TRIG → D2, ECHO → D3. Place the sensor facing the door opening direction — ideally mounted at chest height.
💡 Keep HC-SR04 wires short (under 30cm) to avoid noise in the echo readings.
4
Connect the PIR Sensor
VCC → 5V, GND → GND, OUT → D4. Adjust the sensitivity and time-delay potentiometers on the PIR board to suit your room size — the two small orange dials on the sensor module.
5
Connect the LM35 Temperature Sensor
Flat face of LM35 facing you: left pin → 5V, middle pin → A0, right pin → GND. Do not reverse — the sensor will get hot and fail.
⚠️ Triple-check LM35 orientation. The pins are very close and it looks symmetric but it is not.
6
Attach the Servo Motor (Door)
Servo brown/black → GND, red → 5V, orange signal → D6. Mount the servo horn to a physical door/panel for the demo — or just watch the servo rotate in Tinkercad.
7
Connect the LED (Room Light)
LED anode (long leg) → D5 via a 220Ω resistor. LED cathode (short leg) → GND. The resistor prevents the LED from drawing too much current.
8
Connect DC Motor via transistor or L298N
If using direct connection (Tinkercad only): Motor one terminal → D7, other → D8. For real hardware: use an L298N motor driver — IN1 → D7, IN2 → D8, motor supply from external 9V.
9
Upload code and test each subsystem
Upload the code, open Serial Monitor at 9600 baud. Wave your hand near the ultrasonic sensor, walk past the PIR, and warm the LM35 with your finger. Each subsystem should respond independently.
6Arduino Code
home_automation.ino
// Home Automation System — Arduino UNO // Auto Door (HC-SR04 + Servo) | Motion Light (PIR + LED) // Temp Fan (LM35 + DC Motor) | MakeMindz.com #include <Servo.h> // ── PIN DEFINITIONS ────────────────────────── const int TRIG_PIN = 2; // HC-SR04 Trigger const int ECHO_PIN = 3; // HC-SR04 Echo const int PIR_PIN = 4; // PIR motion sensor const int LED_PIN = 5; // Room LED const int SERVO_PIN = 6; // Servo motor (door) const int MOTOR_IN1 = 7; // DC Motor IN1 const int MOTOR_IN2 = 8; // DC Motor IN2 const int TEMP_PIN = A0; // LM35 analog input // ── SETTINGS ───────────────────────────────── const int DOOR_DIST = 40; // cm — open door if closer const float FAN_TEMP = 20.0; // °C — start fan above this const int DOOR_OPEN = 90; // Servo degrees for OPEN const int DOOR_CLOSED = 0; // Servo degrees for CLOSED Servo doorServo; void setup() { Serial.begin(9600); pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT); pinMode(PIR_PIN, INPUT); pinMode(LED_PIN, OUTPUT); pinMode(MOTOR_IN1, OUTPUT); pinMode(MOTOR_IN2, OUTPUT); doorServo.attach(SERVO_PIN); doorServo.write(DOOR_CLOSED); Serial.println("Home Automation Ready!"); } void loop() { controlDoor(); controlLight(); controlFan(); delay(500); } // ── SUBSYSTEM 1: AUTO DOOR ──────────────────── void controlDoor() { long dist = getDistance(); Serial.print("Distance: "); Serial.print(dist); Serial.println(" cm"); if (dist < DOOR_DIST && dist > 0) { doorServo.write(DOOR_OPEN); // Open door Serial.println("Door: OPEN"); delay(2000); // Hold open 2s dist = getDistance(); // Re-check if (dist >= DOOR_DIST || dist == 0) { doorServo.write(DOOR_CLOSED); // Close if clear Serial.println("Door: CLOSED"); } } } long getDistance() { digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2); digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW); long dur = pulseIn(ECHO_PIN, HIGH); return dur * 0.034 / 2; } // ── SUBSYSTEM 2: MOTION LIGHT ───────────────── void controlLight() { int motion = digitalRead(PIR_PIN); digitalWrite(LED_PIN, motion); Serial.print("Light: "); Serial.println(motion ? "ON" : "OFF"); } // ── SUBSYSTEM 3: TEMP FAN ───────────────────── void controlFan() { int raw = analogRead(TEMP_PIN); float voltage = raw * (5.0 / 1023.0); float tempC = voltage * 100.0; Serial.print("Temp: "); Serial.print(tempC); Serial.println(" C"); if (tempC > FAN_TEMP) { digitalWrite(MOTOR_IN1, HIGH); digitalWrite(MOTOR_IN2, LOW); Serial.println("Fan: ON"); } else { digitalWrite(MOTOR_IN1, LOW); digitalWrite(MOTOR_IN2, LOW); Serial.println("Fan: OFF"); } }
8Try the Simulation
🎮 Try It Without Hardware
Open the Tinkercad simulation — interact with all 3 subsystems live in your browser. Also download the full code from Google Drive.
9Advantages & Applications
Advantages
💰 Low cost — under ₹500 in components
🔧 Easy to build and expand
⚡ Energy efficient automation
📚 Great learning project
🌐 Expandable to IoT via ESP8266/ESP32
🔄 Modular — add/remove subsystems
Applications
🏠 Smart home systems
🏢 Office automation
🏫 Schools & laboratories
🏭 Industrial automation
Comments
Post a Comment