top of page
Writer's pictureErika Camilleri

Arduino 4 Fixed Period Traffic Lights

Updated: Dec 14, 2023

We use traffic lights because they deliver efficient traffic flow. It may not seem like it, but due to trafflic lights, overall travel time is reduced, therefore less fuel is wasted, and less minor accidents happen. A fixed period traffic light system is relatively simple to build using Arduino Maker Uno X.

How does a fixed period traffic light system work?

How traffic light signals change.

Traffic light signals are universal and we should all know what each light signal means. Generally speaking, a steady red light is for stop, a steady green light is for go, and amber acts as an in-between for one of the main signals. This is explained visually in the diagram on the right.


We will be building a fixed-period traffic signal that changes according to a pre-defined time interval. The light signals cycle in a loop for ever.


We still use pre-timed traffic lights today because they work well on roads with predictable traffic patterns and slow speeds.


In this lesson... 📝

  • All the lessons we did have been preparing us to build a simple traffic light system. You will learn how to approach a problem presented to you based on a real life scenario.

The specifics of what you will build

The mechanics of our fixed period traffic light system.

We will build a fixed-period traffic light system that starts a signal cycle starting from a steady red signal on a push of a button. Main signals, i.e., Stop and Go last for 5 seconds, while in-between signals only last for 3 seconds. During the in-between signal from Go to Stop, a buzzer will triggered to alert drivers to slow down and prepare for a stop. This is a minor improvement to discourage excessive speeding to avoid stopping at the red light.

Build your circuit

Basic Circuit Setup Without Analogue Buzzer (Easy)

Write your program


Visualising our logic in the form of a flowchart first will make coding the actual thing feel like a breeze! You should remember the symbols from Chapter 51. Do not worry if you do not yet. You just need a little bit more practice.


Study the flowchart and convert it into C++ to program your circuit. You can use any of the code snippets from previous lessons:

  • Arduino 1 | Blinking Lights

  • Arduino 2 | Simple Circuits

  • Arduino 3 | External Input Components

Traffic Light Signal Flowchart












































Test your work

All syntax errors must be resolved!

Chapter 47 talks about testing in detail. Ensure that you do not have any syntax errors as these negatively impact functionality greatly. If your code builds, then analyse the components to make sure that they are behaving correctly. You might have a small bug, which we normally refer to as a logical error. Dealing with such errors is normal, but practice is key as well as an eye for detail and patience.


Great work!

If you got this far, congratulations, you have reached an important milestone. Have you reached all the success criteria without looking at the solution? If so, that is fanstastic, and you will find the SBA easy to do. If you are not at this stage yet, do not give up just yet. Keep moving forward.



330 views0 comments

Comments


bottom of page