wirecraft

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

Mini Map
power
ground
data
signal
analog

Parts

PartRefsQtyEst.
HC-SR501 PIR motion sensorPIR1$1.50
Passive piezo buzzerBuzzer1$0.60
LED (5 mm) + 220 Ω resistorLED1$0.15
Tactile push buttonButton1$0.10
SG90 micro servoServo1$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

src/main.cpp
1// Motion Alarm
2// 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 it
4//
5// Wiring, parts and step-by-step assembly live alongside this file.
6
7#include <Arduino.h>
8#include <Servo.h>
9
10#define PIR_PIN 2
11#define BUZZER_PIN 3
12#define LED_PIN 4
13#define BUTTON_PIN 5
14#define SERVO_PIN 6
15
16bool pIRMotion = false;
17bool buttonPressed = false;
18Servo servo;
19
20void 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}
30
31void loop() {
32 // --- Read sensors ---
33 pIRMotion = (digitalRead(PIR_PIN) == HIGH);
34 buttonPressed = (digitalRead(BUTTON_PIN) == LOW);
35
36 // --- 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 }
43
44 delay(50);
45}
46
platformio.ini
1; PlatformIO project for Motion Alarm
2[env:uno]
3platform = atmelavr
4board = uno
5framework = arduino
6monitor_speed = 115200
7lib_deps =
8 arduino-libraries/Servo@^1.2.1
9

Assembly

  1. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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.