Arduino Projects

Traffic Light System using Arduino

Traffic light system:

Traffic Light System using ArduinoIn this article, we will implement the State machine term. It’s a machine that can assume different but finite states. this has her the English name Finite State Machine, also short FSM, that the behavior of this machine is quite good indeed describes. The following points are part of this model, whereby I present the matter here in a very simplified way:


State transition


Let’s get back to our traffic light system that a lighting system to regulate traffic is and with different Colors works, changing the colors in any country is uniformly regulated. But we’ll meet first once clear about the individual possible traffic light phases.

traffic light system

The individual traffic light system phases are from the 1st to the 4th phase run through. Then it starts all over again. Of simplicity For the sake of this, we limit ourselves to one traffic light system for one direction of travel. The example certainly encourages experimentation and makes a lot of fun. The meaning of each color should be clear:

Red (stop driving)

Yellow (waiting for the next signal)

Green (driving)

Each individual phase has a fixed light duration. The road user must have enough time to perceive the individual phase and react accordingly. We will for our example The following light durations define which are certainly not reality because you don’t want to spend too long on the Wait for phase change. But you can choose the times as you wish adjust.

traffic light system

After the sketch has been transmitted, the traffic light system should switch to the Go through the 4 phases just shown and start all over again. But let’s first take a look at the parts list.

Required components Traffic light system:

One red led

One yellow led

One green led

Three 330 ohm resistors


Jumper wires

Or Ardest 5mm LED Traffic Light Module Board

LED Traffic Light system Module Board

traffic light system

This is 5mm LED Traffic Light system Module Board using this board, we do not need to use a resistor because the resistor is already mounted on the board.

LED Traffic Light system Module Board pin description:

traffic light system

There are four labels over board the R, the Y, G and the gnd. R is red, Y is yellow, G is green and gnd is the ground.

I am not using the traffic light system module in this project. I am using LEDs and resistor as you can see in the below circuit diagram

Amazon product purchase links:

Arduino Uno:

Mega 2560:

330-ohm resistors pack:

5×7 cm Vero board:

female headers:

connection wires:

Bread Board:

12v Adaptor:

5mm LED Traffic Light Module Board

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Arduino traffic light system circuit diagram:

traffic light system

the circuit diagram is very simple as you can see I connected red led with Arduino pin 7, yellow led with Arduino pin 6 and green led with Arduino pin 5, and gnd with Arduino gnd pin. in this circuit I used 330ohm resistors.

traffic light system Arduino program:

Code explanation:

The command #define is actually not a real command, but a preprocessor directive. Remember the #include preprocessor directive. You can recognize it by the fact that there is no semicolon at the end of the line which usually marks the end of a command. When the compiler begins translating the source code begins, processes a special part of the compiler the preprocessor directives, always with the hash sign # be initiated. You will learn in the course of this book know other such directives. The #define directive allows us the use of symbolic names and constants. Here I am using

The line works like this: Wherever the compiler in the Sketch code finds the identifier DELAY1, it replaces it with the value 10000.

The line works like this: Wherever the compiler in the Sketch code finds the identifier DELAY2, it replaces it with the value 2000.

The line works like this: Wherever the compiler in the Sketch code finds the identifier DELAY3, it replaces it with the value 3000.

then I define the variables for LEDs and assign them to the Arduino pins.

in the setup() function I initialize the LED pins as an output

in loop() function I write the basic controlling code which controls the LEDs using digitalwrite and delays. The code is very simple.

Implement a traffic light system:

Implement a traffic light switch at an intersection. The following sketch should serve as a basis for a suitable introduction Find.

traffic light system

The traffic light system pairs A and B are to be activated in the same way. This time there is no pedestrian crossing. Make sure that if one direction gets a red light, the other does not immediately turn green. It should have been a safety buffer be planned for the driver when switching Just chase from green to red across the intersection.

project final test:


Related Article:

16×2 LCD and i2c LCD with Arduino Examples


Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button