IR infrared remote control dengan Arduino

[ [ images & links ] ]

Gambar 1. [sumber]

Gambar 2. [sumber]

Infrared IR Receiver Module Wireless Remote Control Kit For Arduino

Description:

Arduino mini infrared wireless remote control kit consists of ultra-thin infrared remote control and 38KHz infrared receiver module. This mini slim infrared remote control with 20 function keys. Its transmit distances up to 8 meters. Ideal for handling a variety of equipment indoors.
IR receiver module can receive standard 38KHz modulation remote control signal. You can decode the remote control signal through Arduino programming. You can design a variety of remote control robots and interactive works.

Specification:

Transmission distance: up to 8m(depending on the surrounding environment, sensitivity of receiver etc)
Battery: CR2025 button battery
Battery capacity: 160mAh
Effective angle: 60°
Sticking material: 0.125mmPET
Effective life: 20,000 times
Static current: 3uA – 5uA
Dynamic current: 3mA – 5mA

~alexnld.com

MAKER Version Electronic Brick Set IR Remote

The IR Remote supplied with this Set looks like this (Others may also be supplied):

– Based on NEC protocol; Built-in 1 x AG10 battery;
– Remote control range: above 8m;
– Wavelength: 940Nm;
– Frequency: crystal oscillator: 455KHz; IR carrier frequency: 38KHz

This is especially good for remote control of a small robot, using the arrow buttons. Below is [ps2id url=’#terryyourduino’ offset=’300′]an example Software Sketch[/ps2id] for this remote. The reported buttons will be Forward, Left, Right, Reverse (for the 4 blue button), OK for the red ‘OK’ button, 1 to 0 for the white number buttons, and ‘*’ and ‘#’ for the bottom red buttons.

TYPES OF IR REMOTE CONTROLS
NOTE!! Most handheld remotes are shipped with a small clear plastic piece in the battery compartment that must be removed to activate it. You can usually just pull it out.
There are many different IR remote controls. Some from YourDuino.com are the low-cost IR Infrared Remote Control Kit 2 and also the THIS IR Remote (right) which has directional buttons that would be good for controlling a vehicle etc. Then, there are the typical TV and Stereo Remotes. All of these may have different encoding methods and number of physical buttons, and different codes received when a button is pressed. Below we will give [ps2id url=’#terryyourduino’ offset=’300′]example Software Sketches[/ps2id] for a few common IR Remotes.

IR-REMOTE LIBRARY:
Note: The following library must be installed in your Arduino installation for this to work!
CLICK HERE – IR REMOTE CONTROL: ARDUINO LIBRARY

NOTE!! If you have a late version of Arduino with a library IRRobotRemote, it may conflict and you may have to remove that library.
Make sure to delete Arduino_Root/libraries/RobotIRremote. Where Arduino_Root refers to the install directory of Arduino. The library RobotIRremote has similar definitions to IRremote and causes errors.

~arduino-info.wikispaces.com/IR-RemoteControl

Gambar 3. [sumber]

Gambar 4. [sumber]

Contoh salah satu tabel output dari IR remote control (cocok untuk IR RC Keyes warna hitam dengan tombol arah).

Untuk contoh kode lihat di [ps2id url=’#xindacode’ offset=’350′] bagian halaman ini.[/ps2id]

z3t0/Arduino-IRremote

Receiving and printing a code:

The following sketch will receive codes and print them to the serial port. This sketch is very useful for testing IR receiving, and for determining what code values to use in your code. A slightly more complex version is in the examples directory as IRrecvDump.

This sketch also illustrates how to perform an action while a button is pressed. In this example, the action is writing to the serial port.

#include <IRremote.h>
IRrecv irrecv(7); // Receive on pin 7
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() 
{
  if (irrecv.decode(&results)) 
  {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Continue receiving
  }
}

 

IRrecvDemo.ino

/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 7;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  // In case the interrupt driver crashes on setup, give a clue
  // to the user what's going on.
  Serial.println("Enabling IRin");
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("Enabled IRin");
}

void loop() 
{
  if (irrecv.decode(&results)) 
  {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

IRrecvDump.ino

/*
 * IRremote: IRrecvDump - dump details of IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
 * LG added by Darryl Smith (based on the JVC protocol)
 */

#include <IRremote.h>

/* 
*  Default is Arduino pin D11. 
*  You can change this to another available Arduino Pin.
*  Your IR receiver should be connected to the pin defined here
*/
int RECV_PIN = 7;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}


void dump(decode_results *results) {
  // Dumps out the decode_results structure.
  // Call this after IRrecv::decode()
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");

  }
  else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
  }
  else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
  }
  else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->address, HEX);
    Serial.print(" Value: ");
  }
  else if (results->decode_type == LG) {
    Serial.print("Decoded LG: ");
  }
  else if (results->decode_type == JVC) {
    Serial.print("Decoded JVC: ");
  }
  else if (results->decode_type == AIWA_RC_T501) {
    Serial.print("Decoded AIWA RC T501: ");
  }
  else if (results->decode_type == WHYNTER) {
    Serial.print("Decoded Whynter: ");
  }
  Serial.print(results->value, HEX);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 1; i < count; i++) {
    if (i & 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.write('-');
      Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println();
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    dump(&results);
    irrecv.resume(); // Receive the next value
  }
}

