G2 CPP110 Arduino Traffic Light Design 10-11-24
G2 CPP110 Arduino Traffic Light Design 10-11-24
University of Cabuyao
(Pamantasan ng Cabuyao)
College of Engineering
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna, Philippines 4025
2. Circuit Schematic
3. Component List
Republic of the Philippines
University of Cabuyao
(Pamantasan ng Cabuyao)
College of Engineering
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna, Philippines 4025
4. Code
void setup() {
// Setting the LED pins to OUTPUT
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
void loop() {
digitalWrite(greenLED, HIGH);
Serial.println("GREEN");
greenLight();
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, HIGH);
Serial.println("YELLOW");
delay(2000);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, HIGH);
Serial.println("RED");
redLight(5);
digitalWrite(redLED, LOW);
digitalWrite(yellowLED, HIGH);
Serial.println("YELLOW");
delay(2000);
digitalWrite(yellowLED, LOW);
}
void greenLight() {
for (int i = 1; i < 11; i++){
buttonState = digitalRead(buttonPin);
if (buttonState == 0){
Serial.println(i);
delay(1000);
}
Republic of the Philippines
University of Cabuyao
(Pamantasan ng Cabuyao)
College of Engineering
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna, Philippines 4025
void redLight(int j) {
for (int i = 1; i < j+1; i++){
Serial.println(i);
delay(1000);
}
}
void pedestrian(){
digitalWrite(yellowLED, HIGH);
Serial.println("YELLOW");
delay(2000);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, HIGH);
Serial.println("RED");
redLight(10);
digitalWrite(redLED, LOW);
digitalWrite(yellowLED, HIGH);
Serial.println("YELLOW");
delay(2000);
digitalWrite(yellowLED, LOW);
loop();
}
5. Reflection
- How does timing affect the behavior of traffic lights.
Proper timing of traffic lights helps to keep cars moving efficiently, reduces waiting time, cuts down
on fuel use, and improves safety for both drivers and pedestrians. For instance, if the total time it
takes for a traffic light to go through its entire sequence (red, yellow, green) is too long, drivers may
have to wait for too long, leading to frustration. And if it’s too short, drivers may not have enough
time to get through intersection, causing backups.
- What challenges did you face while connecting multiple LEDs, and how did you solve them?
Wiring multiple LEDs is much simpler than programming multiple LEDs in Arduino. Errors in the
code can happen, leading to the circuit not functioning as intended. But we’ve solved it by writing
and debugging the code incrementally. Starting with single LED and then progressing to more
complex sequences.
- How would you improve this system for a more complex traffic scenario?
We could improve it by adding adaptive signal control. This system can change the timing to better
handle current traffic conditions, reducing wait times and improving flow. We could also add an
intersection type and configuration.
6. Output
https://drive.google.com/drive/folders/1MBsKrZks5YYMmEDMEg6QUA9aor8V_P-K?usp=sharing