🎃 New: 5 spooky Halloween STEM activities →

Arduino Smart Home Project for Kids: Circuit and Code

Put it all together. The porch lamp turns on at night, and pressing the doorbell rings the buzzer and opens the door.

Parts you need

Wiring

  1. LDR → A0
  2. Doorbell button → pin 2
  3. Buzzer → pin 8
  4. Servo → pin ~9
  5. Lamp LED → pin 13

Arduino code

#include <Servo.h>
Servo door;
int lamp = 13;
int bell = 2;
int buzzer = 8;

void setup() {
  pinMode(lamp, OUTPUT);
  pinMode(bell, INPUT);
  door.attach(9);
  door.write(0);
}

void loop() {
  int light = analogRead(A0);
  if (light < 300) {
    digitalWrite(lamp, HIGH);
  } else {
    digitalWrite(lamp, LOW);
  }

  if (digitalRead(bell) == HIGH) {
    tone(buzzer, 660, 200);
    door.write(90);
    delay(2000);
    door.write(0);
  }
  delay(50);
}

Goal and tip

Goal: Make it dark so the lamp turns on, then ring the doorbell to open the door.

Tip: Try this: keep the door open for 4 seconds instead of 2.

Run this experiment in the free simulator