#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define LCD_ADDRESS 0x27 // I2C address of the LCD module
#define LCD_COLUMNS 20 // Number of columns in the LCD module
#define LCD_ROWS 4 // Number of rows in the LCD module
LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS);
const int redPin = 2; // Red LED connected to pin 13
const int yellowPin = 5; // Yellow LED connected to pin 12
const int greenPin = 18; // Green LED connected to pin 14
void setup() {
lcd.init();
lcd.print("TRAFFIC_LIGHT");
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
lcd.begin(LCD_COLUMNS, LCD_ROWS);
lcd.setBacklight(HIGH);
}
void loop() {
// Red light
digitalWrite(redPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, LOW);
lcd.setCursor(0, 0);
lcd.print("STOP ");
delay(2000); // Stay red for 3 seconds
// Yellow light
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(greenPin, LOW);
lcd.setCursor(0, 0);
lcd.print("READY ");
delay(2000); // Stay green for 5 seconds
// Green light
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, HIGH);
lcd.setCursor(0, 0);
lcd.print("GO AHEAD ");
delay(2000); // Stay yellow for 2 seconds
}