Density-Based Traffic Light Control in Atmega32 using ATMEL STUDIO

Density Based Traffic Light Control in Atmega32 using ATMEL STUDIO

Due to the fast growth of automobiles and the lengthy intervals between traffic signals, regulating the flow of traffic has become a significant problem in modern times. We shall thus use Density Based Traffic Signal System using a Microcontroller to solve this issue. In this tutorial, you will learn how to manage Density Based Traffic Light Control in Atmega32 Microcontroller.

Video

In this video you will clearly understand the usage of density based traffic light control in atmega32.

In this system, the traffic density will be measured using IR sensors. One IR sensor must be placed on each road; the traffic on that road is regularly detected by this sensor. All these sensors have interfaces with the microcontroller. The controller can monitor traffic and control the traffic system thanks to these sensors.

Components of a Density Based Traffic Light Signal System using a Microcontroller

The components used in this system are:

Components:

  • Atmega32 microcontroller
  • 12 signal lights (4-green, 4 red, 4-yellow)
  • 4 Infrared Sensors, 1 for each root
  • Connecting wires
  • 4 resistors for voltage control

 Density-Based Traffic Signal System using a Microcontroller Circuit Design

4 IR sensors, an ATmega8 microprocessor, and traffic lights make up this circuit. The IR transmitter resembles an LED. This IR transmitter continuously generates IR rays. This IR transmitter’s operational voltage range is 2 to 3 volts. The human eye cannot see these infrared (IR) rays. But a camera may be used to see this infrared light.

IR transmitter sends out IR rays, which are received by the IR receiver. When an IR receiver is receiving IR rays, its resistance, which is typically in the mega ohm range, is very low. The IR receiver’s working voltage ranges from 2 to 3V.

These IR pairs must be positioned so that, even with an obstruction in their path, the IR receiver can still receive the IR rays. When we provide power, the IR rays that are being transmitted strike the item and bounce back to the IR receiver.

Use LEDs in place of traffic lights (RED, GREEN, YELLOW). In a regular traffic system, you must time the LED illumination. If there is a lot of traffic on a particular path, the green LED for that path will glow together with the red LEDs for the other paths.

In a typical traffic system, we give each path of the traffic a one-minute time delay.

Working of Density-Based Traffic Light System

Usually, there is a simple traffic control system. But, we have added functionality here which is a density based traffic signal system using Microcontroller. Here we have two modes to function this traffic control system:

1) Normal mode

Every root is given a set amount of time to pass moving vehicles. For instance, after root 1, when traffic has passed, a delay will occur, followed by root 2 turns, a delay, root 3 turns, and so on.

2) Density based mode

If any root density or traffic is higher in density based mode, that root will be given more time to pass vehicles, and when traffic becomes lighter, another root will be given permission to pass vehicles.

Let us understand this concept using a real-life example,

We want this root to only become open and other roots to become closed if the Prime Minister is going through root 1 and that root is experiencing more traffic.

There are two methods to go about this.

  1. Allow the sensor to operate freely, which indicates that the sensor is detecting more vehicles on this root. This will cause the LED light to remain green for an extended period, indicating that only all vehicles can pass through this root and that all others are blocked.
  2. A toggle switch that signals only a particular root is permitted to pass vehicles is attached. Let’s assume that this root is busy, which will undoubtedly have an impact on all others as well. Additionally, in this case, the obstacle sensor will send the value 1 to our microcontroller, and the microcontroller will keep switching that root.

Density-Based Traffic Signal System using a Microcontroller in Proteus

1. Normal Way of Running Traffic

First, construct the solution by pressing the F7 key and launching your stored hex file from the location. Before launching the project, all the roots’ sensors showed a value of 0, indicating that they were unable to detect any traffic. Normal 4 way Trafic Light Signals Now that the project is running, we can see that root 1 has been granted permission to pass traffic, root 2 is prepared to begin, and roots 3 and 4 are blocked. Normal mode 4 way Trafic Light Signals.jpg In addition, root 2 is now able to pass cars after a little wait, while root 3 is preparing to begin and other roots are obstructed. All other roots will also function with it. Density-Based Traffic Light Control in Atmega32 and Atmel studio 7

2. Density-Based Running Traffic

Let’s imagine we have traffic on root number 3 three. If we click the toggle button when it is on, the green light will be on, meaning that traffic can only travel via root number 3 at that time. Additionally, the other root is allowed to prepare for passing traffic, and the remaining two roots are blocked. Density-Based Traffic Light Control in Atmega32 and Atmel studio1 Additionally, the sensor will begin flowing traffic normally when it detects less traffic at the root. The same idea will apply to other roots as well. Density-Based Traffic Light Control in Atmega32 and Atmel studio2

Limitations

  • Occasionally, the IR sensors in this circuit will also absorb visible light. The traffic system consequently runs inefficiently.
  • IR sensors only operate over short distances.
  • Additionally, the IR sensors need to be positioned precisely to assess traffic density accurately

Code

//Density Based 4 Way Traffic Light Control System
.INCLUDE "M32DEF.INC"

CBI DDRA,0  // pa0 configured as input
CBI DDRA,1  // pa1 //
CBI DDRA,2  // pa2 //
CBI DDRA,3  // pa3 //