Arduino Keyes / Xinda IR Remote Control Tutorial

 

IR Remote Tutorial Code Part 2

//  Henry's Bench IR Remote Tutorial 2

#include <IRremote.h>

int IR_PIN = 7;

IRrecv irDetect(IR_PIN);

decode_results irIn;

void setup()
{
  Serial.begin(9600);
  
  irDetect.enableIRIn(); // Start the Receiver
}

void loop() {
  if (irDetect.decode(&irIn)) {
    decodeIR();
    irDetect.resume(); 
  }
}

void decodeIR() // Indicate what key is pressed

{

  switch(irIn.value)

  {

  case 0xFF629D:  
    Serial.println("Up Arrow"); 
    break;

  case 0xFF22DD:  
    Serial.println("Left Arrow"); 
    break;

  case 0xFF02FD:  
    Serial.println("OK"); 
    break;

  case 0xFFC23D:  
    Serial.println("Right Arrow"); 
    break;

  case 0xFFA857:  
    Serial.println("Down Arrow"); 
    break;

  case 0xFF6897:  
    Serial.println("1"); 
    break;

  case 0xFF9867:  
    Serial.println("2"); 
    break;

  case 0xFFB04F:  
    Serial.println("3"); 
    break;

  case 0xFF30CF:  
    Serial.println("4"); 
    break;

  case 0xFF18E7:  
    Serial.println("5"); 
    break;

  case 0xFF7A85:  
    Serial.println("6"); 
    break;

  case 0xFF10EF:  
    Serial.println("7"); 
    break;

  case 0xFF38C7:  
    Serial.println("8"); 
    break;

  case 0xFF5AA5:  
    Serial.println("9"); 
    break;

  case 0xFF42BD:  
    Serial.println("*"); 
    break;

  case 0xFF4AB5:  
    Serial.println("0"); 
    break;

  case 0xFF52AD:  
    Serial.println("#"); 
    break; 

  default: 
   break;

  }
}

https://arduino-info.wikispaces.com/IR-RemoteControl  

/* YourDuino.com Example Software Sketch
 Brick Starter Set IR Remote Kit Test
http://yourduino.com/sunshop2/index.php?l=product_detail&p=364
 based on code by Ken Shirriff - http://arcfn.com
 Get Library at: https://github.com/shirriff/Arduino-IRremote
 Unzip folder into Libraries. RENAME folder IRremote
 terry@yourduino.com */

/*-----( Import needed libraries )-----*/

#include "IRremote.h"

/*-----( Declare Constants )-----*/
int receiver = 7; // pin 1 of IR receiver to Arduino digital pin 7

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);           // create instance of 'irrecv'
decode_results results;            // create instance of 'decode_results'
/*-----( Declare Variables )-----*/


void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  Serial.println("YourDuino IR Receiver Button Decode Test");
  Serial.println("Questions: terry@yourduino.com");  
  irrecv.enableIRIn(); // Start the receiver

}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&results)) // have we received an IR signal?

  {
//    Serial.println(results.value, HEX);  UN Comment to see raw values
    translateIR(); 
    irrecv.resume(); // receive the next value
  }  
}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
void translateIR() // takes action based on IR code received

