Skip to content

nizarbadriali/Sensor-Traffic-Light

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Sensor-Traffic-Light

Sensor-triggered traffic light using a finite state machine and non-blocking timing.

Description

An HC-SR04 ultrasonic sensor watches for approaching objects. When triggered, a full traffic light sequence runs: red hold → green → yellow → cooldown. Built using a finite state machine with non-blocking timing via millis().

Components

  • Arduino Uno
  • 1x HC-SR04 Ultrasonic Sensor
  • 1x Red LED
  • 1x Yellow LED
  • 1x Green LED
  • 3x 220Ω resistors
  • Breadboard + jumper wires

Wiring

Component Arduino Pin
Red LED (+) Pin 13
Yellow LED (+) Pin 11
Green LED (+) Pin 8
All LED (-) GND via 220Ω resistors
HC-SR04 Trig Pin 12
HC-SR04 Echo Pin 10
HC-SR04 VCC 5V
HC-SR04 GND GND

State Machine

State Behavior Duration
IDLE_RED Red on, waiting for sensor Until triggered
RED_DELAY Red holds before changing 3 seconds
GREEN Green on 5 seconds
YELLOW Yellow on 2 seconds
COOLDOWN_RED Red on before resetting to idle 5 seconds

Skills Demonstrated

  • Non-blocking timing with millis()
  • Finite state machine design with enum
  • Ultrasonic sensor driving multi-output logic
  • Modular helper functions

About

Sensor triggered traffic light system

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages