0% found this document useful (0 votes)
13 views3 pages

Wycliff Arduino

This document contains an Arduino code for a traffic light control system using an IR sensor. When an object is detected, it initiates a traffic light sequence with red, yellow, and green lights, including a dimming effect for the yellow light. The code sets up the necessary pins and runs the traffic light cycle with specific delays for each light state.

Uploaded by

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

Wycliff Arduino

This document contains an Arduino code for a traffic light control system using an IR sensor. When an object is detected, it initiates a traffic light sequence with red, yellow, and green lights, including a dimming effect for the yellow light. The code sets up the necessary pins and runs the traffic light cycle with specific delays for each light state.

Uploaded by

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

#define IR_SENSOR 2 // IR sensor connected to digital pin 2

#define RED 4 // Red LED (Stop)

#define YELLOW 5 // Yellow LED (Dimming effect)

#define GREEN 6 // Green LED (Go)

void setup() {

pinMode(IR_SENSOR, INPUT);

pinMode(RED, OUTPUT);

pinMode(YELLOW, OUTPUT);

pinMode(GREEN, OUTPUT);

Serial.begin(9600);

void loop() {

if (digitalRead(IR_SENSOR) == LOW) { // 🚗 Object Detected

Serial.println("🚗 Object detected! Starting traffic sequence.");

runTrafficLightCycle(); // Run the traffic light sequence

// Function to run the traffic light sequence

void runTrafficLightCycle() {

Serial.println("🚦 Traffic light cycle started");

// Step 1: Red Light ON (Stop)

digitalWrite(RED, HIGH);

digitalWrite(GREEN, LOW);

digitalWrite(YELLOW, LOW);

delay(5000); // Red for 5 sec (Adjust as needed)


// Step 2: Yellow Light Blinks (Get Ready)

for (int i = 0; i < 3; i++) {

digitalWrite(YELLOW, HIGH);

delay(500);

digitalWrite(YELLOW, LOW);

delay(500);

// Step 3: Green Light ON (Go) + Yellow Dimming Effect

digitalWrite(RED, LOW);

digitalWrite(GREEN, HIGH);

Serial.println("🟢 Green ON, Yellow Dimming...");

for (int brightness = 255; brightness >= 0; brightness -= 5) { //


Gradually dim

analogWrite(YELLOW, brightness);

delay(50);

analogWrite(YELLOW, 0); // Ensure it's fully OFF

delay(15000); // Green for 5 sec (Adjust as needed)

// Turn off all lights

digitalWrite(GREEN, LOW);

digitalWrite(YELLOW, LOW);

digitalWrite(RED, LOW);

Serial.println("🚦 All lights OFF. Waiting for next object.");

You might also like