Menghidupkan lampu dengan saklar digital dan remote kontrol
Dalam praktek kali ini kita coba menghidupkan dua buah led dengan saklar digital dan remot kontrol, jadi led tersebut dapat dihidupkan baik oleh saklar maupun oleh remot kontrol.
Alat yang di perlukan :
- Arduino Uno
- Remote Kontrol Buatan DF Robot
- Saklar digital 4 buah
- Led 2 buah
- Resistor 100 kilo ohm 4 buah
- BreadBoard
- Kabel Jumper
Listing Programnya di bawah inni yaaaaaa.....!!!
#include <IRremote.h>
int RECV_PIN =8;
String IRButton1 = "FD08F7";
String IRButton2 = "FD8877";
String IRButton3 = "FD48B7";
String IRButton4 = "FD28D7";
IRrecv irrecv(RECV_PIN);
decode_results results;
String BUTTONPRESSED;
int aa=0; int bb = 0;
int cc = 0; int dd =0;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode (2,INPUT); pinMode (3,INPUT);
pinMode (4, INPUT); pinMode (5,INPUT);
pinMode (13,OUTPUT); pinMode(12,OUTPUT);
}
void loop(){
// read the state of the pushbutton value:
bb = digitalRead(3); cc= digitalRead(4);
aa= digitalRead(2); dd=digitalRead (5);
if (aa==1){digitalWrite(13,1);}
if (bb==1){digitalWrite(13,0);}
if (cc==1){digitalWrite(12,1);}
if (dd==1){digitalWrite(12,0);}
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
BUTTONPRESSED = String(results.value, HEX);
BUTTONPRESSED.toUpperCase();
if (BUTTONPRESSED == IRButton1){ digitalWrite(13,1); }
if(BUTTONPRESSED ==IRButton2) { digitalWrite(13,0);}
if(BUTTONPRESSED == IRButton3) {digitalWrite(12,1);}
if(BUTTONPRESSED ==IRButton4) {digitalWrite (12,0);}
irrecv.resume(); // Receive the next value
}
}
*******************************************************************
**** Terima Kasih Atas Kunjungannya.... Selamat Berlatih.. Semangaaath ********
*******************************************************************
Tidak ada komentar:
Posting Komentar