Electronic Project 26: How to make a simple traffic light system in a single lane and a pedestrian lane with manual operation

in #utopian-io7 years ago (edited)

What Will I Learn?

At the end of this tutorial:

♦ The readers will be able to create a traffic light system

♦ The readers will be able to know how the circuit works.

♦ Learn to apply the circuit in real time scenario

Introduction

In this tutorial, we will create a simple traffic light mechanism that could be applied in real time scenario. Here we will program the arduino uno to make a traffic light system in a single lane and a pedestrian lane. At the pedestrian lane, there is a pushbutton that can be used by the people or traffic enforcer to directly activate the pedestrian lights. The switching of lights is only 30 seconds interval, green and red.

Requirements

Electronic Components

♦ Arduino Uno

♦ Pushbutton

♦ LED

♦ Resistor

♦ Breadboard

♦ Connecting wires

Software

♦ Fritzing application

Difficulty

♦ Intermediate

Tutorial Contents

Using the fritzing software, we will create our circuit diagram, arduino codes and prototype using the breadboard

Part I. Schematic Diagram

So first let us construct our circuit diagram.

image.png

Select the electronic components needed for the circuit in the fritzing library. We need 1 arduino uno, 1 pushbutton, 6 resistors and 5 LEDs.

image.png

Arrange the components before constructing the circuit.
In arranging the components, place all the components for the input side (left side) of the arduino and the components for the output side (right side).
In this tutorial the input components will be the pushbutton and a resistor. The rest of the components are for the output side.

image.png

Now let us construct our circuit diagram. At the input side of our microcontroller, we need one input pin for our pushbutton. Since the pushbutton is an analog input, so we will choose the analog inputs of our microcontroller. So in this tutorial I will select the analog pin 1.
The pushbutton will be connected to our 5V source output from the arduino uno and the other terminal is to be connected to the ground resistor.

image.png

While at the output side of our microcontroller is the traffic light system which is composed of 5 LEDs. So we need 5 digital output pins, 3 for the single traffic lights and 2 pins for the pedestrian lane traffic lights.
Each output pins must be connected first with a resistor to limit the current flow and to avoid damaging the led.

image.png

Now we will connect the led base from the single traffic lane and pedestrian lane. At the single traffic lane, 1 Green led, 1 Yellow led & 1 Red led. While at the pedestrian lane, we have 1 Green led and 1 Red led.

image.png

Here is our final circuit diagram.

image.png

At the single lane traffic light, the time interval between green and red light is 35 seconds. When the light is green (it means go) it is programmed for only 30 seconds, then after 30 seconds the yellow led will start to lights. It means the red led (stop light) is about to occur allowing vehicle to have time to stop. This 30 seconds is intended only for this tutorial, but in the real scenario it is above 30 seconds.

image.png

Then at the pedestrian lane, the moment the traffic light turns to red light, it will turn the green signal which means the crowd can now walk through the pedestrian lane and vice versa when light turns to green. The traffic enforcer can manually turns the green or red light at the pedestrian lane using the pushbutton.

image.png

Part II. Code

Now let us do programming of our Arduino uno.
Click on code to start.

image.png

We declare that the input pin of the pushbutton is analog pin 1 and the output pins are pin 9, 10, 11, 12 & 13.

int pushPin = 1;   // select the input pin for the pushbutton
int gpLed = 9; // select the pin for the green light for the pedestrian lane
int rpLed = 10; // select the pin for the red light for the pedestrian lane
int gsLed = 11; // select the pin for the green light for the single traffic lane
int yellowLed = 12; // select the pin for the yellow light for the single traffic lane
int rsLed = 13; // select the pin for the red light for the single traffic lane

image.png

int pushValue = 0;  // variable to store the value coming from the pushbutton

image.png

