Traffic light controllers are one of the most practical examples of real-time embedded systems used in cities across the world. They help regulate vehicle movement, reduce congestion, and improve road safety by following a proper red–yellow–green sequence. Using the ATmega16 microcontroller, we can build a simple and reliable traffic light controller to understand how timing, sequencing, and output control work in embedded applications. This experiment helps students learn how to configure I/O pins, generate accurate delays, and design a complete state-based sequence that mimics real traffic operation. By studying this system step-by-step, beginners get a clear idea of how embedded controllers manage real-time tasks, and how similar concepts are applied in more advanced smart traffic and automation systems
Understanding Traffic Light System
A typical intersection uses three main lights:
- Red — Stop
- Yellow — Wait / Ready
- Green — Go
The controller must ensure:
- No two directions get green at the same time.
- Each light follows the order: Green → Yellow → Red.
- Each state has a fixed delay duration.
Hardware Requirements
- ATmega16 microcontroller
- 9 LEDs: Red, Yellow, Green for each road
- 220Ω resistors (for current limiting)
- Power supply 5V
- Breadboard and jumper wires
Pin Configuration
In this project, we use PORTA and PORTB to drive the LEDs.
| LED Signal | ATmega16 Pin |
|---|---|
| Road A Red | PA0 |
| Road A Yellow | PA1 |
| Road A Green | PA2 |
| Road B Red | PB0 |
| Road B Yellow | PB1 |
| Road B Green | PB2 |
Traffic Light Timing Logic
The system follows four main states:
- State 1: Road A = Green, Road B = Red
- State 2: Road A = Yellow, Road B = Red
- State 3: Road A = Red, Road B = Green
- State 4: Road A = Red, Road B = Yellow
Green = 5 seconds
Yellow = 2 seconds
Red = Opposite road's green + yellow
C Program for ATmega16 — Traffic Light Controller
#include <avr/io.h>
#include <util/delay.h>
void roadA_green() {
PORTA = (1<<PA2); // Green ON
PORTB = (1<<PB0); // Road B Red
}
void roadA_yellow() {
PORTA = (1<<PA1); // Yellow ON
PORTB = (1<<PB0);
}
void roadB_green() {
PORTB = (1<<PB2); // Green ON
PORTA = (1<<PA0); // Road A Red
}
void roadB_yellow() {
PORTB = (1<<PB1); // Yellow ON
PORTA = (1<<PA0);
}
int main(void)
{
DDRA = 0x07; // PA0,PA1,PA2 as output
DDRB = 0x07; // PB0,PB1,PB2 as output
while(1)
{
// State 1: Road A Green
roadA_green();
_delay_ms(5000);
// State 2: Road A Yellow
roadA_yellow();
_delay_ms(2000);
// State 3: Road B Green
roadB_green();
_delay_ms(5000);
// State 4: Road B Yellow
roadB_yellow();
_delay_ms(2000);
}
}
Animated Traffic Light Diagram
The following animated diagram shows how the ATmega16 controls two road signals. As the program runs, both traffic lights switch between Red, Yellow and Green exactly like a real intersection.
Applications
- Real-time traffic signal design
- Smart city automation
- Mini-projects and engineering labs
- AVR based embedded system learning
Conclusion
Designing a traffic light controller using ATmega16 helps beginners understand real-time embedded logic, state machines, I/O programming, and timing functions. The same concept can be extended to more roads, sensors, pedestrian crossing systems, or adaptive traffic management systems. With this foundation, learners can step into building more advanced real-world smart automation projects.
Comments
Post a Comment
Subscribe to Post Comments [Atom]