Top 5 Arduino Home Automation Projects (With Code & Circuit)



Top 5 Arduino Home Automation Projects (With Code & Circuit)

Arduino makes home automation accessible to anyone — no electrician needed, no expensive smart-home hub. These 5 projects turn your ordinary home into a smarter one using components that cost less than a takeaway meal. Each project is standalone, fully explained, and ready to build today.

Project 1 — Smart Light Switch with IR Remote

Project Description

Control any mains light or appliance using a TV remote and an Arduino. A relay module acts as the switch while an IR receiver captures the remote signal. Press a button on any IR remote to toggle the light on or off — no rewiring of mains required, the relay sits between the socket and the device.

Components: Arduino Uno, IR receiver (VS1838B), 5V relay module, any IR remote, LED (for testing), 220Ω resistor, breadboard, jumper wires.

Circuit Description

ComponentPinArduino Pin
IR ReceiverOUTPin 11
IR ReceiverVCC5V
IR ReceiverGNDGND
Relay ModuleINPin 7
Relay ModuleVCC5V
Relay ModuleGNDGND

For testing: wire an LED with a 220Ω resistor through the relay's NO and COM terminals. For a real appliance, have a qualified electrician connect the relay into the mains circuit.

Code

#include <IRremote.h>

#define IR_PIN    11
#define RELAY_PIN  7

// Record your remote's button code using IRrecvDemo sketch first
#define BUTTON_CODE 0xFF30CF  // Example: change to match your remote

IRrecv irrecv(IR_PIN);
decode_results results;
bool lightOn = false;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
  Serial.println("IR Smart Switch Ready");
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.print("Received code: 0x");
    Serial.println(results.value, HEX);

    if (results.value == BUTTON_CODE) {
      lightOn = !lightOn;
      digitalWrite(RELAY_PIN, lightOn ? HIGH : LOW);
      Serial.println(lightOn ? "Light ON" : "Light OFF");
    }
    irrecv.resume();
  }
}

Conclusion

You've added remote-control switching to any appliance without touching the wiring. Next step: decode multiple button codes from your remote to control several relays independently, or swap the IR remote for an ESP8266 module to control lights over WiFi from your phone.

Project 2 — Keypad Door Lock

Project Description

A 4×4 keypad lets you enter a secret 4-digit PIN to unlock a solenoid or servo-driven door lock. Three wrong attempts trigger a buzzer alarm and lock out further entry for 30 seconds. This is one of the most searched Arduino security projects and teaches keypad scanning, string comparison, and timed lockout logic.

Components: Arduino Uno, 4×4 membrane keypad, servo motor (or 12V solenoid + relay), buzzer, green LED, red LED, 2 × 220Ω resistors, breadboard, jumper wires.

Circuit Description

ComponentConnectionArduino Pin
Keypad rowsR1–R4Pins 9, 8, 7, 6
Keypad colsC1–C4Pins 5, 4, 3, 2
Servo signalPWMPin 10
Buzzer+Pin 12
Green LED+Pin 13
Red LED+Pin 11

Code

#include <Keypad.h>
#include <Servo.h>

const byte ROWS = 4, COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

Servo lockServo;
const String correctPIN = "1234";
String enteredPIN = "";
int attempts = 0;

#define GREEN_LED 13
#define RED_LED   11
#define BUZZER    12

void buzz(int times) {
  for (int i = 0; i < times; i++) {
    digitalWrite(BUZZER, HIGH); delay(200);
    digitalWrite(BUZZER, LOW);  delay(100);
  }
}

void unlock() {
  Serial.println("Correct PIN! Unlocking...");
  digitalWrite(GREEN_LED, HIGH);
  lockServo.write(90);   // open position
  delay(5000);
  lockServo.write(0);    // locked position
  digitalWrite(GREEN_LED, LOW);
  attempts = 0;
}

