Tuesday, April 19, 2016

IR remote control Arduino

IR Remote control for arduino reads the key code of IR Remote having NEC Protocol.

Components Required:
1. IR Sensor
2. Arduino Uno
3. Remote Control

Step 1: Circuit Connections

The connection of the IR receiver module shown in the image below, which is the connection of the module pins to port 11 of the Arduino (signal), 5v and GND. In the right image, we can see the module in operation, with an LED that flashes when the module is receiving infrared signals:

For the circuit we will use 2 LEDs, 2 resistors of 330 ohms and the IR receiver, taking care to observe the correct connection of the module pins, avoiding component of burning:

Arduino IR Remote

Step 2: Programming the arduino

A program that reads the IR signal received, and based on the value read, triggers the ports, where the LEDs are connected. This program also features the serial monitor the values ​​read by IR receiver:

This way you can find out the values ​​in hex on Serial terminal, the signal received by all remote control keys. In the program, used the values ​​FF30CF (Key 1), FF18E7 (key 2), FF10EF (key 4), FF38C7 ​​(key 5), and FF52AD (key 9) . Finally, in the loop, I test the value received by the IR receiver , and some commands IF I check which key was pressed, lighting and putting out the corresponding lED. I used the 9 key to erase the 2 LEDs at once. For this program, we will use the library irRemote , which you can download by clicking here :

// Program: Test IR Remote Control   
#include <IRremote.h>  
int RECV_PIN = 11 ;  
 float IRRemote;  
 int pinLED1 = 5 ;  
 int pinLED2 = 7 ;  
IRrecv irrecv (RECV_PIN);  
decode_results results;  
void setup ()  
  pinMode (pinoledvermelho, OUTPUT);   
  pinMode (pinoledverde, OUTPUT);  
  Serial.begin ( 9600 );  
  irrecv.enableIRIn (); // Initialize the IR receiver  
void loop ()  
  if (irrecv.decode (& results))  
    Serial.print ( "read value" );  
    Serial.println (results.value, HEX);  
    IRRemote = (results.value);  
    if (IRRemote == 0xFF30CF ) // Check if the 1 key is pressed  
      digitalWrite (pinLED1, HIGH);   // Lights red LED  
    if (IRRemote == 0xFF18E7 ) // Check if the 2 key has been thrown  
      digitalWrite (pinLED1, LOW); // Off the red LED  
    if (IRRemote == 0xFF10EF ) // Check if the 4 key has been pressed  
      digitalWrite (pinLED2, HIGH); // Turns on the green LED  
    if (IRRemote == 0xFF38C7 ​​) // Check if the 5 button was pressed  
      digitalWrite (pinLED2, LOW); // Off the green LED  
    if (IRRemote == 0xFF52AD ) // Check if the key was thrown 9  
      digitalWrite (pinLED1, LOW); // Turn off all leds  
      digitalWrite (pinLED2, LOW);  
  irrecv.resume ();

No comments:

Post a Comment