Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Ananda Oktazana Rdirakit community
Published

Traffic Light Simulation - Arduino Uno

Traffic light simulation using Arduino Uno : automatically controlling light changes according to set durations.

BeginnerProtip1 hour242
Traffic Light Simulation - Arduino Uno

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Male Jumper Wires
×7
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
5 mm LED: Green
5 mm LED: Green
×1
Resistor 220 ohm
Resistor 220 ohm
×3
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Traffic Light Simulation Scheme

Code

Traffic Light Simulation Code

Arduino
// inisialisasi PIN
int LedMerah = 13;
int LedKuning = 12;
int LedHijau = 11;

void setup() {
  // inisialisasi PIN Digital 13(LedMerah), 12(LedKuning), 11(LedHijau) sebagai output
  pinMode (LedMerah, OUTPUT);
  pinMode (LedKuning, OUTPUT);
  pinMode (LedHijau, OUTPUT);
  
}

void loop() {
  // LedHijau akan menyala 9 detik
  digitalWrite (LedMerah, LOW); 
  digitalWrite (LedKuning, LOW);
  digitalWrite (LedHijau, HIGH);
  delay (9000);
  
  // LedKuning mulai nyala sebelum 1 detik LedHijau mati
  digitalWrite (LedKuning, HIGH); //
  delay (1000);
  digitalWrite (LedKuning, HIGH);
  digitalWrite (LedHijau, LOW);
  delay (1000);
  
  // LedMerah nyala 7 detik  
  digitalWrite (LedKuning, LOW);
  digitalWrite (LedMerah, HIGH);
  delay (7000);
  
}

Credits

Ananda Oktazana R
1 project • 0 followers
dirakit community
23 projects • 109 followers
Indonesia IoT Community by Informatics UIN Sunan Kalijaga Yogyakarta

Comments