Anda di halaman 1dari 3

LED Control menggunakan IR inframerah

remote control di Arduino uno R3


>> coding Decoder IR untuk menampilkan ke serial monitor:

#include <IRremote.h>
int IRpin = 11;
IRrecv irrecv(IRpin);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX); // untuk print bilangan hexa
irrecv.resume();
}
}

ket: - pake library IRremote untuk manggil <IRremote.h>


- buka windows serial monitor di Arduino IDE (aplikasi) nya.
- catat nilai DEC atau HEX di serial monitor untuk mengetahui output IR dari remote
kontrolnya.

>>Contoh coding control LED:

#include <IRremote.h>
int RECV_PIN = 11;
int led1 = 2;
int led2 = 3;
int led3 = 4;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the ir receiver
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);
if(results.value == 16724175) //if you want to configure with your remote controll change the
results.value
digitalWrite(led1, HIGH); // set the LED on
if (irrecv.decode(&results)) {
if(results.value == 16718055)
digitalWrite(led1, LOW); // set the LED off
irrecv.resume(); // Receive the next value
if(results.value == 16743045)
digitalWrite(led2, HIGH); // set the LED on
if(results.value == 16716015)
digitalWrite(led2, LOW); // set the LED off
irrecv.resume(); // Receive the next value
if(results.value == 16726215)
digitalWrite(led3, HIGH); // set the LED on
if(results.value == 16734885)
digitalWrite(led3, LOW); // set the LED off
irrecv.resume(); // Receive the next value
}
}
}

Ket: - pin input IR (s) = pin 11 di Arduino. GND dan Vdc 5 volt disesuaikan
- output ke LED (+) di pin LED1 = pin 2 Arduino
LED2 = pin 3 Arduino
LED3 = pin 4 Arduino
GND di sesuaikan.

Anda mungkin juga menyukai