Percobaan 6
Push Button DAN LCD
1. Prosedur [Kembali]
- Rangkailah seperti rangkaian berikut
- Buka Arduino IDE dan masukan listing program
- Upload program ke arduino
- Variasikan tombol yang ditekan dan amati keluarannya pada LCD
- Rangkailah seperti rangkaian berikut
- Buka Arduino IDE dan masukan listing program
- Upload program ke arduino
- Variasikan tombol yang ditekan dan amati keluarannya pada LCD
2. Hardware dan Diagram Blok [Kembali]
Gambar 1. Rangkaian Percobaan 6
1. Arduino Uno
2. switch spdt
3. LCD
4. Kabel jumper
=> Diagram Blok:
Dalam percobaan ke-6, Arduino mengambil input dari push button yang terhubung ke pin-pin analog yaitu dari PB1 sampai PB6 dan pada pin digital dari PB7 sampai PB8. Push Button berguna untuk sumber masukan yang mengirimkan sinyal menuju Arduino. Respons yang dihasilkan oleh arduino dan ditampilkan pada layar LCD yang terhubung ditentukan oleh kondisi masukan dari Push Button. Dalam program di arduino IDE , saat tombol dengan warna merah ditekan misalnya, maka tulisan akan muncul di layar LCD yaitu Merah yang terdapat di LCD. Begitu pula Saat tombol dengan warna putih ditekan, maka tulisan akan ditampilkan di layar LCD yaitu Putih yang terdapat di LCD. Begitu juga saat tombol dengan warna hijau, biru, atau putih ditekan, masing-masing akan menampilkan tulisan yang sesuai dengan warnanya di layar LCD, mengapa sesuai dengan warnanya? nah itu karena telah diprogram di program arduino IDE yaitu salah satu contohnya :"else if(Button8==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW & Button6==LOW & Button7==LOW & Button1==LOW){ lcd.clear(); lcd.setCursor(0, 1); lcd.print("Putih"); }".
1. Arduino Uno
2. switch spdt
3. LCD
4. Kabel jumper
=> Diagram Blok:
Dalam percobaan ke-6, Arduino mengambil input dari push button yang terhubung ke pin-pin analog yaitu dari PB1 sampai PB6 dan pada pin digital dari PB7 sampai PB8. Push Button berguna untuk sumber masukan yang mengirimkan sinyal menuju Arduino. Respons yang dihasilkan oleh arduino dan ditampilkan pada layar LCD yang terhubung ditentukan oleh kondisi masukan dari Push Button. Dalam program di arduino IDE , saat tombol dengan warna merah ditekan misalnya, maka tulisan akan muncul di layar LCD yaitu Merah yang terdapat di LCD. Begitu pula Saat tombol dengan warna putih ditekan, maka tulisan akan ditampilkan di layar LCD yaitu Putih yang terdapat di LCD. Begitu juga saat tombol dengan warna hijau, biru, atau putih ditekan, masing-masing akan menampilkan tulisan yang sesuai dengan warnanya di layar LCD, mengapa sesuai dengan warnanya? nah itu karena telah diprogram di program arduino IDE yaitu salah satu contohnya :
"else if(Button8==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button1==LOW){
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Putih");
}".
4. Flowchart dan Listing Program [Kembali]
=> Flowchart:
Gambar 4. Flowchart
=> Listing Program :
#include <LiquidCrystal.h>#define PB1 A0#define PB2 A1#define PB3 A2#define PB4 A3#define PB5 A4#define PB6 A5#define PB7 12#define PB8 13const int rs = 11, en = 10, d4 = 6, d5 = 5, d6 = 4, d7 = 3;LiquidCrystal lcd(rs, en, d4, d5, d6, d7);bool Button1,Button2,Button3,Button4,Button5,Button6,Button7,Button8;void setup() { Serial.begin(9600); lcd.begin(16,2); pinMode(PB1, INPUT); pinMode(PB2, INPUT); pinMode(PB3, INPUT); pinMode(PB4, INPUT); pinMode(PB5, INPUT); pinMode(PB6, INPUT); pinMode(PB7, INPUT); pinMode(PB8, INPUT);}void loop() { Button1 = digitalRead(PB1); Button2 = digitalRead(PB2); Button3 = digitalRead(PB3); Button4 = digitalRead(PB4); Button5 = digitalRead(PB5); Button6 = digitalRead(PB6); Button7 = digitalRead(PB7); Button8 = digitalRead(PB8); if(Button1==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW & Button6==LOW & Button7==LOW & Button8==LOW){ lcd.clear(); lcd.setCursor(0, 0); lcd.print("Merah"); } else if(Button2==HIGH & Button1==LOW & Button3==LOW & Button4==LOW & Button5==LOW & Button6==LOW & Button7==LOW & Button8==LOW){ lcd.clear(); lcd.setCursor(0, 0); lcd.print("Kuning"); } else if(Button3==HIGH & Button2==LOW & Button1==LOW & Button4==LOW & Button5==LOW & Button6==LOW & Button7==LOW & Button8==LOW){ lcd.clear(); lcd.setCursor(0, 0); lcd.print("Hijau"); } else if(Button4==HIGH & Button2==LOW & Button3==LOW & Button1==LOW & Button5==LOW & Button6==LOW & Button7==LOW & Button8==LOW){ lcd.clear();
lcd.setCursor(0, 0); lcd.print("Biru"); } else if(Button5==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button1==LOW& Button6==LOW & Button7==LOW & Button8==LOW){ lcd.clear(); lcd.setCursor(0, 1); lcd.print("Merah"); } else if(Button6==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW & Button1==LOW & Button7==LOW & Button8==LOW){ lcd.clear(); lcd.setCursor(0, 1); lcd.print("Hijau"); } else if(Button7==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW & Button6==LOW & Button1==LOW & Button8==LOW){ lcd.clear(); lcd.setCursor(0, 1); lcd.print("Biru"); } else if(Button8==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW & Button6==LOW & Button7==LOW & Button1==LOW){ lcd.clear(); lcd.setCursor(0, 1); lcd.print("Putih"); } else if(Button1==LOW & Button2==LOW & Button3==LOW & Button5==LOW & Button5==LOW & Button6==LOW & Button7==LOW & Button8==LOW){ lcd.clear(); lcd.setCursor(0, 0); lcd.print("Silahkan Tekan"); lcd.setCursor(0, 1); lcd.print("Salah Satu SW"); } else{ lcd.clear(); lcd.setCursor(0, 0); lcd.print("Error"); } delay(100); // Tambahkan penundaan agar tampilan tidak berubah terlalu cepat}
Saat memencet salah satu button akan dibaca oleh Arduino dan, arduino akan memberikan perintah untuk menampilkan pada layar LCD.
=> Flowchart:
Gambar 4. Flowchart
=> Listing Program :
#include <LiquidCrystal.h>
#define PB1 A0
#define PB2 A1
#define PB3 A2
#define PB4 A3
#define PB5 A4
#define PB6 A5
#define PB7 12
#define PB8 13
const int rs = 11, en = 10, d4 = 6, d5 = 5, d6 = 4, d7 = 3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
bool Button1,Button2,Button3,Button4,Button5,Button6,Button7,Button8;
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
pinMode(PB1, INPUT);
pinMode(PB2, INPUT);
pinMode(PB3, INPUT);
pinMode(PB4, INPUT);
pinMode(PB5, INPUT);
pinMode(PB6, INPUT);
pinMode(PB7, INPUT);
pinMode(PB8, INPUT);
}
void loop() {
Button1 = digitalRead(PB1);
Button2 = digitalRead(PB2);
Button3 = digitalRead(PB3);
Button4 = digitalRead(PB4);
Button5 = digitalRead(PB5);
Button6 = digitalRead(PB6);
Button7 = digitalRead(PB7);
Button8 = digitalRead(PB8);
if(Button1==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW &
Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Merah");
}
else if(Button2==HIGH & Button1==LOW & Button3==LOW & Button4==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kuning");
}
else if(Button3==HIGH & Button2==LOW & Button1==LOW & Button4==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hijau");
}
else if(Button4==HIGH & Button2==LOW & Button3==LOW & Button1==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Biru");
}
else if(Button5==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button1==LOW
& Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Merah");
}
else if(Button6==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW
& Button1==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Hijau");
}
else if(Button7==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW
& Button6==LOW & Button1==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Biru");
}
else if(Button8==HIGH & Button2==LOW & Button3==LOW & Button4==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button1==LOW){
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Putih");
}
else if(Button1==LOW & Button2==LOW & Button3==LOW & Button5==LOW & Button5==LOW
& Button6==LOW & Button7==LOW & Button8==LOW){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Silahkan Tekan");
lcd.setCursor(0, 1);
lcd.print("Salah Satu SW");
}
else{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Error");
}
delay(100); // Tambahkan penundaan agar tampilan tidak berubah terlalu cepat
}
Saat memencet salah satu button akan dibaca oleh Arduino dan, arduino akan memberikan perintah untuk menampilkan pada layar LCD.





.jpeg)




Tidak ada komentar:
Posting Komentar