• customerservices@pimulta.com
  • 061-42081275
News Photo

Simulasi Lampu Lalu Lintas

Pada percobaan kali ini, kita akan menggabungkan beberapa LED untuk membuat simulasi dari lampu lalu lintas.

berikut vidionya :

setelah melihat vidio yang membosankan diatas. Ada baiknya mengikuti skematic pada vidio tersebut ke papan Arduino yang kita miliki. pada vidio diatas dilakukan simulasi dengan  menggunakan software Proteus 8 yang dapat di download di internet.


berikut adalah code dari rangkaian diatas:

int trafic;

void setup() {
pinMode (2, OUTPUT);
pinMode (3, OUTPUT);
pinMode (4, OUTPUT);

pinMode (5, OUTPUT);
pinMode (6, OUTPUT);
pinMode (7, OUTPUT);

pinMode (A2, OUTPUT);
pinMode (A3, OUTPUT);
pinMode (A4, OUTPUT);

pinMode (A5, OUTPUT);
pinMode (11, OUTPUT);
pinMode (12, OUTPUT);

digitalWrite (2, LOW);
digitalWrite (3,LOW);
digitalWrite(4,LOW);

digitalWrite (5, LOW);
digitalWrite (6,LOW);
digitalWrite(7,LOW);

digitalWrite (A2, LOW);
digitalWrite (A3,LOW);
digitalWrite(A4,LOW);

digitalWrite (A5, LOW);
digitalWrite (12,LOW);
digitalWrite(11,LOW);


}

void loop() {
switch(trafic){
  case 0:
  digitalWrite(4, HIGH); // HIJAU On
  digitalWrite(3, LOW);
  digitalWrite(2, LOW);

  digitalWrite(5, LOW); 
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH); // Merah On

  digitalWrite(A2, LOW); 
  digitalWrite(A3, LOW);
  digitalWrite(A4, HIGH); // Merah On

  digitalWrite(A5, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, HIGH); // Merah On
  delay(5000);
  trafic = 1;
  break;
  case 1:
  digitalWrite(4, LOW); 
  digitalWrite(3, HIGH); // KUNING ON
  digitalWrite(2, LOW);

  digitalWrite(5, LOW); 
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH); // Merah On

  digitalWrite(A2, LOW); 
  digitalWrite(A3, LOW);
  digitalWrite(A4, HIGH); // Merah On

  digitalWrite(A5, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, HIGH); // Merah On
  delay(1500);
  trafic = 2;
  break;
  case 2:
  digitalWrite(4, LOW); 
  digitalWrite(3, LOW); 
  digitalWrite(2, HIGH); // MERAH ON

  digitalWrite(5, HIGH); // HIJAU ON
  digitalWrite(6, LOW);
  digitalWrite(7, LOW); 

  digitalWrite(A2, LOW); 
  digitalWrite(A3, LOW);
  digitalWrite(A4, HIGH); // Merah On

  digitalWrite(A5, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, HIGH); // Merah On
  delay(5000);
  trafic = 3;
  break;
  case 3:
   digitalWrite(4, LOW); 
  digitalWrite(3, LOW); 
  digitalWrite(2, HIGH); // MERAH ON

  digitalWrite(5, LOW); 
  digitalWrite(6, HIGH); // KUNING ON
  digitalWrite(7, LOW); 

  digitalWrite(A2, LOW); 
  digitalWrite(A3, LOW);
  digitalWrite(A4, HIGH); // Merah On

  digitalWrite(A5, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, HIGH); // Merah On
  delay(1500);
  trafic = 4;
  break;
  case 4:
    digitalWrite(4, LOW); 
  digitalWrite(3, LOW); 
  digitalWrite(2, HIGH); // MERAH ON

  digitalWrite(5, LOW); 
  digitalWrite(6, LOW); 
  digitalWrite(7, HIGH); // MERAH ON

  digitalWrite(A2, HIGH); // HIJAU ON
  digitalWrite(A3, LOW);
  digitalWrite(A4, LOW);

  digitalWrite(A5, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, HIGH); // Merah On
  delay(5000);
  trafic = 5;
  break;
  case 5:
     digitalWrite(4, LOW); 
  digitalWrite(3, LOW); 
  digitalWrite(2, HIGH); // MERAH ON

  digitalWrite(5, LOW); 
  digitalWrite(6, LOW); 
  digitalWrite(7, HIGH); // MERAH ON

  digitalWrite(A2, LOW); 
  digitalWrite(A3, HIGH);// KUNING ON
  digitalWrite(A4, LOW);

  digitalWrite(A5, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, HIGH); // Merah On
  delay(1500);
  trafic = 6;
  break;
  case 6:
  digitalWrite(4, LOW); 
  digitalWrite(3, LOW); 
  digitalWrite(2, HIGH); // MERAH ON

  digitalWrite(5, LOW); 
  digitalWrite(6, LOW); 
  digitalWrite(7, HIGH); // MERAH ON

  digitalWrite(A2, LOW); 
  digitalWrite(A3, LOW);
  digitalWrite(A4, HIGH); // MERAH ON

  digitalWrite(A5, HIGH); // HIJAU ON
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  delay(5000);
  trafic = 7;
  break;
  case 7:
  digitalWrite(4, LOW); 
  digitalWrite(3, LOW); 
  digitalWrite(2, HIGH); // MERAH ON

  digitalWrite(5, LOW); 
  digitalWrite(6, LOW); 
  digitalWrite(7, HIGH); // MERAH ON

  digitalWrite(A2, LOW); 
  digitalWrite(A3, LOW);
  digitalWrite(A4, HIGH); // MERAH ON

  digitalWrite(A5, LOW); 
  digitalWrite(12, HIGH); // KUNING ON
  digitalWrite(11, LOW);
  delay(1500);
  trafic = 0;
  break;
}
}


Pada rangkaian diatas digunakan Arduino Nano. Tidak ada perbedaan jauh diantara Arduino Nano dengan Arduino Uno. Perlu di perhatikan pada sub menu Tools - Board - (pilih jenis papan mu) .



Share This News

Comment

Do you want to get our quality service for your business?