void deny() {
  attempts++;
  Serial.println("Wrong PIN! Attempt " + String(attempts));
  digitalWrite(RED_LED, HIGH);
  buzz(3);
  delay(1000);
  digitalWrite(RED_LED, LOW);

  if (attempts >= 3) {
    Serial.println("Too many attempts! Locked for 30 seconds.");
    buzz(5);
    delay(30000);
    attempts = 0;
  }
}

void setup() {
  Serial.begin(9600);
  lockServo.attach(10);
  lockServo.write(0); // start locked
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED,   OUTPUT);
  pinMode(BUZZER,    OUTPUT);
  Serial.println("Enter PIN:");
}

void loop() {
  char key = keypad.getKey();
  if (!key) return;
  Serial.print(key);

  if (key == '#') {
    Serial.println();
    if (enteredPIN == correctPIN) unlock();
    else deny();
    enteredPIN = "";
  } else if (key == '*') {
    enteredPIN = "";
    Serial.println("\nCleared.");
  } else {
    enteredPIN += key;
  }
}

Conclusion

This project teaches input scanning, state tracking, and timed lockout — the same logic behind ATM PIN systems. Next step: store the PIN in EEPROM so it survives power cuts, or add a WiFi module to log every unlock attempt with a timestamp.

Project 3 — Automatic Temperature Fan Controller

Project Description

This thermostat reads room temperature with a DS18B20 sensor and automatically adjusts a fan's speed using PWM. Below 25°C the fan is off; between 25–35°C it runs at proportional speed; above 35°C it runs at full speed. The current temperature and fan speed percentage are displayed on a 16×2 LCD. Ideal for server racks, grow tents, or any heat-sensitive enclosure.

Components: Arduino Uno, DS18B20 temperature sensor, NPN transistor (TIP120), 5V fan, 16×2 I2C LCD, 4.7kΩ resistor, 1kΩ resistor, flyback diode (1N4007), breadboard, jumper wires.

Circuit Description

ComponentConnectionArduino Pin
DS18B20DATAPin 2 (with 4.7kΩ to 5V)
TIP120 basevia 1kΩPin 9 (PWM)
Fan +5V—
Fan –TIP120 collector—
1N4007across fan terminals—
LCD SDAI2CA4
LCD SCLI2CA5

Code

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>

#define ONE_WIRE_BUS 2
#define FAN_PIN      9

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Serial.begin(9600);
  sensors.begin();
  lcd.begin(); lcd.backlight();
  pinMode(FAN_PIN, OUTPUT);
}

void loop() {
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);

  int fanSpeed = 0;
  if      (temp <= 25) fanSpeed = 0;
  else if (temp >= 35) fanSpeed = 255;
  else    fanSpeed = map((int)temp, 25, 35, 60, 255);

  analogWrite(FAN_PIN, fanSpeed);

  int fanPercent = map(fanSpeed, 0, 255, 0, 100);
  Serial.printf("Temp: %.1f C | Fan: %d%%\n", temp, fanPercent);

  lcd.clear();
  lcd.setCursor(0, 0); lcd.print("Temp: "); lcd.print(temp, 1); lcd.print(" C");
  lcd.setCursor(0, 1); lcd.print("Fan:  "); lcd.print(fanPercent); lcd.print(" %");
  delay(2000);
}

Conclusion

PWM fan control with a temperature sensor is a foundational automation pattern used everywhere from PC cooling to industrial HVAC. Next step: add a setpoint button so the user can adjust the target temperature, or log the data to a web dashboard via an ESP8266.

Project 4 — Motion-Activated Security Light

Project Description

A PIR motion sensor triggers a relay to switch on a light (or siren) whenever movement is detected. The light stays on for a configurable timeout (default 30 seconds) then turns off. A sensitivity potentiometer on the PIR module lets you tune the detection range from 3 to 7 metres. Simple, practical, and genuinely useful.

Components: Arduino Uno, HC-SR501 PIR sensor, 5V relay module, LED (or lamp via relay), 220Ω resistor, breadboard, jumper wires.