// describing KEYES Remote IR codes 

{

  switch(results.value)

  {

  case 0xFF629D: Serial.println(" FORWARD"); break;
  case 0xFF22DD: Serial.println(" LEFT");    break;
  case 0xFF02FD: Serial.println(" -OK-");    break;
  case 0xFFC23D: Serial.println(" RIGHT");   break;
  case 0xFFA857: Serial.println(" REVERSE"); break;
  case 0xFF6897: Serial.println(" 1");    break;
  case 0xFF9867: Serial.println(" 2");    break;
  case 0xFFB04F: Serial.println(" 3");    break;
  case 0xFF30CF: Serial.println(" 4");    break;
  case 0xFF18E7: Serial.println(" 5");    break;
  case 0xFF7A85: Serial.println(" 6");    break;
  case 0xFF10EF: Serial.println(" 7");    break;
  case 0xFF38C7: Serial.println(" 8");    break;
  case 0xFF5AA5: Serial.println(" 9");    break;
  case 0xFF42BD: Serial.println(" *");    break;
  case 0xFF4AB5: Serial.println(" 0");    break;
  case 0xFF52AD: Serial.println(" #");    break;
  case 0xFFFFFFFF: Serial.println(" REPEAT");break;  

  default: 
    Serial.println(" other button   ");

  }// End Case

  delay(500); // Do not get immediate repeat


} //END translateIR

/* ( THE END ) */

Gambar 5.

