For fast transaction call 0916.457.0748
Infrared Remote Using Arduino Tutorial

Infrared Remote Using Arduino Tutorial

In this tutorial, we will tackle on how you could send infrared signal using KY – 005 Infrared Transmitter Sensor and receives it via KY – 022 Infrared Receiver sensor. A signal to turn on a LED via this module.

Things you’ll need:

  • 2pcs Arduino UNO Rev 3
  • 2pcs Arduino UNO Power Cable
  • 2pcs Breadboard
  • 1pc KY – 005 Infrared Transmitter Sensor
  • 1pc KY – 022 Infrared Receiver Sensor
  • 1pc LED
  • 1pc Tactile Switch
  • 2pc 220 ohms Resistor
  • Connecting Wires

Hardware assembly

            Schematic Diagram

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Pin Configuration are as follow:

Transmitter

            S to Digital I/O pin 3
            Vcc to +5V of Arduino
            Gnd to Gnd of Arduino
            Switch to Digital I/O pin 7

 

Receiver

            S to Digital I/O pin 11
            Vcc to +5v of Arduino
            Gnd to Gnd of Arduino
            LED to Digital I/O pin 7

 

Connect your Arduino Board to your computer using the UNO Power Cable.

Building the Code

For you to code the Arduino UNO, you need first to install the Arduino Software from their official Website.

The following Arduino sketch uses the IRremote library to serially send infra-red signals with the KY-005. Download first the library here. Select the .zip file.

Now include the library in your Arduino Software.

Sketch >> Include Library >> Add .ZIP Library

 

And locate  the library you downloaded.

 

 

WRITE THE CODE

TRANSMITTER SIDE:

#include <boarddefs.h>                                     // This libraries can be include by clicking
#include <IRremote.h>                                     // Sketch >> Include Library >> IRremote
#include <IRremoteInt.h>                                 //
#include <ir_Lego_PF_BitStreamEncoder.h>     //
 
IRsend irsend;
int button = 7;                                                   // set pin 7 of Arduino for Switch Button
bool on = false;
void setup()
{
 Serial.begin(9600);                                          // Start serial monitor and set baud rate to 9600
 pinMode(button, INPUT);                                // set button as Input
}
 
void loop()
{
  if(digitalRead(button) == HIGH) {                   // if button is pressed
 
    if(on == false) {
     irsend.sendSony(0xa90, 12);                         // IR sends an HEX value of a90
     Serial.println("Pressed!");                             // Display “Pressed” in your serial monitor
     on = true;
    } else { on = false; }
  }
}

 

RECEIVER SIDE:

#include <boarddefs.h>                                     // This libraries can be include by clicking
#include <IRremote.h>                                     // Sketch >> Include Library >> IRremote
#include <IRremoteInt.h>                                 //
#include <ir_Lego_PF_BitStreamEncoder.h>     //
 
 
int RECV_PIN = 11;                                         // set pin 11 as receive pin of the sensor
int led = 7;                                                        // connection of LED
IRrecv irrecv(RECV_PIN);
decode_results results;
 
void setup()
{
  Serial.begin(9600);                                         // Start serial monitor and set baud rate to 9600
  irrecv.enableIRIn();                                        // Start the receiver
}
 
void loop()
{
  if (irrecv.decode(&results))
    {
     Serial.println(results.value, HEX);                // Display the receive data in the Serial Monitor
     digitalWrite(led, HIGH);                              // Turn on the LED
     irrecv.resume();                                            // Receive the next value
     delay(100);                                                  // time on how long your LED in turned on 100ms
     digitalWrite(led, LOW);                               // Turn off LED
    }
}

 

Before you upload, make sure you have selected the right Board and Ports you are using.

Make sure that the transmitter and receiver are in line of sight when you are testing it.

That’s it, and now you can try to make use of two switch to turn it “ON” and “OFF”.

 

Happy Coding!


0 comments

Leave a comment

Please note, comments must be approved before they are published

Payment Methods

Facebook Rewards Program