Circuit Description

ComponentPinArduino Pin
PIR sensorOUTPin 2
PIR sensorVCC5V
PIR sensorGNDGND
RelayINPin 7

Set the PIR module's jumper to "H" (retriggering) mode so the timer resets while motion continues.

Code

#define PIR_PIN    2
#define RELAY_PIN  7

unsigned long lightOnTime = 0;
const unsigned long TIMEOUT = 30000; // 30 seconds
bool lightOn = false;

void setup() {
  Serial.begin(9600);
  pinMode(PIR_PIN,   INPUT);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
  delay(30000); // Allow PIR sensor to calibrate on startup
  Serial.println("Security light ready.");
}

void loop() {
  int motion = digitalRead(PIR_PIN);

  if (motion == HIGH) {
    if (!lightOn) {
      Serial.println("Motion detected! Light ON.");
      digitalWrite(RELAY_PIN, HIGH);
      lightOn = true;
    }
    lightOnTime = millis(); // reset the timeout on each detection
  }

  if (lightOn && (millis() - lightOnTime > TIMEOUT)) {
    Serial.println("No motion. Light OFF.");
    digitalWrite(RELAY_PIN, LOW);
    lightOn = false;
  }
}

Conclusion

This is the exact logic inside commercial motion-sensor lights. Next step: add a light-dependent resistor (LDR) so the light only activates at night, or connect the relay to a buzzer for an intruder alarm instead.

Project 5 — AC Current Energy Monitor

Project Description

Use a non-invasive SCT-013 current transformer clipped around a mains cable to measure how much current an appliance draws — without cutting any wire. The Arduino reads the AC waveform, calculates RMS current, estimates power (watts) and cost, and displays it on the serial monitor. A safe and impressive project for any home energy audit.

Components: Arduino Uno, SCT-013-030 (30A) current transformer, 10µF electrolytic capacitor, 2 × 10kΩ resistors, 33Ω burden resistor (if not built in), breadboard, jumper wires.

Circuit Description

ComponentConnectionArduino Pin
SCT-013 wire 1via 33Ω burdenA1
SCT-013 wire 2GNDGND
Bias divider2 × 10kΩ from 5V to GNDmidpoint to A1
10µF capacross A1 and GND—

The two 10kΩ resistors create a 2.5V bias so the AC waveform sits in the middle of the Arduino's 0–5V ADC range. The SCT-013-030 has a built-in burden resistor — if yours does not, add a 33Ω resistor across the output.

Code

// Uses the EmonLib library: install via Arduino Library Manager
#include "EmonLib.h"

EnergyMonitor emon;

// Calibration: 30A SCT-013-030 on 5V Arduino = calibration ~111.1
// Adjust until emon.Irms matches a clamp meter reading
#define CALIBRATION 111.1
#define VOLTAGE     230.0  // mains voltage in your country (230V UK/EU, 120V US)
#define COST_PER_KWH 0.28  // adjust to your electricity tariff

void setup() {
  Serial.begin(9600);
  emon.current(A1, CALIBRATION);
  Serial.println("Energy Monitor Ready");
  Serial.println("Irms(A) | Power(W) | Cost/hr(p)");
}

void loop() {
  double Irms  = emon.calcIrms(1480); // 1480 samples
  double power = Irms * VOLTAGE;
  double costPerHour = (power / 1000.0) * COST_PER_KWH * 100; // pence

  Serial.print(Irms, 3); Serial.print(" A  | ");
  Serial.print(power, 1); Serial.print(" W  | ");
  Serial.print(costPerHour, 2); Serial.println(" p/hr");
  delay(2000);
}

Conclusion

Non-invasive current monitoring is how commercial smart plugs work under the hood. Next step: add a WiFi module to push readings to a Home Assistant dashboard, or track daily kWh consumption by logging to an SD card.


More ESP32 & Arduino Project Guides

Post a Comment

0 Comments