Laboratory #2_ Arduino Traffic Light
Laboratory #2_ Arduino Traffic Light
Objective: To create and simulate a simple Arduino application using Tinkercad simulation.
To be able to apply the principle of Digital Write, I/O Activation, and Delay.
To be able to understand the concept of real life application of programming.
Short Lecture:
The reason that Arduino has the two functions setup and loop is to separate the things that only
need to be done once, when the Arduino starts running its sketch, from the things that have to
keep happening continuously. The function setup will just be run once when the sketch starts.
Let’s add some code to it that will blink the LED built onto the board. Add the lines to your
sketch so that it appears as follows and then upload them to your board:
pinMode(13, OUTPUT);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
} // the loop routine runs over and over again forever: void loop() { }
General Instructions:
Code:
// Traffic Light Simulation
// Name: Darrell Kim Garcia
// Date: 3-12-25
// Code that simulates a basic traffic light system using Arduino.
// Light sequence: R - G - Y - R - G
void setup() {
// Initialize LED pins as OUTPUT
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}
void loop() {
digitalWrite(redLED, HIGH); // To stop
delay(10000); // 10sec
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH); // To Go
delay(15000); // 15sec
digitalWrite(greenLED, LOW);
digitalWrite(greenLED, HIGH); // To Go
delay(15000); //15sec
digitalWrite(greenLED, LOW);
}
Screenshot:
Code, Circuit (Including Time and Date of the Desktop)
Video Link:
https://drive.google.com/file/d/1Z2j4sEU7kKvHYeHYSUIip8x6rIoXCHvn/view?usp=sharing