0% found this document useful (0 votes)
9 views2 pages

Arduino Traffic Light Controller Code

This document contains an Arduino code for controlling an LCD and traffic lights using an MCP23008-based LCD and LEDs. It manages the traffic light system for vehicles and pedestrians, displaying messages on the LCD and implementing countdowns for pedestrian waiting and crossing times. The code sets up the necessary pins, initializes the LCD, and uses a loop to alternate between vehicle and pedestrian signals based on button input.

Uploaded by

kanizmitu22
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Arduino Traffic Light Controller Code

This document contains an Arduino code for controlling an LCD and traffic lights using an MCP23008-based LCD and LEDs. It manages the traffic light system for vehicles and pedestrians, displaying messages on the LCD and implementing countdowns for pedestrian waiting and crossing times. The code sets up the necessary pins, initializes the LCD, and uses a loop to alternate between vehicle and pedestrian signals based on button input.

Uploaded by

kanizmitu22
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <Wire.

h>
#include <Adafruit_LiquidCrystal.h>

// Constructor for MCP23008-based LCD (0x20 is a common I2C address)


Adafruit_LiquidCrystal lcd(0); // 0 = address 0x20 by default

// Declare LEDs
const int greenLed = 8;
const int orangeLed = 9;
const int redLed = 10;

// Declare Push button


const int pushButton = 7;

void setup() {
// Set up LCD
[Link](16, 2); // initialize 16x2 LCD
[Link](1); // turn on backlight

// Set LED pins


pinMode(greenLed, OUTPUT);
pinMode(orangeLed, OUTPUT);
pinMode(redLed, OUTPUT);

digitalWrite(greenLed, LOW);
digitalWrite(orangeLed, LOW);
digitalWrite(redLed, LOW);

// Set button pin


pinMode(pushButton, INPUT);

[Link](9600);
}

void loop() {
int buttonState = digitalRead(pushButton);

if (buttonState == LOW) {
// Vehicles go
digitalWrite(greenLed, HIGH);
digitalWrite(orangeLed, LOW);
digitalWrite(redLed, LOW);

[Link]();
[Link](0, 0);
[Link]("VEHICLES GO");
[Link](0, 1);
[Link]("WAIT TO CROSS");

delay(1000);
} else {
// Pedestrian waiting
[Link]("PEDESTRIAN WAITING");

digitalWrite(greenLed, LOW);
digitalWrite(orangeLed, HIGH);
digitalWrite(redLed, LOW);

// 5-second waiting countdown


for (int i = 5; i > 0; i--) {
[Link]();
[Link](0, 0);
[Link]("PEDESTRIAN");
[Link](0, 1);
[Link]("WAITING ");
[Link](i);
[Link](" sec");
delay(1000);
}

// Pedestrian crossing
[Link]("PEDESTRIAN CROSSING");

digitalWrite(orangeLed, LOW);
digitalWrite(redLed, HIGH);

// 15-second crossing countdown


for (int i = 15; i > 0; i--) {
[Link]();
[Link](0, 0);
[Link]("PEDESTRIAN");
[Link](0, 1);
[Link]("CROSSING ");
[Link](i);
[Link](" sec");
delay(1000);
}

// After crossing, blink orange once


digitalWrite(redLed, LOW);
digitalWrite(orangeLed, HIGH);
delay(500);
digitalWrite(orangeLed, LOW);
delay(500);
}
}

You might also like