TRAFFIC LIGHT ASSIGNMENT
INTRODUCTION
Introduction:
In today's rapidly advancing technological landscape, security and access control systems have become
integral components in safeguarding sensitive information and ensuring the protection of valuable
assets. As such, the development of efficient and reliable access systems plays a pivotal role in various
industries, ranging from residential and commercial settings to industrial and institutional applications.
This report presents the design and implementation of an embedded access system that utilizes a bi-
color LED (BIRG) to indicate access authorization based on a predefined passcode entered via push
buttons. The system aims to provide a simple yet effective method of controlling access, allowing only
authorized individuals to gain entry.
The core functionality of the access system lies in the evaluation of a specific passcode sequence
entered through four push buttons connected to PORTB (PB0 to PB3). The passcode, comprising four
unique button presses, serves as the key to unlocking the access system. When the correct passcode is
entered, the bi-color LED will blink green for four times, each time with a 500ms interval, creating a
distinctive visual signal of successful access.
However, if an incorrect passcode is detected, the bi-color LED will instead blink red for four times using
the same 500ms interval, signaling a failed access attempt. The access system employs the distinct
lighting pattern of the bi-color LED to indicate the outcome of the access attempt clearly.
The report will explore the design and programming of the embedded system using C language,
targeting an AVR microcontroller (ATmega328P). A detailed circuit schematic will be provided,
showcasing the connections of the push buttons to PORTB and the red LEDs to PORTC. Additionally, the
bi-color LED, which lights green when PD0 is HIGH and PD1 is LOW, and red when PD0 is LOW and PD1 is
HIGH, will be connected to PORTD.
Moreover, the report will outline the step-by-step process of checking and verifying the entered
passcode, progressively lighting up the corresponding red LEDs as each button is pressed. Once the four-
button presses are complete, the system will promptly evaluate the sequence's correctness and respond
by blinking the bi-color LED accordingly.
In conclusion, this report will present a comprehensive overview of the access system's design and
functionality, illustrating how it successfully operates as a secure and user-friendly solution. By
showcasing the effective utilization of the bi-color LED for access indication and the implementation of
the password verification process, this embedded access system stands as an essential demonstration of
practical access control methods in the realm of embedded systems development.
METHODOLOGY
#include <avr/io.h>
#include <util/delay.h>
#define PASSWORD_LENGTH 4
uint8_t password[PASSWORD_LENGTH] = {4, 3, 2, 1}; // Replace with your desired password sequence
void initializeIO()
// Set PORTB pins as input (push buttons)
DDRB = 0x00;
// Set PORTC pins as output (red LEDs)
DDRC = 0xFF;
// Set PORTD pins as output (bi-color LED)
DDRD |= (1 << PD0) | (1 << PD1);
uint8_t readButtonInput()
// Read the button input and return a 4-bit value
return PINB & 0x0F;
void blinkBicolorLED(uint8_t blinkCount, uint16_t interval)
for (uint8_t i = 0; i < blinkCount; i++)
// Toggle bi-color LED (PD0 and PD1)
PORTD ^= (1 << PD0) | (1 << PD1);
_delay_ms(interval);
PORTD ^= (1 << PD0) | (1 << PD1);
_delay_ms(interval);
void checkPassword()
uint8_t inputSequence[PASSWORD_LENGTH];
uint8_t correctPassword = 1;
// Read the button input for PASSWORD_LENGTH times
for (uint8_t i = 0; i < PASSWORD_LENGTH; i++)
while ((readButtonInput() & 0x0F) == 0x00); // Wait for button press
_delay_ms(50); // Debounce delay
// Store the pressed button value in the inputSequence array
inputSequence[i] = readButtonInput() & 0x0F;
// Display the pressed button on the corresponding red LED
PORTC = (inputSequence[i] << PC0);
// Wait for the button to be released
while ((readButtonInput() & 0x0F) != 0x00);
// Check if the input sequence matches the password
for (uint8_t i = 0; i < PASSWORD_LENGTH; i++)
if (inputSequence[i] != password[i])
correctPassword = 0;
break;
// Blink the bi-color LED based on the result
if (correctPassword)
blinkBicolorLED(4, 500); // Blink green 4 times with 500ms interval
else
blinkBicolorLED(4, 500); // Blink red 4 times with 500ms interval
}
int main()
initializeIO();
while (1)
checkPassword();
// Clear red LEDs after checking the password
PORTC = 0x00;
_delay_ms(1000); // Wait for 1 second before checking the password again
return 0;