Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
Bettesworth Construction
Alarm System

Arduino Alarm System: Build a Keypad-Controlled Door and Motion Alarm

A practical Arduino alarm system guide covering sensor choice, keypad control, non-blocking alarm logic, safe siren drivers, power, testing, and connected notifications.

By Bettesworth Construction Team 8 min read
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An Arduino alarm system can provide a useful local warning when a door opens or motion is detected. The most practical beginner design combines a normally closed magnetic door contact, optional PIR motion sensor, keypad PIN, status LEDs, entry and exit delays, and a buzzer or externally switched siren.

This is a DIY prototype or supplementary alarm—not a certified, monitored security system. It can be expanded with Wi-Fi or cellular notifications, but local detection and alarming should continue to work when the network is unavailable.

As an Amazon Associate I earn from qualifying purchases.

Choose the right alarm sensor

Use a magnetic reed contact for a door or window. It detects the opening event directly and is usually the most predictable perimeter sensor. Wire it normally closed so an open door or broken wire appears as a fault or open circuit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a PIR sensor for movement in a room, garage, shed, or hallway. PIR sensors are inexpensive and easy to connect, but placement matters. Pets, heaters, sunlight, fans, curtains, and the sensor’s warm-up period can cause false triggers. A stationary person may also eventually stop producing a motion event.

#1 Best Overall
LONELY BINARY 5-Set I2C 4x4 Matrix Membrane Keypad for C++ ESP32 Pico
  • 【5-SET SOFT KEYPAD KIT (5 KEYPADS + 5 I2C ADAPTERS)】Includes 5 flexible soft 4x4 matrix keypads (16 keys each), 5 I2C adapters to simplify connections, and a storage container — suitable for multiple projects or backups.
  • 【SOFT MEMBRANE KEYPADS WITH EASY MOUNTING】Each keypad has a flexible design with double-sided adhesive tape on the back for attachment to project boxes, desks, or enclosures — for custom interfaces in robotics, security systems, or prototypes.
  • 【GPIO-SAVING I2C ADAPTERS】The included adapters enable I2C communication using just 2 GPIO pins (SDA and SCL) instead of the traditional 8, freeing up pins on your microcontroller. Compatible with Raspberry Pi, ESP32, and more.
  • 【WIDE COMPATIBILITY】Keypads and adapters support 3.3V to 5V operation for a wide range of MCUs. Easy to program with libraries like Keypad_I2C for quick setup.
  • 【VERSATILE APPLICATIONS】Use these 4x4 keypads for numeric entry, menu navigation, or custom controls in IoT devices, home automation, smart locks, and educational projects. Soft, responsive keys provide tactile feedback in a compact form.

Vibration, smoke, water, temperature, and gas sensors can be added as separate zones, but each requires its own filtering and failure response.

Recommended hardware

  • Arduino UNO R4 WiFi, UNO R4 Minima, UNO R3, Nano, or equivalent
  • Normally closed magnetic reed contact
  • Optional PIR motion sensor
  • 4×3 or 4×4 matrix keypad
  • Active buzzer for a prototype
  • Red and green LEDs with suitable resistors
  • 16×2 I2C LCD or small OLED display
  • MOSFET or transistor driver, and a separate supply, for a larger siren
  • Breadboard and jumper wires for testing
  • Regulated power supply and, for a permanent installation, an enclosure

The Arduino UNO R4 WiFi is a convenient connected choice: it uses a 5 V main circuit, has 14 digital I/O pins and six analog inputs, and combines a Renesas RA4M1 microcontroller with an ESP32-S3 wireless module. The Starter Kit R4 includes an UNO R4 WiFi, breadboard, LCD, piezo, LEDs, buttons, wires, and sensors, but it is a learning kit rather than a complete security-alarm package. It does not supply a complete PIR installation, door-contact enclosure, backup battery, tamper circuit, or certified siren system.

Example wiring

The following pin plan is internally consistent with the example sketch below:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Blue Charm Fake Security Alarm Keypad, Extra Long 1.5 Year Continuous Usage Battery Life, No Wiring Needed
  • Realistic Deterrent Design: This fake security alarm keypad features an authentic appearance with a red blinking LED light and professional black housing that creates the impression of an active security system, helping to deter potential intruders without the cost of a full alarm installation
  • Extended Battery Life: Enjoy exceptional longevity with up to 1.5 years of continuous usage from just four AAA batteries, providing reliable operation and peace of mind while minimizing the need for frequent battery replacements and maintenance
  • Simple Installation Process: No complicated wiring or professional installation required - this keypad can be easily mounted anywhere you need it, making it perfect for renters, temporary locations, or anyone seeking a hassle-free security solution
  • Energy Efficient Operation: The LED light is designed to blink continuously while consuming minimal power, ensuring your deterrent remains visible and effective throughout the extended battery life without draining energy unnecessarily
  • Versatile Placement Options: The wireless design allows you to position this security keypad in the most visible and strategic locations such as near entry doors, garages, or windows to maximize its deterrent effect without being limited by electrical outlet locations
