Traffic light controller with timer display for a 4 road junction with any Micro

Hi every one,

I just joined this forum. I would like to do a project for traffic signal control. At present, our existing system is having 3 Digit 7 Segment LED Display as timer (to show the remaining time in seconds) and three lights RED, YELLOW & GREEN (as general standard) for each direction. The timers in every direction shows remaining time of its signal light i.e. RED or GREEN as the case may be.

My Idea is to use Bi-Color 3 Digit 7 Segment LED Displays in each direction and removing three lights i.e. RED, YELLOW & GREEN. Bi-Color LED used is RED-GREEN. During RED Signal, the timer i.e. Bi-Color 3 Digit 7 Segment LED Display will run the time in RED Color and during Yellow Signal, the timer will run in Yellow Color (Amber Color) i.e. by giving supply to both the anodes (if we use common cathode LEDs) at a time and during GREEN Signal, the timer will run in GREEN Color.

If we implement this, we can save 12 lights for a four road junction and traffic can be controlled with four timers (Bi-color LEDs). Can it be possible with one Microcontroller such as Arduino Uno.

Please guide me in this project. If any other options, with microcontrollers only, please suggest me.

Thanks

cpcbmurthy: Can it be possible with one Microcontroller such as Arduino Uno.

Here's a quick question, how many inputs does that 3 digit segment need to proper control?

Basically, it has to display the time in seconds like '180', '179' etc. I think 7 inputs for each digit are required.

cpcbmurthy: Basically, it has to display the time in seconds like '180', '179' etc. I think 7 inputs for each digit are required.

Then Arduino UNO is fine but you have to add some shift registers to add more output pins (74HC595). These IC are very cheap and not hard to understand.

Can you explain in details about the whole system.

Thank you,

cpcbmurthy: Can you explain in details about the whole system.

Thank you,

Basically the 74HC595 is a IC also known as shift register (google definition).

It uses 3 Arduino pins and gives you 8 outputs, in other words you gain 5 extra digital outputs. You'd need one 74HC595 for each digit on the display.

Google for "Arduino and 74HC595" you'll find many examples.

Even better, use one MAX7219 to drive up to four bi-colour 7-segment LEDs.

Mind you - I have no idea where you will get dual colour 7-segment LEDs. Can you give a link?

Thank you Mr. Paul,

The link for bi-color 7 segment display is as follows:

http://www.betlux.com/led/1.00-inch-single-seven-segment-led-display-bi-color-BL-S100E-12xx,BL-S100F-12xx.htm

Can I use LED Driver or shift register in my project to run four timers at a time with one arduino uno board.

A MAX7219 would be the go then. It can normally drive eight seven-segment digits, but for a bi-colour device, it can drive four digits, either common anode or common cathode though common cathode is easier to code.

It interfaces to the Arduino with three pins, and multiple MAX7219s can be chained together (four bi-colour digits each) so you only ever use the same three pins from the Arduino.

So, it means, I have to use MAX7219 four numbers for 4 directions i.e. for four counters.

Is there any way to check in the computer whether the total setup is working or not, without purchasing hardware? Please guide me.

Thank you,

cpcbmurthy: So, it means, I have to use MAX7219 four numbers for 4 directions i.e. for four counters.

Is there any way to check in the computer whether the total setup is working or not, without purchasing hardware? Please guide me.

Thank you,

Try Proteus, it's a software were you can simulate.

Can't imagine a simulator would simulate a MAX7219 but I could be wrong.

I can assure you the MAX7219 is the part for the job, as long as the display behaves as the datasheet suggests (it is a little confusing on some points, such as whether the LEDs in the segments are actually connected in series).

In practice, I suggest you get the parts, study the examples, have a go at it and get back to us here for assistance in coding.

Mr.Mart256,

I installed Proteus software, but how to write a program, load into arduino uno and its testing in this software (simulation). Please guide me.

Thanks

cpcbmurthy: Mr.Mart256,

I installed Proteus software, but how to write a program, load into arduino uno and its testing in this software (simulation). Please guide me.

Thanks

Haven't used Proteus in years. Look on youtube "Proteus and Arduino".

No Sir. I haven't used. This is 1st time.

Can you please tell me, if I written a program into Arduino uno for a particular project, later can I reload a new project by deleting old project/program.

Like that can I do as many time as I want.