SBI DDRC,0 // pc0 configured as an output
SBI DDRC,1 // PC1 //
SBI DDRC,2 // PC2 //
SBI DDRC,3 // PC3 //
SBI DDRC,4 // PC4 //
SBI DDRC,5 // PC5 //

SBI DDRD,0 //PD0 //
SBI DDRD,1 // PD1 //
SBI DDRD,2 //PD2 //
SBI DDRD,3 //PD3 //
SBI DDRD,4 //PD4 //
SBI DDRD,5 //PD5 //

LDI R16,0X00
OUT PORTC,R16
OUT PORTD,R16

LOOP1:  // LOOP FOR ROOT1


 SBIS PINA,0 // IF PINA HAS 1 THEN SKIP NEXT INSTRUCTION
 JMP LOOP2
 SBI PORTC,2  // GREEN1 LIGHT ON
 SBI PORTC,4 // YELLOW 2 //
 SBI PORTD,5// RED 3//
 SBI PORTD,2 // RED4 //
 CALL DelayMEGA
 
 LDI R16,0X00
 OUT PORTC,R16   
 OUT PORTD,R16
 JMP LOOP1

LOOP2:  // LOOP FOR ROOT2
 SBIS PINA,1 //PA1
 JMP LOOP3
 SBI PORTC,0 //RED1 LIGHT ONN
 SBI PORTC,5 //GREEN2 //
 SBI PORTD,4 //YELLOW5 //
 SBI PORTD,2 //RED4 //

 CALL DelayMEGA
 LDI R16,0X00
 OUT PORTC,R16
 OUT PORTD,R16
 JMP LOOP2

LOOP3:  // LOOP FOR ROOT3
 SBIS PINA,2 //PA2
 JMP LOOP4
 SBI PORTC,0 // RED1
 SBI PORTC,3 // RED2 //
 SBI PORTD,3 //GREEN3 //
 SBI PORTD,1 // YELLOW4 //

 CALL DelayMEGA
 LDI R16,0X00
 OUT PORTC,R16
 OUT PORTD,R16
 JMP LOOP3

LOOP4: // LOOP FOR ROOT4
 SBIS PINA,3  // IF PA3 HAS=1 THEN SKIP NEXT INSTRUCTION
 JMP NORMALDENSITY
 SBI PORTC,1  //YELLOW1 //
 SBI PORTC,3  //RED2 //
 SBI PORTD,5  //RED3 /
 SBI PORTD,0  //GREEN 4

 CALL DelayMEGA
 LDI R16,0X00
 OUT PORTC,R16  // CLEARING PORTC
 OUT PORTD,R16  // CLEARING PORTD
 JMP LOOP4

NORMALDENSITY: // ROOTS FOR ALL ROOTS  AFTER FIX DELAY
 SBIC PINA,0
 JMP NORMALDENSITY
 SBI PORTC,2  // GREEN1 LIGHT ON
 SBI PORTC,4 // YELLOW 2 //
 SBI PORTD,5// RED 3//
 SBI PORTD,2 // RED4 //
 CALL DelayMEGA
 CALL DelayMEGA

 LDI R16,0X00
 OUT PORTC,R16
 OUT PORTD,R16

 SBIC PINA,1 // IF PA1=0 THEN SKIP NEXT INSTRUCTION.
 JMP NORMALDENSITY
 SBI PORTC,0 //RED1 LIGHT ONN
 SBI PORTC,5 //GREEN2 //
 SBI PORTD,4 //YELLOW5 //
 SBI PORTD,2 //RED4 //
 CALL DelayMEGA
 CALL DelayMEGA

 LDI R16,0X00
 OUT PORTC,R16
 OUT PORTD,R16

 SBIC PINA,2
 JMP NORMALDENSITY
 SBI PORTC,0 // RED1
 SBI PORTC,3 // RED2 //
 SBI PORTD,3 //GREEN3 //
 SBI PORTD,1 // YELLOW4 //
 CALL DelayMEGA
 CALL DelayMEGA

 LDI R16,0X00
 OUT PORTC,R16
 OUT PORTD,R16

 SBIC PINA,3
 JMP NORMALDENSITY
 SBI PORTC,1  //YELLOW1 //
 SBI PORTC,3  //RED2 //
 SBI PORTD,5  //RED3 /
 SBI PORTD,0  //GREEN 4
 CALL DelayMEGA


 LDI R16,0X00
 OUT PORTC,R16  // CLEARING PORTC
 OUT PORTD,R16  // CLEARING PORTD
 CALL DelayMEGA
 
 JMP LOOP1 //INFINITE LOOP

 


 DelayMEGA:                               // function used for delay                      

ldi     R18,byte3(11* 1000 * 100 / 5)
ldi     R17,high(11* 1000 * 100 / 5)
ldi     R16,low(11* 1000 * 100 / 5)

subi    R16,1
sbci    R17,0
sbci    R18,0
brcc    pc-3

ret

Additionally, If you want to see the project Water Level Indicator Using Atmega32  then visit our website.

Leave a Comment

Your email address will not be published. Required fields are marked *