[intense_tabs direction=”right” active_tab_background_color=”#000000″ active_tab_font_color=”#ffff00″ trigger=”click”] [intense_tab title=”Video01″ border=”3px solid #e8e8e8″ link_target=”_self” content_background_color=”#000000″ content_font_color=”#ffffff” icon_size=”1″ icon_position=”left”]

[/intense_tab] [intense_tab title=”Video02″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video03″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video04″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video05″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [/intense_tabs]

Mengisi ulang bootloader papan Arduino Uno

Sebelum memulai, pertanyaan yang mungkin timbul adalah mengapat kita perlu mengisi ulang/membakar (burn) bootloader untuk Arduino Uno? Sebelumnya apakah bootloader itu sendiri? Mari mulai dari istilah firmware, secara singkat firmware adalah program yang paling awal diisikan ke sebuah mikrokontroler, program ini bersifat permen (atau tepatnya semi-permanen). Sekali diisikan, program ini tidak mudah untuk diubah seperti program lain. Menurut sumber di Arduino.cc ini, “So named because you couldn’t change it once it had been programmed in the chip.”

Lebih lengkap lagi bisa dipelajari dari sumber ini:

Lalu bagaimanakah bootloader menurut Arduino sendiri ? Jawabannya bisa dibaca di sini:

What’s a bootloader?

Microcontrollers are usually programmed through a programmer unless you have a piece of firmware in your microcontroller that allows installing new firmware without the need of an external programmer. This is called a bootloader.

Not using a bootloader

If you want to use the full program space (flash) of the chip or avoid the bootloader delay, you can burn your sketches using an external programmer.

Secara sederhana bootloader Arduino memudahkan pengguna (programmer) untuk memprogram mikrokontroler di papan sistem. Pengguna tidak perlu hardware programmer lainnya, cukup menggunakan kabel USB (dahulu kabel serial) ke papan sistem Arduino. Kecuali pengguna memilih untuk memprogram tanpa bantuan bootloader.

Kembali ke pertanyaan awal, mengapa perlu mengisi ulang bootloader ? Sekenario yang bisa terjadi adalah karena adanya kerusakan pada bootloader, meskipun kemungkinannya kecil. Kemungkinan lain adalah karena mikrokontroler asli pada papan Arduino mengalami kerusakan. Jika mikrokontroler yang dipergunakan adalah versi DIP. Salah satu penjual di salah satu toko online menjual μC ATmega328P dengan harga kurang dari dua puluh ribu rupiah (di luar ongkos kirim). Bisa juga karena ingin menggunakan μC ATmega328P yang berisi bootloader Arduino di tempat lain, misalnya seperti yang ditulis di link ini dan link ini. Lalu kemungkinan ketiga adalah karena ingin/perlu mengganti bootloader dengan versi lain.

  Bootloader (firmware) untuk Arduino:    <<klik di sini untuk membuka>>
Sekarang dengan menggunakan AVRDUDE dan AVRDUDESS kita melihat kondisi awal (kosong) dari mikrokontroler ATmega328P.

Gambar 1.

Bandingkan dengan kondisi default sebagaimana yang bisa dilihat di sini:

Gambar 2.

Gambar 3.

Pada Gambar 3, untuk mengisi bootloader pilih board yang sesuai dengan papan yang hendak diisi lalu pilih item menu Burn Bootloader. Gambar 4 menunjukkan proses pengisian berlangsung lancar.

Gambar 4.

Gambar 5.

Dapat dilihat di Gambar 5 kondisi fuse bits & lock bits setelah Arduino Nano diisi dengan bootloader, bandingkan dengan kondisi yang terlihat pada Gambar 1.

Gambar 6.

Makna dari konfigurasi bits dapat dilihat pada Gambar 6. Konfigurasi seperti ini dapat dengan lebih mudah diatur dengan bantuan fasilitas yang tersedia secara online, misalnya fusecalc atau Engbedded Atmel AVR® Fuse Calculator. Meskipun fasilitas bantuan seperti ini tidak selalu dapat sepenuhnya menggantikan keperluan untuk membaca datasheet. Bahkan sering kali kita juga perlu belajar dari pemahaman dan pengalaman orang lain yang telah mencoba terlebih dahulu, jadi bukan hanya belajar kepada pegawai dari produsen saja. Sebagai contoh, untuk memahami tentang CKSEL pada Gambar 6, kita bisa membaca di halaman ini. Dalam kutipan berikut bisa diketahui konfigurasi seperti pada Gambar 6, CKSEL=1111 diartikan bahwa frekuensi dapat dipilih berdasarkan nilai crystal antara 8 MHz sampai 16 MHz.

Gambar 7. Uji coba bootloader yang baru diisikan pada Arduino Uno

Sekadar sebagai pembanding cara-cara untuk mengisi bootloader Arduino bisa dibaca di sini: Installing an Arduino Bootloader.

Berikutnya adalah percobaan untuk menggunaakan bootloader Optiboot. Saya akan mencobanya di Arduino Nano dengan ATmega328P 5 V.

Gambar 8. Kondisi awal Arduino Nano ATmega328P

Gambar 9. Lock bits berubah setelah penghapusan isi

Gambar 10. Pengaturan konfigurasi untuk pengisian bootloader

Gambar 11.

Pada Gambar 11, terlihat adanya pesan kesalahan (failed). Meskipun begitu sebenarnya proses pengisian bootloader optiboot telah berhasil. Pesan kesalahan terjadi karena pengaturan efuse (extended fuse) yang sesungghuhnya tidak benar-benar mengakibatkan kesalahan. Solusi dari permasalahan ini adalah pengaturan konfigurasi di boards.txt:

## Optiboot for ATmega328p
## ---------------------------------------------
optiboot32.menu.cpu.atmega328p=ATmega328p
optiboot32.menu.cpu.atmega328p.upload.maximum_size=32256
optiboot32.menu.cpu.atmega328p.upload.maximum_data_size=2048

optiboot32.menu.cpu.atmega328p.bootloader.high_fuses=0xDE
optiboot32.menu.cpu.atmega328p.bootloader.extended_fuses=0xFD
optiboot32.menu.cpu.atmega328p.bootloader.file=optiboot/optiboot_atmega328.hex

optiboot32.menu.cpu.atmega328p.build.mcu=atmega328p

Untuk mempelajari lebih lanjut tentang masalah ini silakan baca: <<klik di sini untuk membuka>>

Gambar 12. Pengisian bootloader dengan USBasp, AVRDUDE dan AVRDUDESS

Gambar 13.

Gambar 13 menunjukkan proses bootloader burning setelah perbaikan boards.txt, tidak ada pesan kesalahan sama sekali; bandingkan dengan Gambar 11.

Gambar 14. Pengisian program menggunakan bootloader Arduino otiboot melalui ttyUSB0

Gambar 15. Upload program Arduino melalui USB port (ttyUSB0)