Density Based Traffic Control System Using Atmega32

Recent mini project I tutored my students at KLE Technological University.



Nowadays, controlling the traffic becomes major issue because of rapid increase in automobiles and also because of large time delays between traffic lights. So, in order to rectify this problem, we will go for density based traffic lights system. This article explains you how to control the traffic based on density.

In this system, we will use IR sensors to measure the traffic density. We have to arrange one IR sensor for each road; these sensors always sense the traffic on that particular road. All these sensors are interfaced to the microcontroller. Based on these sensors, controller detects the traffic and controls the traffic system.

This circuit consists of 4 IR sensors, atmega8 microcontroller, 4 traffic lights.

IR transmitter looks like an LED. This IR transmitter always emits IR rays from it. The operating voltage of this IR transmitter is 2 to 3v. These IR (infra red) rays are invisible to the human eye. But we can view these IR rays through camera.

IR receiver receives IR rays that are transmitted by IR transmitter. Normally IR receiver has high resistance in order of mega ohms, when it is receiving IR rays the resistance is very low. The operating voltage of IR receiver also 2 to 3V.

We have to place these IR pair in such a way that when we place an obstacle in front of this IR pair, IR receiver should be able to receive the IR rays. When we give the power, the transmitted IR rays hit the object and reflect back to the IR receiver.

Instead of traffic lights, you can use LEDs (RED, GREEN, YELLOW). In normal traffic system, you have to glow the LEDs on time basis. If the traffic density is high on any particular path, then glows green LED of that particular path and glows the red LEDs for remaining paths.

            Source: Electronicshub.org

    My Code: 

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#define R1 PB0
#define Y1 PB1
#define G1 PB2
#define R2 PB3
#define Y2 PB4
#define G2 PB5
#define R3 PD5
#define Y3 PD4
#define G3 PD3
#define R4 PD2
#define Y4 PD1
#define G4 PD0
int main(void)
{
DDRB = 0xff;
DDRD = 0xff;
DDRA = 0x00;

PORTB = 0x00;
PORTD = 0x00;

while(1)
{
PORTB = 0x00;
PORTD = 0x00;
if(!(PINA & (1 << 0)))
{
PORTB |= (1<<G1);
PORTB |= (1<<Y2);
PORTD |= (1<<R3);
PORTD |= (1<<R4);
_delay_ms(500);
}
else if(!(PINA & (1 << 1)))
{
PORTB |= (1<<R1);
PORTB |= (1<<G2);
PORTD |= (1<<Y3);
PORTD |= (1<<R4);
_delay_ms(500);
}

else if(!(PINA & (1 << 2)))
{
PORTB |= (1<<R1);
PORTB |= (1<<R2);
PORTD |= (1<<G3);
PORTD |= (1<<Y4);
_delay_ms(500);
}

else if(!(PINA & (1 << 3)))
{
PORTB |= (1<<Y1);
PORTB |= (1<<R2);
PORTD |= (1<<R3);
PORTD |= (1<<G4);
_delay_ms(500);
}

else
{
PORTB = 0x00;
PORTD = 0x00;

PORTB |= (1<<G1);
PORTB |= (1<<Y2);
PORTD |= (1<<R3);
PORTD |= (1<<R4);
_delay_ms(7000);

PORTB = 0x00;
PORTD = 0x00;

PORTB |= (1<<R1);
PORTB |= (1<<G2);
PORTD |= (1<<Y3);
PORTD |= (1<<R4);
_delay_ms(7000);

PORTB = 0x00;
PORTD = 0x00;

PORTB |= (1<<R1);
PORTB |= (1<<R2);
PORTD |= (1<<G3);
PORTD |= (1<<Y4);
_delay_ms(7000);

PORTB = 0x00;
PORTD = 0x00;
PORTB |= (1<<Y1);
PORTB |= (1<<R2);
PORTD |= (1<<R3);
PORTD |= (1<<G4);
_delay_ms(7000);
PORTB = 0x00;
PORTD = 0x00;
}
}
}

Code Structural Meaning:(For NOOBS ;-)

While(1){
if(sensor1 == 1){
//there is traffic in lane1
//lane 1 green
}
else if(sensor2 == 1){
//there is traffic in lane2 - green
}
else if(sensor3 == 1){
//lane3 - green
}
else if(sensor4 == 1){
//
}lane4 green
else{
//execute the normal system
lane 1 green
wait for 7 seconds
lane 2 green
wait 7 seconds
lane 3 green
wait 7 seconds
lane 4 
7 seconds
}




Comments

Popular Posts