Traffic lights with Arduino

01SemaforoInteligente005

Traffic lights, also known as traffic signals, traffic lamps, signal lights, or semaphores.

On 10 December 1868, the first traffic lights were installed outside the British Houses of Parliament in London, to control the traffic in Bridge Street, Great George Street and Parliament Street. They were promoted by the railway engineer J. P. Knight and constructed by the railway signal engineers of Saxby & Farmer.

The first electric traffic light was developed in 1912 by Lester Wire, an American policeman of Salt Lake City, Utah, who also used red-green lights. On 5 August 1914, the American Traffic Signal Company installed a traffic signal system on the corner of East 105th Street and Euclid Avenue in Cleveland, Ohio. It had two colors, red and green, and a buzzer, based on the design of James Hoge, to provide a warning for color changes. The design by James Hoge allowed police and fire stations to control the signals in case of emergency. The first four-way, three-color traffic light was created by police officer William Potts in Detroit, Michigan in 1920. In 1922, T.E. Hayes patented his “Combination traffic guide and traffic regulating signal” (Patent # 1447659). (Wikipedia)

Today, traffic lights examples can be used to teach, learn and practice microcontrollers basic concepts, and this is a little demonstration of what we do in our very first month of classes in Area1-Devry… the students starts from the very basics and can soon build their own projects and still keep eyes on microcontrollers deeper theory.

Thales Burque did a great job and in this video he shows us detailed information about his the problem proposed, the logic he designed to solve the problem, the C code developed and fully functional electronic simulation in Proteus-ISIS.

Thanks to Harisson Nobre for the great video using Arduino UNO!

This is the code provided by Harrison… can you make it better, shorter and/or faster? Post you suggestions here and let us all learn with each others!

int LED_VERD=11;
int LED_AMAR=12;
int LED_VERM=13;
void setup(){
pinMode(10,1);
digitalWrite(10,1);
pinMode(LED_VERD,OUTPUT);
pinMode(LED_AMAR,OUTPUT);
pinMode(LED_VERM,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(9,1);//ponto desligado
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,1);
digitalWrite(8,1);
}
void loop(){
int leitura=digitalRead(10);
digitalWrite(LED_VERD,HIGH);
if (leitura == 0) {
delay(4000);
digitalWrite(LED_VERD,LOW);
digitalWrite(LED_AMAR,HIGH);
delay(4000);
digitalWrite(LED_AMAR,LOW);
digitalWrite(LED_VERM,HIGH);
//escreve 5
digitalWrite(2,0);
digitalWrite(3,1);
digitalWrite(4,0);
digitalWrite(5,0);
digitalWrite(6,1);
digitalWrite(7,0);
digitalWrite(8,0);
delay(1000);
//escreve 4
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,0);
digitalWrite(8,0);
delay(1000);
//escreve 3
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(5,0);
digitalWrite(6,1);
digitalWrite(7,1);
digitalWrite(8,0);
delay(1000);
//escreve 2
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,1);
digitalWrite(5,0);
digitalWrite(6,0);
digitalWrite(7,1);
digitalWrite(8,0);
delay(1000);
//escreve 1
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,1);
digitalWrite(8,1);
delay(1000);
//escreve 0
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(5,0);
digitalWrite(6,0);
digitalWrite(7,0);
digitalWrite(8,1);
delay(1000);
//apaga tudo
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,1);
digitalWrite(5,1);
digitalWrite(6,1);
digitalWrite(7,1);
digitalWrite(8,1);
digitalWrite(LED_VERM,LOW);
}
}

Leave a Reply

*