All projects
🏠🔴 Advanced 4 hrs

Mini Smart Home

A cardboard house with automatic lights, a motion-sensing door and a climate display.

What You'll Build

This is your biggest build yet: a whole miniature smart home. Lights switch on when it gets dark, the front door opens when someone walks up to it, the living room shows temperature and humidity on a small screen, and an alarm sounds if the house gets too hot. Everything runs from one Arduino at the same time.

What You Need

  • Arduino Uno
  • PIR motion sensor
  • DHT11
  • Servo (door)
  • LDR
  • 2 × LED
  • Buzzer
  • LCD

How It Works

The trick with a multi-feature project is that no single part is allowed to block the others. Instead of long delay() calls, the loop checks the clock with millis() and only acts when enough time has passed. That way the door can respond instantly even while the screen is waiting two seconds for its next temperature reading.

Wiring

  1. 1PIR OUT → pin 2, VCC → 5V, GND → GND.
  2. 2DHT11 DATA → pin 3 (the 3-pin module already has its pull-up on board).
  3. 3Door servo signal → pin 5 (external 5V recommended).
  4. 4LDR divider → A0. Room LEDs → pins 6 and 7. Buzzer → pin 8. LCD → A4/A5.

Step-by-Step Instructions

  1. 1

    Build the house

    Cut a simple cardboard house with a hinged front door and holes for the sensors. Keep the roof removable so you can reach the wiring.

  2. 2

    Add one feature at a time

    Get the lights working alone. Then the door alone. Then the screen. Combining tested pieces is far easier than debugging everything at once.

  3. 3

    Switch to millis timing

    Replace every delay() with a timer check so all the features stay responsive together. This is the most important skill in this project.

  4. 4

    Mount the door servo

    Glue the servo behind the doorframe and attach the horn to the door with a small piece of wire so it swings smoothly.

  5. 5

    Wire the alarm

    Reuse the temperature alarm logic from the earlier project — good makers reuse code they already trust.

  6. 6

    Decorate and demo

    Add furniture, paint the walls, then show someone. Walking up and watching the door open never gets old.

Arduino Code

mini-smart-home.ino
#include <Servo.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>

DHT dht(3, DHT11);
Servo door;
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int PIR = 2, LAMP_A = 6, LAMP_B = 7, BUZZER = 8, LDR = A0;

unsigned long lastClimate = 0;
unsigned long doorOpenedAt = 0;
bool doorOpen = false;

void setup() {
  pinMode(PIR, INPUT);
  pinMode(LAMP_A, OUTPUT);
  pinMode(LAMP_B, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  door.attach(5);
  door.write(0);
  dht.begin();
  lcd.init();
  lcd.backlight();
}

void loop() {
  unsigned long now = millis();

  // 1. lights follow the daylight
  bool dark = analogRead(LDR) < 400;
  digitalWrite(LAMP_A, dark);
  digitalWrite(LAMP_B, dark);

  // 2. door opens on motion, closes after 4 seconds
  if (digitalRead(PIR) == HIGH && !doorOpen) {
    door.write(90);
    doorOpen = true;
    doorOpenedAt = now;
  }
  if (doorOpen && now - doorOpenedAt > 4000) {
    door.write(0);
    doorOpen = false;
  }

  // 3. climate screen updates every 2 seconds
  if (now - lastClimate > 2000) {
    lastClimate = now;
    float t = dht.readTemperature();
    float h = dht.readHumidity();
    lcd.setCursor(0, 0);
    lcd.print("T:"); lcd.print(t); lcd.print("C  ");
    lcd.setCursor(0, 1);
    lcd.print("H:"); lcd.print(h); lcd.print("%  ");
    if (t > 30) tone(BUZZER, 1000, 200);
  }
}

Understanding the Code

unsigned long now = millis()

millis() counts milliseconds since the board started. It lets you measure time without stopping the program.

now - doorOpenedAt > 4000

Has four seconds passed since the door opened? If yes, close it. No delay needed.

bool doorOpen

A flag that remembers the door's state between loops, so motion does not re-trigger it endlessly.

tone(BUZZER, 1000, 200)

A beep of exactly 200 ms that stops on its own — perfect for non-blocking code.

Challenges & Upgrades

Add a keypad so the door only opens with the right code.
Log the temperature to an SD card overnight.
Add Bluetooth so you can switch the lights from your phone.

Troubleshooting

😖 Door opens constantly

Fix: PIR sensors have a sensitivity and a time trimmer. Turn the delay trimmer down and keep the sensor away from the servo.

😖 Screen freezes when the door moves

Fix: You still have a delay() somewhere. Convert it to a millis() timer.

Up next

🚦 Traffic Light

Build This