Build a SMART SECURITY ALARM with Arduino! 🚨👀
- Robin PJ
- Oct 30
- 5 min read
Posted on October 30, 2025 | By Micromaker Labs Team
Hey makers and security-savvy tinkerers! 👋 Back at it with the Maker's Build series on Micromaker Labs—your go-to for STEM kits that turn curiosity into cool gadgets. Since launching on October 1st, we've been buzzing (pun intended!) in our home lab, crafting projects that make electronics feel like playtime. If you're just joining, check out Part 1: our Auto Night Light that auto-glows at dusk.
Today for Part 2, we're leveling up to a Smart Security Alarm! This bad boy uses an IR sensor to spot motion—like an invisible guard dog—and triggers a flashing LED warning light plus a piercing buzzer alert. Imagine setting it by your door or desk to catch sneaky siblings (or actual intruders). Practical, fun, and a gateway to real-world IoT security hacks.
What You'll Need 🔧
Beginner-level alert: This builds in ~15 minutes with stuff we keep stocked (hint: our kits bundle it all for hassle-free shipping from www.micromakerlabs.com). Grab these:
Arduino UNO (brain of the operation—clones work great!)
IR Sensor Module (motion detective; dive into its infrared wizardry in our next Sensor Secrets)
Passive Buzzer (for that ear-catching alarm—active ones work too, but passive gives tunable tones)
LED (red for danger vibes; use the built-in on pin 13 to start)
Breadboard & Jumper Wires (solder-free prototyping paradise)
220Ω Resistor (for the LED if not using built-in—protect that glow!)
USB Cable for power and code zaps

Step-by-Step Wiring Guide 🛠️
Breadboard bliss—no mess, all access. Follow this for a clean setup:
Hook Up the IR Sensor:
VCC to Arduino 5V.
GND to Arduino GND.
OUT to digital pin 7 (this is where motion magic flows).
Wire the Buzzer:
Positive (+) leg to digital pin 8.
Negative (-) to GND (passive buzzers need Arduino tones to sing).
Add the LED:
Anode (long leg) to digital pin 13 (built-in LED is resistor-ready).
Cathode (short leg) to GND. (Pro tip: External LED? Slip in that 220Ω resistor.)
Power On:
USB in—watch for the startup beep sequence in Serial Monitor (9600 baud) to confirm it's live.

