Main Content

Pedestrian traffic light for an Arduino by using YAKINDU Statechart Tools to implement a Finite State Machine (FSM) in C and C++.

I’m going to show you how to program a pedestrian traffic light for Arduino for C++ with a finite state machine by using YAKINDU Statechart Tools. This will demonstrate the power of state machines and can be used as a blueprint for further projects.

Pedestrian Traffic Light
At first, I need to specify how the pedestrian traffic light should work. I’ve tried to summarize the bullet points:

- Two traffic lights are used - one for the cars, the other for the pedestrians
- Traffic light can be turned on by using a button
- Pedestrian can request crossing the street by pressing a button
- Turned off traffic light is indicated by blinking both yellow LEDs
- After turning on, the traffic light waits for 10 seconds in safe mode
- After safe mode, cars always have a green phase until a pedestrian starts a request
- Pedestrian request for crossing is indicated by toggling yellow LED

Additionally, there are some time events depending on the way of how a traffic light works.

Build the Circuit
Let’s start set up the circuit. In my example, as you can see on the preview image, I’ve used a Arduino Mega 2560, but every other Arduino with at least eight GPIOs should be fine. Additionally, I’ve bought some 5V traffic lights at Amazon. Just search for Traffic Light Arduino. Otherwise, you can simply use six different LEDs. Furthermore, you need two push buttons and two 10k Ohm resistors.”

Link to article

Related Content