Thank you

cpcbmurthy: Can you please tell me, if I written a program into Arduino uno for a particular project, later can I reload a new project by deleting old project/program.

Like that can I do as many time as I want.

Thank you

Yes you can rewrite programs as many times as you want.

Once the program written, loaded in arduion uno and used for few months, later, if I want to use this arduino uno for another project, can I use it, by erasing the existing program and loading the new program.

Thank you,

I done some part of my project i.e. Traffic Light Controller with Timer Display. Here is the code:

int digitR1 = 11; //To display the digit in Red color
int digitR2 = 10; //To display the digit in Red color
int digitR3 = 9; //To display the digit in Red color
int digitG1 = A2; //To display the digit in Green
int digitG2 = A3; //To display the digit in Green
int digitG3 = A4; //To display the digit in Green
int x = 0;

int segA = A1;
int segB = 3;
int segC = 4;
int segD = 5;
int segE = A0;
int segF = 7;
int segG = 8;

void setup() {

pinMode (segA, OUTPUT);
pinMode (segB, OUTPUT);
pinMode (segC, OUTPUT);
pinMode (segD, OUTPUT);
pinMode (segE, OUTPUT);
pinMode (segF, OUTPUT);
pinMode (segG, OUTPUT);

pinMode (digitR1, OUTPUT);
pinMode (digitR2, OUTPUT);
pinMode (digitR3, OUTPUT);
pinMode (digitG1, OUTPUT);
pinMode (digitG2, OUTPUT);
pinMode (digitG3, OUTPUT);

}

void loop() {

x = 200 - (millis()/1000);

displayNumber (x);

}

void displayNumber (int toDisplay){
#define DISPLAY_BRIGHTNESS 500

#define DIGIT_ON HIGH
#define DIGIT_OFF LOW

long beginTime = millis ();

for (int digit = 3; digit>0; digit–){
switch (digit){
case 1:
if (x >80)
{
digitalWrite (digitR1,DIGIT_ON );
}
else
{
digitalWrite (digitG1,DIGIT_ON );
}
break;

case 2:
if (x >80){
digitalWrite (digitR2,DIGIT_ON );
}
else {
digitalWrite (digitG2,DIGIT_ON );
}
break;

case 3:
if (x >80){
digitalWrite (digitR3,DIGIT_ON );
}
else {
digitalWrite (digitG3,DIGIT_ON );
}
break;
}
lightNumber (toDisplay % 10);
toDisplay /=10;
delayMicroseconds (DISPLAY_BRIGHTNESS);

lightNumber (10);

digitalWrite (digitR1, DIGIT_OFF);
digitalWrite (digitR2, DIGIT_OFF);
digitalWrite (digitR3, DIGIT_OFF);
digitalWrite (digitG1, DIGIT_OFF);
digitalWrite (digitG2, DIGIT_OFF);
digitalWrite (digitG3, DIGIT_OFF);
}
while ((millis ()- beginTime)<10);
}

