Belajar Bahasa Pemrograman Arduino dengan WOKWI Simulasi Traffic Light Lampu Lalu Lintas
2 min read
4 months ago
Published on Aug 18, 2024
This response is partially generated with the help of AI. It may contain inaccuracies.
Table of Contents
Introduction
In this tutorial, you will learn how to create a basic traffic light simulation using Arduino programming with the WOKWI online simulator. This project is ideal for beginners looking to get hands-on experience with Arduino and understand how traffic lights function in a real-world scenario.
Step 1: Access the WOKWI Simulator
- Open your web browser and navigate to the WOKWI website: WOKWI.
- Create a free account if you don’t have one, or log in to your existing account.
Step 2: Set Up the Project
- Once logged in, start a new project by selecting "New Project".
- Search for "Arduino Uno" in the components library and add it to your project workspace.
Step 3: Wiring the Components
- Connect the LED lights to the Arduino Uno as follows:
- Red LED: Connect the long leg (anode) to pin 13 and the short leg (cathode) to GND.
- Yellow LED: Connect the long leg to pin 12 and the short leg to GND.
- Green LED: Connect the long leg to pin 11 and the short leg to GND.
- Use a breadboard if necessary to help with the connections.
Step 4: Write the Arduino Program
- Click on the code editor and input the following code to control the traffic lights:
int redLight = 13;
int yellowLight = 12;
int greenLight = 11;
void setup() {
pinMode(redLight, OUTPUT);
pinMode(yellowLight, OUTPUT);
pinMode(greenLight, OUTPUT);
}
void loop() {
digitalWrite(redLight, HIGH);
delay(5000); // Red light for 5 seconds
digitalWrite(redLight, LOW);
digitalWrite(greenLight, HIGH);
delay(5000); // Green light for 5 seconds
digitalWrite(greenLight, LOW);
digitalWrite(yellowLight, HIGH);
delay(2000); // Yellow light for 2 seconds
digitalWrite(yellowLight, LOW);
}
- This code sets up three LEDs to simulate a traffic light, with specific delays for each color.
Step 5: Run the Simulation
- Click on the "Run" button in the WOKWI simulator to test your traffic light program.
- Observe the LEDs changing according to the logic defined in the code.
Step 6: Enhance the Program
- To add more functionality, you can modify the timing or integrate additional features, such as pedestrian signals or emergency vehicle overrides.
Conclusion
Congratulations! You have successfully created a basic traffic light simulation using Arduino in the WOKWI simulator. This project serves as a foundation for understanding more complex Arduino applications. Consider exploring other projects or enhancing this one with additional features. Happy coding!