You are on page 1of 4

NIM : 1513500288

NAMA : MAULANA MALIK IBRAHIM

KASUS 1
Catatan :

1. Komponen terdiri dari :


- Lampu LED 5 (2 Merah dan 3 Biru)
- 10 Kabel Jumper Male to male
- 4 Kabel Jumper Male to Female
- LCD I2C
- Arduino Uno
- Push Button
- 10k Resistor
- 5 Resistor 220 ohm
- Board

2. Alur Program

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
boolean lastbutton=LOW;
boolean currentbutton=LOW;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int input=0;
int buzz=13; // Buzzer Pin
int j=3;
int k=12;
void setup() {
lcd.begin();
lcd.backlight();
lcd.print("BAHAYA");
for(int i=3;i<=12;i++)
pinMode(i,OUTPUT);
pinMode(2,INPUT);
}
boolean debounce(boolean last){ //Function to solve the problem of button debouncing
boolean current=digitalRead(2);
if(last!=current)
{
delay(5);
current=digitalRead(2);
}
return current;
}
void loop() {
for(int i=3;i<=12;i++)
digitalWrite(i,LOW);
currentbutton=debounce(lastbutton);
if(lastbutton==LOW && currentbutton==HIGH)
{
input++;
}
lastbutton=currentbutton;
settone(input);
}

void settone(int input)


{

if(input==1)
four();
}

void four() { //This function produces the 4th siren(POLICE) sound with led transition.

for(int i=3;i<=11;i+=2)
digitalWrite(i,HIGH);
for(int hz = 440; hz < 1000; hz++){
tone(buzz, hz, 50);
delay(5);
}
for(int i=3;i<=11;i+=2)
digitalWrite(i,LOW);
for(int i=4;i<=12;i+=2)
digitalWrite(i,HIGH);
for(int hz = 1000; hz > 440; hz--){
tone(buzz, hz, 50);
delay(5);
}
}
3. Keterangan Penggunaan

int input=0;
int buzz=13; // Buzzer Pin
int j=3;
int k=12;
Untuk inisialisasi Speaker dan LED

lcd.begin();
lcd.backlight();
lcd.print("BAHAYA");
Untuk Memuncul kan Tulisan di LCD

for(int i=3;i<=12;i++)
pinMode(i,OUTPUT);
pinMode(2,INPUT);
Untuk menyalakan lampu secara bergantian

boolean debounce(boolean last){ //Function to solve the problem of button debouncing


boolean current=digitalRead(2);
if(last!=current)
{
delay(5);
current=digitalRead(2);
}
return current;
Untuk membuat fungsi push button

for(int i=3;i<=11;i+=2)
digitalWrite(i,HIGH);
for(int hz = 440; hz < 1000; hz++){
tone(buzz, hz, 50);
delay(5);
}
for(int i=3;i<=11;i+=2)
digitalWrite(i,LOW);
for(int i=4;i<=12;i+=2)
digitalWrite(i,HIGH);
for(int hz = 1000; hz > 440; hz--){
tone(buzz, hz, 50);
delay(5);
Untuk penyettingan suara sirine polisi
4. Pembuatan Rangkaian

Push button kaki 1 dengan Resistor 10k = GND


Push button kaki 2 = 5v
Push button kaki 3 = port 2

LED 1 = port 3
LED 2 = port 4
LED 3 = port 5
LED 4 = port 6
LED 5 = port 7

Speaker = port 13

I2C LCD
- GND = port GND
- VCC = port 5v
- SDA = A4
- SCL = A5

You might also like