Function Arduino connection
Normally closed door contact D2 to GND; use INPUT_PULLUP
PIR output D3
Active buzzer or driver input D4
Green status LED D5 through a resistor
Red status LED D6 through a resistor
Keypad rows D7, D8, D9, D10
Keypad columns D11, D12, D13

With the door contact wired to ground, LOW means closed and HIGH means open or disconnected. This is a simple fail-open technique, not a certified supervised alarm loop. A professional design may use end-of-line resistors and tamper supervision to distinguish an open door, a short circuit, and a cut cable.

Do not drive a large siren from a GPIO pin

A small piezo buzzer is different from a 12 V siren, horn, motor, strobe, or high-current sounder. The UNO R4 WiFi specification lists a maximum DC current of 8 mA per I/O pin, so a larger load must be switched externally.

Arduino GPIO → gate/base resistor → MOSFET or transistor → siren
                                      │
                                  separate supply

Use a suitable logic-level MOSFET or transistor, size the separate supply for the siren’s startup and running current, and connect grounds where the circuit requires a shared reference. Relay coils and other inductive loads need flyback protection unless the relay module already includes it. Confirm that the module’s input voltage and logic levels match your board.

Rank #3
Sale
GRSICO Wireless Home Alarm System 15-Piece Kit, WiFi Alarm System for Home Security with Phone APP Alert (Alarm Siren, Keypad, Remote, Motion, and Door Sensors) for Home, Apartment, Work with Alexa
  • Easily DIY Installation: Get ready to protect your home security right out of the box. Set up in minutes all by yourself. No wiring or drilling required.
  • No Monthly Fees: GRSICO WiFi Alarm System is a one-time purchase at no extra fee and provides 24-hour comprehensive protection for your home security.
  • Remotely Control: Complete control of your home security system with the Smart Life App - Arm, disarm and protect anytime, anywhere.
  • Security in Seconds: Arm and disarm your alarm system with keypad and remote in seconds or directly from your phone via the Smart Life App.
  • Instant Alerts: Scare off unwelcome guests with an 120db alarm when a sensor is triggered and get notified with the Smart Life app .

Use a state machine, not blocking delays

A reliable alarm should have explicit states:

  • DISARMED: Sensors are monitored but do not sound the alarm.
  • ARMING: The exit countdown is running.
  • ARMED: A sensor event begins the configured response.
  • ENTRY_DELAY: An entry door allows time to enter the PIN.
  • ALARM: The output remains active until a valid disarm command.
  • FAULT: A sensor, power, tamper, or communication problem is reported.

Use millis() instead of long delay() calls. Blocking delays can stop keypad processing, sensor reading, communications, and watchdog servicing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Working keypad alarm example

Install the Keypad library through the Arduino IDE Library Manager, select the exact board and port, and upload this example. It uses a 3-column keypad; change the row and column definitions if your keypad is 4×4.

#include <Keypad.h>

enum AlarmState { DISARMED, ARMING, ARMED, ENTRY_DELAY, ALARM };
AlarmState state = DISARMED;

const byte DOOR_PIN = 2;
const byte PIR_PIN = 3;
const byte ALARM_PIN = 4;
const byte GREEN_LED = 5;
const byte RED_LED = 6;

const unsigned long EXIT_DELAY_MS = 10000UL;
const unsigned long ENTRY_DELAY_MS = 15000UL;
const unsigned long PIN_TIMEOUT_MS = 10000UL;
const byte MAX_PIN_ATTEMPTS = 3;
const char PIN_CODE[] = "2580"; // Demonstration value; change it.

