- C++ 83.1%
- C 16.4%
- Python 0.5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| docs | ||
| include | ||
| lib | ||
| src | ||
| test | ||
| .gitignore | ||
| gen_version.py | ||
| platformio.ini | ||
| readme.md | ||
DIY Alarm — Core
The core is the Arduino Mega 2560 firmware for a DIY wired/wireless intruder
- fire + water alarm. It talks to a Raspberry Pi bridge over USB serial (500 kbaud, CRC-framed), which in turn talks to Home Assistant and a Zigbee keypad / RFID reader.
Features
- 16 wired DEOL zones + 16 remote (serial-fed) zones, with optional RS485 expanders.
- Alarm state machine: exit delay → armed away/stay → entry delay → alarm.
- 24-hour zones: fire, water, panic, tamper.
- Outputs: sirens, buzzer, water valve, relays, indicators, chime.
- Credential-based arming/disarming (PIN + RFID), with a keypad programming mode.
- Fully non-blocking (
millis()-based timing, nodelay()).
Topology
Zigbee keypad / RFID ──► Raspberry Pi bridge ──USB serial──► Mega (this repo)
│
RS485 ── zone expanders (0 by default)
RS232 ── power-monitor Nano (AC / battery / 12V)
Key concepts
| Topic | Doc |
|---|---|
| Zones (types, states, DEOL, bypass) | docs/zones.md |
| Outputs (types, attributes, sirens/LEDs/buzzer) | docs/outputs.md |
| Alarm state machine & severities | docs/alarm-logic.md |
| Serial protocol (all commands + events) | docs/serial-protocol.md |
| Programming mode (PIN / RFID) | docs/programming.md |
| EEPROM layout & persistence | docs/eeprom.md |
| System overview & architecture | docs/architecture.md |
Repository layout
core/
src/ firmware (Arduino Mega)
main.cpp setup + loop
alarm.cpp alarm state machine glue
zones.cpp zone scanning / debounce
outputs.cpp outputs, sirens, LEDs, buzzer
serial_cmd.cpp command dispatch
pin.cpp PIN/RFID store + programming mode
expander.cpp RS485 zone-expander bus
power_monitor.cpp supply Nano (Serial2)
inputs.cpp panel inputs (reset button, AC/batt/12V)
telemetry.cpp status / zone reporting
eeprom_map.h central EEPROM region map
lib/
alarm_core/ pure, unit-tested logic (alarm, zones, timing, PIN, SHA-256)
serial_parse/ frame parsing + CRC8
test/ PlatformIO Unity tests (native)
docs/ documentation
platformio.ini build config
Building
PlatformIO:
# build the firmware
pio run -e megaatmega2560
# run the unit tests (native)
pio test -e native
The default environment is megaatmega2560 (ATmega2560, Arduino framework).
A second native environment runs the pure-logic unit tests on the host.
Configuration
Compile-time configuration lives in:
lib/alarm_core/config.h— zone/output counts, timings, thresholds, pins, enums.src/zone_config.cpp— per-zone type + attributes, zone pin map.src/output_config.cpp— per-output type + attributes, output pin map.src/eeprom_map.h— EEPROM region layout.
Credentials (PINs/RFID tags) are stored in EEPROM and managed via programming
mode; see docs/programming.md.
AI Usage
The overall design, features, and concepts of this project are the
maintainer's. An AI coding agent (Cline) was used as a collaborator during
development — the concepts were discussed with the AI, which helped with the
implementation. The documentation (this README and the docs/ set) was written
by the AI.
The maintainer actively reviewed and challenged the AI's responses where appropriate, and made the final design decisions.