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
- Arduino Uno
- LDR + 10kΩ
- Push button
- Buzzer
- White LED
- SG90 servo
Wiring
- LDR → A0
- Doorbell button → pin 2
- Buzzer → pin 8
- Servo → pin ~9
- 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.