filmov
tv
Arduino Traffic Light Project | Beginner Tutorial, Code, Circuit & Simulation | @ChipTrails

Показать описание
Welcome to @ChipTrails
Step into the world of Arduino and bring a traffic light system to life! This beginner-friendly tutorial guides you through the process of programming LEDs to mimic real traffic signals—perfect for enthusiasts looking to sharpen their coding skills and explore hardware integration.
What you’ll learn:
How to control LEDs using Arduino Uno
Understanding traffic light timing (Red: 6 sec, Yellow: 3 sec, Green: 6 sec)
Writing clean, structured code with proper comments
Arduino Code:
// ----- Traffic Light Simulation using Arduino UNO -----
// This program simulates a basic traffic light using 3 LEDs:
// Red (pin 8), Yellow (pin 9), and Green (pin 10)
// LEDs will light up in a timed sequence like a real traffic signal.
// Define pin numbers for each LED
const int redPin = 8; // Red LED connected to digital pin 8
const int yellowPin = 9; // Yellow LED connected to digital pin 9
const int greenPin = 10; // Green LED connected to digital pin 10
void setup() {
// Set LED pins as OUTPUT
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
// --- RED Light ON ---
digitalWrite(redPin, HIGH); // Turn ON red LED
digitalWrite(yellowPin, LOW); // Ensure yellow LED is OFF
digitalWrite(greenPin, LOW); // Ensure green LED is OFF
delay(6000); // Wait for 6 seconds
// --- YELLOW Light ON ---
digitalWrite(redPin, LOW); // Turn OFF red LED
digitalWrite(yellowPin, HIGH); // Turn ON yellow LED
digitalWrite(greenPin, LOW); // Ensure green LED is OFF
delay(3000); // Wait for 3 seconds
// --- GREEN Light ON ---
digitalWrite(redPin, LOW); // Ensure red LED is OFF
digitalWrite(yellowPin, LOW); // Turn OFF yellow LED
digitalWrite(greenPin, HIGH); // Turn ON green LED
delay(6000); // Wait for 6 seconds
// (Loop will repeat, going back to red light)
}
Unlock the power of Arduino and create your own miniature traffic control system! Whether you're just starting or looking for an exciting new project, this tutorial has you covered.
Don't forget to LIKE & SUBSCRIBE @ChipTrails more innovative tech builds!
Step into the world of Arduino and bring a traffic light system to life! This beginner-friendly tutorial guides you through the process of programming LEDs to mimic real traffic signals—perfect for enthusiasts looking to sharpen their coding skills and explore hardware integration.
What you’ll learn:
How to control LEDs using Arduino Uno
Understanding traffic light timing (Red: 6 sec, Yellow: 3 sec, Green: 6 sec)
Writing clean, structured code with proper comments
Arduino Code:
// ----- Traffic Light Simulation using Arduino UNO -----
// This program simulates a basic traffic light using 3 LEDs:
// Red (pin 8), Yellow (pin 9), and Green (pin 10)
// LEDs will light up in a timed sequence like a real traffic signal.
// Define pin numbers for each LED
const int redPin = 8; // Red LED connected to digital pin 8
const int yellowPin = 9; // Yellow LED connected to digital pin 9
const int greenPin = 10; // Green LED connected to digital pin 10
void setup() {
// Set LED pins as OUTPUT
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
// --- RED Light ON ---
digitalWrite(redPin, HIGH); // Turn ON red LED
digitalWrite(yellowPin, LOW); // Ensure yellow LED is OFF
digitalWrite(greenPin, LOW); // Ensure green LED is OFF
delay(6000); // Wait for 6 seconds
// --- YELLOW Light ON ---
digitalWrite(redPin, LOW); // Turn OFF red LED
digitalWrite(yellowPin, HIGH); // Turn ON yellow LED
digitalWrite(greenPin, LOW); // Ensure green LED is OFF
delay(3000); // Wait for 3 seconds
// --- GREEN Light ON ---
digitalWrite(redPin, LOW); // Ensure red LED is OFF
digitalWrite(yellowPin, LOW); // Turn OFF yellow LED
digitalWrite(greenPin, HIGH); // Turn ON green LED
delay(6000); // Wait for 6 seconds
// (Loop will repeat, going back to red light)
}
Unlock the power of Arduino and create your own miniature traffic control system! Whether you're just starting or looking for an exciting new project, this tutorial has you covered.
Don't forget to LIKE & SUBSCRIBE @ChipTrails more innovative tech builds!