Category:

Arduino

Title:

Arduino IR Remote Control

Do not dispose of any IR remote controllers. After this event you will now be able to use them in your Ardunio and robotic projects. As it's known, infrared (IR) controls send binary codes via lights. Through these codes, basic commands such as opening, closing, sound opening are given in devices. In robotic projects, we can use these features of IR (IR) controls to provide various controls by using wireless communication over short distances. In this example RGB led and servo motor will be controlled by the communication of infrared (IR) controls with Ardunio . You can adapt this interaction  to your project. Now let's perform this step-by-step.

Materials:

  • Ardunio Uno
  • KY-022 IR Receiver Module
  • IR Remote Controller
  • RGB led 220 Ohm Ressistor(for led)
  • Servo Motor
  • Breadboard
  • Jumper Cables

Project Scheme:

Ardunio'da kızılötesi IR kumanda ile kontrol şeması

After creating the circuit as above, first download the following library file for infrared detection module and define it in Ardunio:

Library files for KY-022 (IR) module:

http://z3t0.github.io/Arduino-IRremote/

Then let's upload the following source code to Ardunio.

Source Code:

#include "IRremote.h"  //For IR module
#include "Servo.h"     //For servo motor

#define bluePin 3
#define redPin 5
#define greenPin 6
Servo srv; 

int RECV_PIN = 11; // Pin 11 is set for infrared data input
IRrecv irrecv(RECV_PIN); 
decode_results results; 

void setup() { 
  Serial.begin(9600); 
  irrecv.enableIRIn();
         
  pinMode(bluePin, OUTPUT); 
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);

  srv.attach(10); //Pin 10 is set for servo motor
} 

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

  switch(results.value){
    case 0xF7C03F:  //Turn on led
    rgb(255,255,255); 
    break;
    case 0xF740BF: //Turn off led 
    rgb(0,0,0);
    break; 
    case 0xF720DF:  //Red light
    rgb(0,255,0);
    break;
    case 0xF7A05F:  //Green light
    rgb(0,0,255);
    break;
    case 0xF7609F:  //Blue light
    rgb(255,0,0);
    break;
    case 0xF700FF:  //Servo turn forward
    srv.write(0); 
    break;
    case 0xF7807F:  //Sevo turn backward
    srv.write(180); 
    break;
  }
  
}

void rgb(int blue, int red, int green)
 {
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

With this code, we assigned tasks to Ardunio according to the frequency values ​​coming from the keys of the controller. Plans were made for switching on-off, turning blue, red, green lights on the led and turning the servo motor to the left and right according to the key-status structure. We have determined the settings in the "Switch-Case" structure according to the values ​​obtained by pressing the keys of the controller. In order to present these values;

Serial.println(results.value, HEX); 

We use this code line to determine the hexadecimal value of the key pressed and write these values ​​in the Switch-Case structure. For example, we set the value of the release key as follows:

Ardunio'da kızılötesi IR kumanda ile kontrol değer okuma

535 views
COMMENTS