sentinel-arduino-firmware

Public

@yousefaliaicha

Download board files

Files for version 1. Pick what you came for.

Share sentinel-arduino-firmware

Check access before sharing the link.

Who can open this board

Anyone can open this board. No sign-in is required.

This link opens the latest version. Copying it does not grant additional access.

Loading…

README

SENTINEL — Adaptive Traffic-Light FSM v1.0

A deterministic, fully offline traffic-light controller running on the Arduino UNO R3 (ATmega328P). SENTINEL manages a 3-LED traffic junction, a multiplexed 7-segment countdown display, a pedestrian crossing system, and an automated night-mode vehicle detection pipeline — all in a single non-blocking loop with no external libraries.


Features

FSM Core

  • Three-state machine: RED (30s) → YELLOW (5s) → GREEN (25s) → YELLOW (5s) → repeat
  • End-of-phase warning blink on RED (600ms period) and GREEN (300ms period) during the final 3 seconds
  • 7-segment countdown display driven through a 74HC595 shift register, multiplexed at 2ms intervals across two active digits — no delay() in the display path

Pedestrian Crossing

  • TTP223 capacitive touch sensor triggers a 10-second safe-passage window
  • If triggered with 15 seconds or less remaining in RED: activates immediately
  • If triggered with more than 15 seconds remaining: queues for the next RED phase
  • One crossing per RED cycle — subsequent touches in the same cycle are ignored
  • Buzzer pulses at 880 Hz (double-beep, 600ms interval) during crossing, escalating to 1050 Hz (single-beep, 300ms interval) in the final 3 seconds

Night Mode

  • LDR sampled every 500ms on A0 via a 1kΩ voltage divider
  • Night mode arms when LDR ADC reading drops below 50
  • After 15 seconds into a RED phase, HC-SR04 begins scanning every 60ms
  • If a vehicle is detected within 20 cm continuously for 2 seconds: RED warning blink (200ms period, 2s duration), then immediate GREEN at a shortened 10-second duration
  • Night RED is also shortened to 25 seconds on the following cycle

Serial Diagnostics (9600 baud)

CommandEffect
L / lPrint current LDR ADC value, threshold, and DAY/NIGHT status
D / dPrint last sonar distance reading in cm
S / sFull FSM snapshot: state, elapsed time, remaining time, night mode status, pedestrian flags

Hardware Requirements

ComponentQuantityNotes
Arduino UNO R31ATmega328P, 5V logic
Red, Yellow, Green LED (5mm)1 eachStandard diffused, Vf 2.0–2.2V
220Ω resistor3Current limiting, one per traffic LED
Active buzzer (5V)1Built-in oscillator, draws ~30mA — must be transistor-driven
2N2222 NPN transistor1Buzzer driver — keeps MCU pin current at ~5mA
1kΩ resistor22N2222 base resistor + LDR voltage divider pull-down
10kΩ resistor12N2222 base pull-down, keeps buzzer off at boot
TTP223 touch sensor module1Capacitive, 2.5–5.5V, clean HIGH/LOW output
74HC595 shift register18-bit serial-to-parallel, drives segment lines
4-digit 7-segment display1Common Anode or Common Cathode — verify before wiring, set flag in firmware
HC-SR04 ultrasonic sensor15V supply, 5V ECHO output
LDR (photoresistor)1Ambient light sensing
100nF ceramic capacitor1Decoupling cap on 74HC595 VCC pin

Wiring

Full pin-level connection map is in WIRING.md.

Arduino PinConnected to
D2Red LED (via 220Ω)
D3Yellow LED (via 220Ω)
D4Green LED (via 220Ω)
D52N2222 base (via 1kΩ) — drives buzzer
D6TTP223 SIG (touch sensor)
D774HC595 SRCLK (shift clock)
D874HC595 RCLK (latch clock)
D974HC595 SER (serial data)
D107-segment DIG4 (ones digit)
D117-segment DIG3 (tens digit)
D12–D137-segment DIG1–DIG2 (driven HIGH, unused)
A0LDR signal (voltage divider mid-point)
A1 (D15)HC-SR04 TRIG
A2 (D16)HC-SR04 ECHO

Note on A1/A2: the ATmega328P analog pins double as digital I/O (D15/D16). Using them here frees all of D0–D13 for the LED, buzzer, shift register, and digit lines.

Note on CC/CA: before wiring the 7-segment display, confirm whether it is Common Cathode or Common Anode using a coin cell test. Set the #define COMMON_CATHODE flag at the top of sentinel.ino accordingly. Wiring the wrong type will produce no output.

PCB Design

A custom PCB was designed in KiCad, integrating all components onto a single board: Arduino UNO R3 footprint, 74HC595 shift register, 4-digit 7-segment display, 2N2222 buzzer driver circuit, traffic LEDs with current-limiting resistors, custom-designed TTP223 touch sensor footprint, LDR voltage divider, and HC-SR04 connector pads. KiCad project files are in hardware/.


Software Setup

1. Prerequisites

  • Arduino IDE 2.x
  • No external libraries required — the sketch uses only Arduino built-ins (tone(), pulseIn(), millis())

2. Configure Display Type

At the top of sentinel.ino, set the flag matching your display:

#define COMMON_CATHODE true   // true for CC, false for CA

3. Flash the Board

  1. Open firmware/sentinel/sentinel.ino in Arduino IDE
  2. Select Tools → Board → Arduino Uno
  3. Select the correct port under Tools → Port
  4. Click Upload

On boot, SENTINEL runs a hardware self-test: all three LEDs fire simultaneously, both active display digits show 8, and the buzzer chirps once. The system then enters STATE_RED and the countdown begins.


How It Works

SENTINEL uses a single non-blocking loop() — no delay() calls in the main execution path. Every timed action is gated by millis() interval checks, keeping the MCU free to service sensors, inputs, and the display multiplexer on every tick.

Cycle diagram:

RED (30s) ──► YELLOW (5s) ──► GREEN (25s) ──► YELLOW (5s) ──► RED ...
    │                               │
    │ [touch, <=15s remaining]      │ [touch while GREEN]
    ▼                               ▼
 PED WINDOW (10s)            queued for next RED
    │
    ▼
 back to RED remainder

RED (night, >=15s elapsed + car at <=20cm for 2s)
    │
    ▼
 NIGHT WARNING (200ms blink, 2s)
    │
    ▼
 GREEN NIGHT (10s) ──► YELLOW (5s) ──► RED NIGHT (25s) ...

Night mode substate machine:

SubstateCondition to advance
NIGHT_IDLE15 seconds elapsed in current RED phase
NIGHT_POLLINGVehicle within 20 cm for 2 continuous seconds
NIGHT_WARNING2-second warning blink completes
NIGHT_DONELocked out for the remainder of the current RED cycle

Timing Reference

ParameterValue
RED duration (day)30s
RED duration (night, post-override)25s
GREEN duration (day)25s
GREEN duration (night override)10s
YELLOW duration5s
Pedestrian window10s
End-of-phase warning blinklast 3s
Night mode sonar arm delay15s into RED
Vehicle confirmation hold2s continuous
Sonar poll interval60ms
LDR sample interval500ms
Display mux interval2ms

License

MIT License — see LICENSE for full terms.

Comments

No comments yet. Be the first to ask about this board.

Ask about this board

Sign in to BoardRepo

New here? Signing in creates your account; there is no separate sign-up.