The Code: Brains of the Operation 💻
Flash this sketch to your Arduino. Serial output lets you spy on detections live—tweak the logic if your IR flips HIGH/LOW on trigger (common module quirk). Startup beeps? Chef's kiss for feedback.
/*
================================================
MICROMAKER LABS - Advanced Proximity Radar
================================================
Project: Multi-stage proximity alarm
Sensor: HC-SR04 Ultrasonic Sensor
Outputs: RGB LEDs (separate) and Passive Buzzer
--- NEW PINOUT ---
TRIG_PIN: A1
ECHO_PIN: A0
RED_LED_PIN: 10
GREEN_LED_PIN: 9
BLUE_LED_PIN: 6
BUZZER_PIN: 5
--- LOGIC ---
- NEAR (Red): 1cm - 5cm
- MEDIUM (Green): 6cm - 15cm
- FAR (Blue): 16cm - 200cm
================================================
*/
// --- Pin Definitions ---
// Sensor Pins
const int TRIG_PIN = A1; // Trigger pin connected to Analog 1
const int ECHO_PIN = A0; // Echo pin connected to Analog 0
// LED Output Pins (PWM) -
const int RED_LED_PIN = 10;
const int GREEN_LED_PIN = 9;
const int BLUE_LED_PIN = 6;
// Buzzer Output Pin (PWM) - *** NEW PIN ***
const int BUZZER_PIN = 5; // Was 6
// --- Proximity Thresholds (in cm) ---
// Using your requested values
const int NEAR_THRESHOLD = 5; // 1-5 cm = RED (High alert)
const int MEDIUM_THRESHOLD = 15; // 6-15 cm = GREEN (Caution)
const int FAR_THRESHOLD = 25; // 16-200 cm = BLUE (Object detected)
// --- Global Variables ---
long duration;
int distance;
void setup() {
// Start Serial Monitor for debugging
Serial.begin(9600);
Serial.println("--- Micromaker Labs Proximity Radar ---");
Serial.println("System Initializing...");
// Set Sensor Pin Modes
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
// Set LED Pin Modes
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(BLUE_LED_PIN, OUTPUT);
// Set Buzzer Pin Mode
pinMode(BUZZER_PIN, OUTPUT);
Serial.println("System Ready. Monitoring...");
}
void loop() {
// 1. Get the current distance from the sensor
distance = getDistanceCm();
// 2. Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// 3. Main Logic: Check distance and set outputs
if (distance > 0 && distance <= NEAR_THRESHOLD) {
// --- ZONE 1: NEAR (RED) ---
// Object is very close (1-5 cm).
int brightness = map(distance, 1, NEAR_THRESHOLD, 255, 50);
setLedColor(brightness, 0, 0); // (Red, Green, Blue)
int frequency = map(distance, 1, NEAR_THRESHOLD, 4000, 2000);
tone(BUZZER_PIN, frequency);
} else if (distance > NEAR_THRESHOLD && distance <= MEDIUM_THRESHOLD) {
// --- ZONE 2: MEDIUM (GREEN) ---
// Object is at a medium range (6-15 cm).
int brightness = map(distance, NEAR_THRESHOLD + 1, MEDIUM_THRESHOLD, 255, 50);
setLedColor(0, brightness, 0); // (Red, Green, Blue)
int frequency = map(distance, NEAR_THRESHOLD + 1, MEDIUM_THRESHOLD, 1999, 500);
tone(BUZZER_PIN, frequency);
} else if (distance > MEDIUM_THRESHOLD && distance <= FAR_THRESHOLD) {
// --- ZONE 3: FAR (BLUE) ---
// Object is detected, but far away (16-200 cm).
int brightness = map(distance, MEDIUM_THRESHOLD + 1, FAR_THRESHOLD, 255, 50);
setLedColor(0, 0, brightness); // (Red, Green, Blue)
int frequency = map(distance, MEDIUM_THRESHOLD + 1, FAR_THRESHOLD, 499, 200);
tone(BUZZER_PIN, frequency);
} else {
// --- ZONE 4: OUT OF RANGE ---
// No object detected (or > 200cm)
setLedColor(0, 0, 0); // All LEDs OFF
noTone(BUZZER_PIN); // No sound
}
// Wait for 100 milliseconds before the next reading
delay(300);
}
/**
* @brief Triggers the sensor and reads the echo to calculate distance.
* @return The distance in centimeters (cm).
*/
int getDistanceCm() {
// Clear the TRIG_PIN
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
// Send a 10 microsecond pulse to trigger the sensor
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Read the echo pin (returns the sound wave travel time in microseconds)
duration = pulseIn(ECHO_PIN, HIGH);
// Calculate the distance
return duration * 0.0343 / 2;
}
/**
* @brief Sets the brightness of the three separate LEDs using analogWrite.
* @param red Brightness value (0-255) for the RED LED
* @param green Brightness value (0-255) for the GREEN LED
* @param blue Brightness value (0-255) for the BLUE LED
*/
void setLedColor(int red, int green, int blue) {
analogWrite(RED_LED_PIN, red);
analogWrite(GREEN_LED_PIN, green);
analogWrite(BLUE_LED_PIN, blue);
}
How to Upload:
Paste into Arduino IDE, pick UNO/port, verify then upload.
Wave your hand—Serial spits "ALERT!" and the alarm kicks in!
How It Works: The Science Behind the Siren 🔬
Echoing our Into the Basics on Arduino as mini-computers: It reads digital inputs (IR's HIGH/LOW flip on infrared bounce-back from motion) and blasts outputs (LED flash, buzzer tone via PWM). Key bits:
IR detects movement up to ~1-2m (adjust sensitivity pot on module).
Code checks pin 7; LOW triggers a 3-burst alarm (2000Hz screech + 1500Hz whoop).
Serial debugs it all—great for Coding for Kids vibes.
Test & Tweak: Your Turn! 🧪
No Motion: All quiet, Serial chill (~"System Ready").
Wave Hello: 3x flash/beep frenzy—distance test your IR's range.
Challenge: Flip to HIGH detection if inverted, or add a delay var for longer alarms. Tag @micromakerlabs with your tweaks!
Micromaker Labs | Empowering Tomorrow's Innovators Today



Nice