const byte ROWS = 4, COLS = 3;
char keys[ROWS][COLS] = {
  {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'}
};
byte rowPins[ROWS] = {7, 8, 9, 10};
byte colPins[COLS] = {11, 12, 13};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

unsigned long stateStarted;
unsigned long lastKeyTime;
char entered[sizeof(PIN_CODE)] = {0};
byte enteredLength = 0;
byte failedAttempts = 0;

bool doorOpen() { return digitalRead(DOOR_PIN) == HIGH; }
bool motionDetected() { return digitalRead(PIR_PIN) == HIGH; }

void clearPIN() {
  enteredLength = 0;
  entered[0] = '';
}

void setState(AlarmState next) {
  state = next;
  stateStarted = millis();
  clearPIN();
  digitalWrite(ALARM_PIN, next == ALARM ? HIGH : LOW);
  digitalWrite(GREEN_LED, next == DISARMED ? HIGH : LOW);
  digitalWrite(RED_LED, next == ARMED || next == ENTRY_DELAY || next == ALARM ? HIGH : LOW);
}

bool validPIN() {
  return enteredLength == strlen(PIN_CODE) && strcmp(entered, PIN_CODE) == 0;
}

void readPIN() {
  char key = keypad.getKey();
  if (!key) return;
  lastKeyTime = millis();

  if (key == '*') { clearPIN(); return; }
  if (key == '#') {
    if (validPIN()) {
      failedAttempts = 0;
      setState(DISARMED);
    } else {
      failedAttempts++;
      clearPIN();
      if (failedAttempts >= MAX_PIN_ATTEMPTS) {
        // Keep the alarm response active after repeated failures.
        if (state == ENTRY_DELAY) setState(ALARM);
        failedAttempts = 0;
      }
    }
    return;
  }
  if (key >= '0' && key <= '9' && enteredLength < sizeof(PIN_CODE) - 1) {
    entered[enteredLength++] = key;
    entered[enteredLength] = '';
  }
}

void setup() {
  pinMode(DOOR_PIN, INPUT_PULLUP);
  pinMode(PIR_PIN, INPUT);
  pinMode(ALARM_PIN, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  Serial.begin(115200);
  setState(DISARMED);
  Serial.println("Alarm ready. Press # to arm; enter PIN then # to disarm.");
}

void loop() {
  unsigned long now = millis();
  readPIN();

  if (enteredLength && now - lastKeyTime > PIN_TIMEOUT_MS) clearPIN();

  switch (state) {
    case DISARMED:
      if (keypad.getState() == PRESSED) { /* keypad remains available */ }
      // Arm by pressing 0 then #, for example.
      if (enteredLength == 1 && entered[0] == '0') setState(ARMING);
      break;

    case ARMING:
      if (now - stateStarted >= EXIT_DELAY_MS) setState(ARMED);
      break;

    case ARMED:
      if (doorOpen()) setState(ENTRY_DELAY);
      else if (motionDetected()) setState(ALARM);
      break;

    case ENTRY_DELAY:
      if (validPIN()) setState(DISARMED);
      else if (now - stateStarted >= ENTRY_DELAY_MS) setState(ALARM);
      break;

    case ALARM:
      // Latched until the correct PIN is entered and # is pressed.
      if (validPIN()) setState(DISARMED);
      break;
  }

  Serial.print("State: ");
  Serial.println(state);
}

The sketch is intentionally a teaching baseline. For a long-running installation, improve it by debouncing the door input, adding a motion-event cooldown, avoiding unnecessary dynamic strings, hiding keypad input, storing credentials carefully, and adding a proper display and fault indicator. The example PIN is not a security credential.

Rank #4
AGSHOME Security Alarm System 99+7 Zone Auto Dial 3/4G GSM SMS Home Burglar Security Wireless GSM Alarm System Detector Sensor Kit Remote Control
  • No monthly fees and contracts with security companies,Just pay the cell phone operation service provider; Put-in a GSM SIM card (This alarm do not including GSM sim card) to call/send alert message, you can choose one of two ways or use all of them. The whole system complete with fully programmable main unit and wireless sensors. Before using, please kindly read user's manual
  • Network Support: The alarm panel built-in GSM Module, it support GSM SIM card, T-Mobile sim card can work with our system (This alarm do not including GSM sim card). When the sensor is triggered, the alarm panel will make an call or send alert message to the alert phone number you set before. The GSM (only) frequency is 850/900/1800/1900MHZ, which can be applied in all over the world; In GSM status, 6 groups calling alert phone number and 2 groups help SMS number you can set
  • Loud Emergency Alarm and Easy to Get Help: Children and seniors at home in emergency, press the emergency alarm button of the remote controller, which will trigger all alarms and send emergency calls and messages to other families, so they can get help in time. Support 6 groups preset alarm phone number, if alarm occurs, the host will dial preset number automatically and 10 seconds help voice recording
  • Defense Zone Support: Allow up to 99 wireless defense zones and 7 wired zones, 5 groups of scheduled arm/disarmed function; 2 wired siren for different size houses as you need; DIY home security, tool-free setup and assembling, plug and play installation
  • With 10 second manual recording function to leave messages

Build it in stages

  1. Install the current Arduino IDE or use Arduino Cloud Editor. Connect the board, select the exact board model and serial port, and upload Blink to verify communication.
  2. Test the buzzer or siren driver independently.
  3. Read the door contact and PIR in Serial Monitor before adding alarm behavior.
  4. Test keypad entry and PIN comparison without connecting the siren.
  5. Add the state machine, exit delay, entry delay, and latched alarm.
  6. Move the output to the transistor, MOSFET, or relay driver.
  7. Add fault handling, watchdog recovery, enclosure, and power protection.
  8. Add Wi-Fi or cellular notifications only after local operation is reliable.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Wi-Fi and cellular notifications

The UNO R4 WiFi can add Wi-Fi or Bluetooth experiments without a separate wireless board. Arduino’s current Cloud compatibility page lists supported Arduino boards and third-party ESP32 and ESP8266 devices, including the access method. Compatibility, plan limits, notification features, and device limits can change, so verify them before choosing a service.

Keep the local alarm independent from the network. If Wi-Fi, DNS, the router, or the cloud fails, the door sensor should still trigger the local alarm. Protect credentials, use authenticated and encrypted services where available, and be cautious with remote disarming because it increases the attack surface.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cellular is useful where Wi-Fi is unavailable, but SMS and voice support depend on the module, carrier, SIM, antenna, frequency bands, coverage, and country. Arduino’s hardware catalog includes cellular-oriented boards such as the MKR GSM 1400 and MKR NB 1500. Check current network compatibility rather than assuming that an old GSM module will work.

Best Value
LONELY BINARY 2-Pack 4x4 Matrix Keypad with I2C Adapter for C++
  • 【8 GPIO PINS DOWN TO 2】 SIX PINS BACK ON EVERY BUILD: A 4x4 matrix keypad wired directly takes eight GPIO pins. Through the adapter it needs two — SDA and SCL. The six pins you get back stay free for displays, SD cards, servos and sensors, and other I2C devices can share the same two wires.
  • 【RIGID HOUSING, INDIVIDUAL KEYS】 BUILT FOR REPEATED PRESSES: Molded ABS frame with 16 separately raised keys on a PCB — 0-9, A-D, star and hash. 160-180g actuation force and under 100 ohm contact resistance give a firm, repeatable press rather than a soft membrane feel.
  • 【NO JUMPER WIRES BETWEEN THEM】 FACTORY PRE-SOLDERED HEADER: The 2.54mm 8-pin header arrives already soldered to the keypad and plugs straight into the adapter socket. Four wires — GND, VCC, SDA, SCL — go to your board. Runs on 3.3V or 5V logic, so no level shifter is needed.
  • 【TWO IN THE PACK】 ONE TO BUILD WITH, ONE IN RESERVE: Two complete keypad-and-adapter pairs, so a second project or a spare is already covered. Both adapters ship at address 0x20 and work independently on separate boards straight away.
  • 【OPTIONAL: BOTH ON ONE BUS】 A0/A1/A2 ADDRESS PADS: To run both keypads on a single board, bridge the A0 solder pad on one adapter to move it to 0x21. This step needs a soldering iron. The pads cover eight addresses, 0x20 to 0x27. Compatible with C++, ESP32-S3 and Raspberry Pi boards; the open-source I2CKeyPad library is in the the open-source library manager.

Power, tamper resistance, and installation

Use a regulated supply with adequate current capacity. A rectangular 9 V battery is a poor choice for a long-running siren or Wi-Fi system. Separate the siren supply from the controller when current spikes or electrical noise could reset the Arduino, and add decoupling near modules.

For meaningful protection, consider battery backup, mains-failure detection, low-battery reporting, a tamper switch, a protected enclosure, and a defined reboot state. Decide explicitly whether a power interruption leaves the system disarmed, armed, or in fault; an unexpected reset must not create a false sense of security.

A solderless breadboard is for testing, not permanent deployment. Loose contacts, vibration, exposed conductors, and temperature changes can cause intermittent faults. Move the finished circuit to screw terminals, perfboard, or a PCB inside a suitable enclosure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Test matrix

Test Expected result
Power on while disarmed Disarmed status is shown; siren is off.
Arm command Exit countdown begins.
Door opens while armed Entry delay begins.
Correct PIN during entry delay System disarms.
Incorrect PIN Alarm remains armed and the attempt is indicated.
PIR detects motion while armed Alarm activates.
Alarm is active Siren remains on until a valid reset.
Door wire is disconnected Open or fault behavior is reported.
Arduino reboots Recovery state is predictable and documented.
Wi-Fi or cloud is unavailable Local alarm behavior continues.
Siren switches on Arduino does not reset, overheat, or drive the load directly.

DIY Arduino alarm or commercial system?

Choose the Arduino build for learning, classroom demonstrations, low-consequence notification, or supplementary protection. Choose a professionally supported alarm when you need monitored response, certified sensors, tamper supervision, battery-backed cellular failover, insurance compliance, or dependable protection of significant property.

For purchasing, the UNO R4 Minima is a sensible offline starting point; the UNO R4 WiFi is the most flexible Arduino prototype; and the Starter Kit R4 is useful for beginners who need basic electronics parts. The Plug and Make Kit is a convenient modular demonstration platform, but it is not a complete perimeter-security kit. Prices and availability vary by region and date, so verify current listings rather than treating European storefront prices as universal.

If you redistribute code or create a commercial product, review Arduino’s licensing guidance and the licenses for every library and component.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Site Office

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.