void lightNumber (int numberToDisplay) {

#define SEGMENT_ON LOW
#define SEGMENT_OFF HIGH

switch (numberToDisplay){

case 0:
digitalWrite (segA,SEGMENT_ON);
digitalWrite (segB,SEGMENT_ON);
digitalWrite (segC,SEGMENT_ON);
digitalWrite (segD,SEGMENT_ON);
digitalWrite (segE,SEGMENT_ON);
digitalWrite (segF,SEGMENT_ON);
digitalWrite (segG,SEGMENT_OFF);
break;

case 1:
digitalWrite (segA,SEGMENT_OFF);
digitalWrite (segB,SEGMENT_ON);
digitalWrite (segC,SEGMENT_ON);
digitalWrite (segD,SEGMENT_OFF);
digitalWrite (segE,SEGMENT_OFF);
digitalWrite (segF,SEGMENT_OFF);
digitalWrite (segG,SEGMENT_OFF);
break;

case 2:
digitalWrite (segA,SEGMENT_ON);
digitalWrite (segB,SEGMENT_ON);
digitalWrite (segC,SEGMENT_OFF);
digitalWrite (segD,SEGMENT_ON);
digitalWrite (segE,SEGMENT_ON);
digitalWrite (segF,SEGMENT_OFF);
digitalWrite (segG,SEGMENT_ON);
break;

case 3:
digitalWrite (segA,SEGMENT_ON);
digitalWrite (segB,SEGMENT_ON);
digitalWrite (segC,SEGMENT_ON);
digitalWrite (segD,SEGMENT_ON);
digitalWrite (segE,SEGMENT_OFF);
digitalWrite (segF,SEGMENT_OFF);
digitalWrite (segG,SEGMENT_ON);
break;

case 4:
digitalWrite (segA,SEGMENT_OFF);
digitalWrite (segB,SEGMENT_ON);
digitalWrite (segC,SEGMENT_ON);
digitalWrite (segD,SEGMENT_OFF);
digitalWrite (segE,SEGMENT_OFF);
digitalWrite (segF,SEGMENT_ON);
digitalWrite (segG,SEGMENT_ON);
break;

case 5:
digitalWrite (segA,SEGMENT_ON);
digitalWrite (segB,SEGMENT_OFF);
digitalWrite (segC,SEGMENT_ON);
digitalWrite (segD,SEGMENT_ON);
digitalWrite (segE,SEGMENT_OFF);
digitalWrite (segF,SEGMENT_ON);
digitalWrite (segG,SEGMENT_ON);
break;

case 6:
digitalWrite (segA,SEGMENT_ON);
digitalWrite (segB,SEGMENT_OFF);
digitalWrite (segC,SEGMENT_ON);
digitalWrite (segD,SEGMENT_ON);
digitalWrite (segE,SEGMENT_ON);
digitalWrite (segF,SEGMENT_ON);
digitalWrite (segG,SEGMENT_ON);
break;

case 7:
digitalWrite (segA,SEGMENT_ON);
digitalWrite (segB,SEGMENT_ON);
digitalWrite (segC,SEGMENT_ON);
digitalWrite (segD,SEGMENT_OFF);
digitalWrite (segE,SEGMENT_OFF);
digitalWrite (segF,SEGMENT_OFF);
digitalWrite (segG,SEGMENT_OFF);
break;

case 8:
digitalWrite (segA,SEGMENT_ON);
digitalWrite (segB,SEGMENT_ON);
digitalWrite (segC,SEGMENT_ON);
digitalWrite (segD,SEGMENT_ON);
digitalWrite (segE,SEGMENT_ON);
digitalWrite (segF,SEGMENT_ON);
digitalWrite (segG,SEGMENT_ON);
break;

case 9:
digitalWrite (segA,SEGMENT_ON);
digitalWrite (segB,SEGMENT_ON);
digitalWrite (segC,SEGMENT_ON);
digitalWrite (segD,SEGMENT_ON);
digitalWrite (segE,SEGMENT_OFF);
digitalWrite (segF,SEGMENT_ON);
digitalWrite (segG,SEGMENT_ON);
break;

case 10:
digitalWrite (segA,SEGMENT_OFF);
digitalWrite (segB,SEGMENT_OFF);
digitalWrite (segC,SEGMENT_OFF);
digitalWrite (segD,SEGMENT_OFF);
digitalWrite (segE,SEGMENT_OFF);
digitalWrite (segF,SEGMENT_OFF);
digitalWrite (segG,SEGMENT_OFF);
break;

}
}

------------------- * -------------------- * ---------------------

With the above code, it is fine as countdown timer. It will start from 200 and counting down as 199 198 197 196…0 and stops there.

I want this circuit to be worked as timer (as auto reload) i.e. it has to start from 200 and count down to 0 and after 0, it has to reset to 200 and count down as before. This process has do continuously.

Here, I taken 200 as initial value. Option is required to change this in future.

Please guide me in this.

Thank you,

cpcbmurthy: Once the program written, loaded in Arduino UNO and used for few months, later, if I want to use this Arduino UNO for another project, can I use it, by erasing the existing program and loading the new program.

I would imagine you have figured it out by now but not only can you re-program ("download") the Arduino a substantial number of times (thousands) but since it is virtually impossible for you to write a program ("sketch") that runs correctly the first time, you must re-program the Arduino a substantial number of times just to get your first (and second, etc.) program to operate.

Precisely how often you do this and how long it is between one download and the next, is basically irrelevant.

As to your current code - it looks awful, but if you go back to your last posting and mark that code up according to the instructions for requesting help, notably items 7 and 9, then some of us may actually take a closer look at it.