Security · Arduino Uno
Doorway Watchdog
A Arduino Uno build with 5 components. Reads: PIR, Button. Drives: Buzzer, LED, Servo. Sound the buzzer when motion is detected; the button arms and disarms.
5 parts · 12 connections · 10 steps
Wiring
Parts
| Part | Refs | Qty | Est. |
|---|---|---|---|
| HC-SR501 PIR motion sensor | PIR | 1 | $1.50 |
| Passive piezo buzzer | Buzzer | 1 | $0.60 |
| LED (5 mm) + 220 Ω resistor | LED | 1 | $0.15 |
| Tactile push button | Button | 1 | $0.10 |
| SG90 micro servo | Servo | 1 | $2.40 |
| Plus: breadboard, jumper wires, USB cable | ≈ $4.75 | ||
Prices are rough hobby-market estimates. Click a part for wiring notes and specs.
Firmware
1// Motion Alarm2// Generated by Wirecraft for the Arduino Uno (ATmega328P)3// Prompt: A motion alarm with a PIR sensor, a loud buzzer, an LED, and a button to arm and disarm it4//5// Wiring, parts and step-by-step assembly live alongside this file.67#include <Arduino.h>8#include <Servo.h>910#define PIR_PIN 211#define BUZZER_PIN 312#define LED_PIN 413#define BUTTON_PIN 514#define SERVO_PIN 61516bool pIRMotion = false;17bool buttonPressed = false;18Servo servo;1920void setup() {21 Serial.begin(115200);22 pinMode(PIR_PIN, INPUT);23 pinMode(BUZZER_PIN, OUTPUT);24 pinMode(LED_PIN, OUTPUT);25 pinMode(BUTTON_PIN, INPUT_PULLUP);26 servo.attach(SERVO_PIN);27 servo.write(0);28 Serial.println(F("Motion Alarm ready."));29}3031void loop() {32 // --- Read sensors ---33 pIRMotion = (digitalRead(PIR_PIN) == HIGH);34 buttonPressed = (digitalRead(BUTTON_PIN) == LOW);3536 // --- React ---37 // Sound the buzzer when motion is detected; the button arms and disarms.38 if (pIRMotion) {39 tone(BUZZER_PIN, 880);40 } else {41 noTone(BUZZER_PIN);42 }4344 delay(50);45}461; PlatformIO project for Motion Alarm2[env:uno]3platform = atmelavr4board = uno5framework = arduino6monitor_speed = 1152007lib_deps =8 arduino-libraries/Servo@^1.2.19Assembly
- 1
Lay out your workbench
Gather the Arduino Uno, a half-size breadboard, and a bundle of male-to-male jumper wires. Keep the parts list open — every component below gets its own spot on the breadboard. Don't plug in USB power until the last wire is placed.
- 2
Seat the board and power rails
Run a red jumper from the Arduino Uno's 3V3 (or 5V for 5 V parts) pin to the breadboard's + rail, and a black jumper from GND to the − rail. Every component's power and ground will tap these rails.
- 3
Wire the PIR
Place the HC-SR501 PIR motion sensor on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: OUT → D2. Tip: Give it 30–60 s to settle after power-up, and turn both trim pots fully counter-clockwise to start.
- 4
Wire the Buzzer
Place the Passive piezo buzzer on the breadboard. Power first: GND → − rail. Then signals: SIG → D3. Tip: Passive buzzers need tone(); active ones just want HIGH. This design assumes passive.
- 5
Wire the LED
Place the LED (5 mm) + 220 Ω resistor on the breadboard. Power first: CATHODE → − rail. Then signals: ANODE → D4. Tip: The longer leg is the anode (+). The resistor can go on either leg.
- 6
Wire the Button
Place the Tactile push button on the breadboard. Power first: GND → − rail. Then signals: SIG → D5. Tip: Legs on the same side are connected in pairs — wire diagonally opposite corners to be safe.
- 7
Wire the Servo
Place the SG90 micro servo on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: SIG → D6. Tip: Servos are power-hungry. For more than one, feed them from a separate 5 V supply and share GND.
- 8
Double-check before power
Trace every wire against the diagram once more — 12 connections in total. The classic mistakes: swapped power and ground, and off-by-one rows on the breadboard. Thirty seconds of checking saves a component.
- 9
Flash the firmware
Open the exported folder in VS Code with the PlatformIO extension (free), plug in the Arduino Uno over USB, and hit Upload. PlatformIO fetches the libraries listed in platformio.ini automatically. Prefer the Arduino IDE? Copy src/main.cpp into a new sketch and install the same libraries from the Library Manager.
- 10
Bring it to life
Open the Serial Monitor at 115200 baud to watch live readings. Sound the buzzer when motion is detected; the button arms and disarms. Adjust the thresholds at the top of the sketch to match your environment.