Traffic Lights With an Arduino

by IshandeepK in Circuits > Arduino

307 Views, 0 Favorites, 0 Comments

Traffic Lights With an Arduino

Traff.png

Hello, my name is Ishandeep, and on this Instructible I will be presenting the project I made for my Computer Engineering Final Project, I have made an Arduino Traffic Light System. I chose to do this project because I thought it would be cool to build a working Traffic Light by using an Arduino, I also thought it would be funny if I added something like a LEGO car to the project when I wanted to demonstrate how it works.

With this project, I will be replicating a real-life Traffic Light, which shows Traffic Lights that go from Red, Green, and Yellow. You must click the Push-Button for the Traffic Light to change colours.

I have incorporated a 3-second time limit for each Traffic Light with a 7 Segment Display, and I have used a Mini Piezo Buzzer to make it beep every second that elapses.

Now that you're familiar with my project, let's look at some of the materials required to build the project itself

Gather the Materials

ok this the one.jpg

READ:

Initially, I planned to build the traffic lights without a Mini Piezo Buzzer, but later I decided to add one. Check out the images below to see where I added the Buzzer. Apologies for any inconvenience.

Plan the Project

tinkercad design.png
schematic.png

I believe that planning and having a clear idea of what you're going to do on a project is the best way to go. In these designs, I made the project I was going to make in real-life on a Breadboard, but I made it on TinkerCAD, and this helped assure me that the project would work when I tried building it by hand.

Planning the project helped me create a neat and tidy Breadboard when I built the project by hand, and I recommend everyone should do this before starting a new project as it helped me a lot.

Place Down the Components

Part 1 Wiring.jpg
Real Part 1.jpg

Here are some pictures of how the Components should be placed before we start wiring them!

Make sure to neatly place down every component so the project can be as neat as possible!

READ:

Initially, I planned to build the traffic lights without a Mini Piezo Buzzer, but later I decided to add one. Check out the images below to see where I added the Buzzer. Apologies for any inconvenience.

Wiring

Wiring 1.jpg
IMG_2011.jpg
Wiring 3.jpg
7 Segment Display Labelled.png

Here is how I did the Wiring for these Traffic Lights. I tried to be as neat as possible and made sure to correctly trim every single Wire I placed, I suggest you do the same.

Tips:

  • Try using your hands to straighten the wires
  • Rather than having wires all over the place, try to bend them at a 90-degree angle to make them more neat and organized

If you're confused about my wiring, you can check out the code I made, or read below ↓↓↓

7 Segment Display:

Check out the Diagram I have given about 7 Segment Displays above. In the code below, the numbers represent the pins on the Arduino UNO. The letters represent pins on the 7 Segment Display. If you look at the 7 Segment Display, there are letters ranging from a - g. To wire this correctly, Wire one end of a Wire to the pin specified on the Arduino, and wire the other end of the wire onto the letter specified on the 7 Segment Display. For example, on the Arduino, pin 12 would connect to the top right of the 7 Segment Display. Pin 9 on the Arduino would connect to the bottom left of the 7 Segment Display. It gets easier with more practice, as I was also confused about how to wire 7 Segment Displays!!

7 Segment Display Code:

int a = 13;

int b = 12;

int c = 11;

int d = 10;

int e = 9;

int f = 7;

int g = 8;

LEDs, Buttons, and Buzzer:

This is where it gets a lot easier! Now, all you have to do is look at the number specified on each of the components on the Arduino Code, and wire it to the positive leg of the LEDs and Buzzer, and the left leg of the Push-Button in this case.

LEDs Code:

int RED = 6;

int YELLOW = 5;

int GREEN = 4;

Push-Button Code:

int push = 3;

Buzzer Code:

int buzzer = 2;

Upload the Code!

Wiring 2.jpg
arduinooo logoooo.png

Now that everything is finished, upload the code I have made!!!

I have added comments to the Arduino Code to make the Code easier to understand.

The Code is at the bottom.

The Game In-Depth:

  • The game starts off with a Red LED on
  • When you click the Push-Button, the 7 Segment Display starts counting down
  • It starts a 3 second countdown with the 7 Segment Display, and it plays a BEEPING sound every second that passes on the 7 Segment Display
  • Once it reaches 0 seconds, the Green Traffic Light turns on, which indicates to you that you can move your car forwards
  • You have about 3 seconds with the Green Traffic Light, and it also turns off after about 3 seconds
  • When the Green Traffic Light turns off, the Yellow Traffic Light turns on
  • When the Yellow Traffic Light is on, you once again have about 3 seconds to either stop your car before the intersection, or quickly get through the intersection in time, which is similar to real-life driving
  • After these 3 seconds, the game automatically resets

I tried to make this game like a real-life intersection with Traffic Lights, and I believe I succeeded.

HERE IS THE CODE :)

Video of the Traffic Light Working

Ishandeep - Arduino Traffic Lights

Here is a cool video of my Traffic Light

I hope you liked the project!

:)