Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara mengakses NEC REMOTE DVD / MP3 menggunakan Arduino. prinsip kerja alat ini yaitu menampilkan nilai dari remote NEC ke serial monitor dan juga mengendalikan led menggunakan Remote NEC. Pengembangan lebih lanjut dari alat ini yaitu bisa diaplikasikan untuk kendali lampu rumah, kipas angin dan lainnya menggunakan NEC Remote. untuk skema dan programnya seperti berikut.
Download Library NEC Remote
a. Arduino Mega
b. IR Infrared Sensor
c. NEC Remote DVD / MP3
d. Program ARDUINO IDE
#include "Adafruit_NECremote.h"
// Connect a 38KHz remote control sensor to the pin below
#define IRpin 4
Adafruit_NECremote remote(IRpin);
int led = 13;
void setup(void) {
Serial.begin(115200);
Serial.println("Ready to decode IR!");
pinMode(led, OUTPUT);
}
int lastcode = -1;
void loop(void) {
// You can set the listen() time out to 'n' seconds
int c = remote.listen(5); // seconds to wait before timing out!
// Or you can wait 'forever' for a valid code
//int c = remote.listen(); // Without a #, it means wait forever
if (c >= 0) {
Serial.print("Received code #");
Serial.println(c, DEC);
lastcode = c;
if (c == 7){
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
}
if (c == 21){
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
}
} else if (c == -3) {
Serial.print("Repeat (");
Serial.print(lastcode);
Serial.println(")");
} else if (c == -2) {
Serial.println("Data error");
} else {
Serial.println("Timed out waiting!");
}
}
// Connect a 38KHz remote control sensor to the pin below
#define IRpin 4
Adafruit_NECremote remote(IRpin);
int led = 13;
void setup(void) {
Serial.begin(115200);
Serial.println("Ready to decode IR!");
pinMode(led, OUTPUT);
}
int lastcode = -1;
void loop(void) {
// You can set the listen() time out to 'n' seconds
int c = remote.listen(5); // seconds to wait before timing out!
// Or you can wait 'forever' for a valid code
//int c = remote.listen(); // Without a #, it means wait forever
if (c >= 0) {
Serial.print("Received code #");
Serial.println(c, DEC);
lastcode = c;
if (c == 7){
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
}
if (c == 21){
digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
}
} else if (c == -3) {
Serial.print("Repeat (");
Serial.print(lastcode);
Serial.println(")");
} else if (c == -2) {
Serial.println("Data error");
} else {
Serial.println("Timed out waiting!");
}
}
e. VIEO HASILNYA
No comments:
Post a Comment