void setup() {
  // declare the pushPin as an INPUT:
  pinMode(pushPin, INPUT);
// declare the traffic light for pedestrian lane as an OUTPUT:
pinMode(gpLed, OUTPUT);
pinMode(rpLed, OUTPUT);
// declare the traffic light for single traffic lane as an OUTPUT:
pinMode(gsLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(rsLed, OUTPUT);
}

image.png

void loop(){
changeLights();
delay(30000); }
void changeLights(){
//green off, yellow on for 5 seconds
digitalWrite(gsLed, LOW);
digitalWrite(yellowLed, HIGH);
delay(5000);
//turn off the yellow led, then turn on the red led for 30 seconds
digitalWrite(yellowLed, LOW);
digitalWrite(rsLed, HIGH);
delay(30000);
// red led and yellow led for the single lane is turn on for 5 seconds
digitalWrite(yellowLed, HIGH);
delay(5000);
// turn off the  red and yellow led, then turn on the green led for the single lane traffic light
digitalWrite(yellowLed, LOW);
digitalWrite(rsLed, LOW);
digitalWrite(gsLed, HIGH);
delay(5000);
}

image.png

For the pedestrian lane traffic light

void loop(){
If (digitalRead(pushPin) == HIGH){
delay(10);
changeLights();
delay(10000); //wait for 10 seconds
}}

image.png

Here are our arduino codes.

int potPin = 1;   // select the input pin for the pushbutton 
int greenLed = 9; // select the pin for the green light for the pedestrian lane 
int redLed = 10; // select the pin for the red light for the pedestrian lane 
int greenLed = 11; // select the pin for the green light for the single traffic lane 
int yellowLed = 12; // select the pin for the yellow light for the single traffic lane 
int redLed = 13; // select the pin for the red light for the single traffic lane 
int pushValue = 0;  // variable to store the value coming from the pushbutton 
void setup() { 
  // declare the pushPin as an INPUT: 
  pinMode(pushPin, INPUT); 
// declare the traffic light for pedestrian lane as an OUTPUT: 
pinMode(greenLed, OUTPUT); 
pinMode(redLed, OUTPUT); 
// declare the traffic light for single traffic lane as an OUTPUT: 
pinMode(greenLed, OUTPUT); 
pinMode(yellowLed, OUTPUT); 
pinMode(redLed, OUTPUT); 
} 
void loop(){ 
changeLights(); 
delay(30000); } 
void changeLights(){ 
//green off, yellow on for 5 seconds 
digitalWrite(gsLed, LOW); 
digitalWrite(yellowLed, HIGH); 
delay(5000); 
//turn off the yellow led, then turn on the red led for 30 seconds 
digitalWrite(yellowLed, LOW); 
digitalWrite(rsLed, HIGH); 
delay(30000); 
// red led and yellow led for the single lane is turn on for 5 seconds 
digitalWrite(yellowLed, HIGH); 
delay(5000); 
// turn off the  red and yellow led, then turn on the green led for the single lane traffic light 
digitalWrite(yellowLed, LOW); 
digitalWrite(rsLed, LOW); 
digitalWrite(gsLed, HIGH); 
delay(5000); 
} 
void loop(){ 
If (digitalRead(pushPin) == HIGH){ 
delay(10); 
changeLights(); 
delay(10000); //wait for 10 seconds 
}}

Part III. Breadboard

Click on the breadboard.

image.png

Arrange each component in the breadboard before connecting.

image.png

Now connect each component if you don’t know how to connect using breadboard just read my previous tutorial about how to construct a circuit in the breadboard

image.png

Application

The readers can create their own traffic light system or a light signal.
Like the example below.

link source

Curriculum

Here are my other tutorials for electronic projects.

ELECTRONIC PROJECTS

Tutorial 1

Tutorial 2

Tutorial 3

Tutorial 4

Tutorial 5

Tutorial 6

Tutorial 7

Tutorial 8

Tutorial 9

Tutorial 10

Tutorial 11

Tutorial 12

Tutorial 13

Tutorial 14

Tutorial 15

Tutorial 16

Tutorial 17

Tutorial 18

Tutorial 19

Tutorial 20

Tutorial 21

Tutorial 22

Tutorial 24

Tutorial 25



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @rfece143 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 64349.20
ETH 2673.53
USDT 1.00
SBD 2.83