- Project Overview
- Project Objectives
- Prerequisites
- Project Steps
- Expected Deliverables
- Getting Started
- License
- Contact
This project simulates a basic traffic light system using an ATmega328P microcontroller. The system uses three LEDs (red, yellow, and green), with each light turning on sequentially every 3 seconds. It also includes a maintenance switch to turn off the entire system when needed.
The project is ideal for beginners in embedded systems and microcontroller programming, offering real-world traffic system behavior in a simple and understandable form.
Simulate a real-world traffic light system using ATmega328P.
Use a physical switch to toggle the system for maintenance purposes.
Ensure only one LED is on at a time for accurate simulation.
Practice programming in embedded C using AVR-GCC or Atmel Studio.
ATmega328P microcontroller
Basic knowledge of C programming for microcontrollers
Breadboard and jumper wires
3x LEDs (Red, Yellow, Green)
3x 100Ω resistors
1x Pushbutton switch
5V power supply or USBasp programmer
(Optional) Proteus simulation software
Connect:
PB2 → Red LED (with resistor)
PB3 → Yellow LED (with resistor)
PB4 → Green LED (with resistor)
PD2 → Pushbutton switch (with pull-up)
Use a pull-up resistor or enable internal pull-up via software.
Set PB2, PB3, PB4 as output pins for LEDs.
Set PD2 as input pin with internal pull-up for the maintenance switch.
c Copy Edit #include <avr/io.h> #include <util/delay.h> #define F_CPU 1000000UL
int main(void) { DDRB |= (1<<PB2) | (1<<PB3) | (1<<PB4); // LEDs as output DDRD &= ~(1<<PD2); // Switch as input PORTD |= (1<<PD2); // Enable pull-up on PD2
while (1)
{
if (PIND & (1<<PD2))
{
PORTB = (1<<PB2); // RED
_delay_ms(3000);
PORTB = (1<<PB3); // YELLOW
_delay_ms(3000);
PORTB = (1<<PB4); // GREEN
_delay_ms(3000);
}
else
{
PORTB &= ~((1<<PB2) | (1<<PB3) | (1<<PB4)); // All OFF
}
}
}
Power on the circuit.
LEDs should:
Red → 3s
Yellow → 3s
Green → 3s
Repeat
Press the switch connected to PD2.
All LEDs should turn off immediately.
Releasing the switch resumes normal operation.
Include:
Schematic diagram (PNG or Proteus file)
Code file (main.c)
Explanation of system behavior
Screenshots (if simulated)
Fully working traffic light system on hardware or simulation
Source code with comments
Circuit diagram (Proteus or drawn)
Optional: short video demo of the working project
To get started, ensure you have:
AVR-GCC or Atmel Studio installed
A way to flash code to ATmega328P (e.g., USBasp)
Proteus for simulation (optional)
Clone or download the repository and upload main.c to your microcontroller.
This project is licensed under the MIT License — feel free to use, modify, and share it!
For questions or collaboration opportunities, reach out:
📧 Email: thato6216@gmail.com 🔗 LinkedIn: https://www.linkedin.com/in/thatomaelane/