Lesson 21 Infrared-Receiver

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp

Introduction

An infrared-receiver is a component which receives infrared signals and can independently receive infrared ray and output signals compatible with TTL level. It’s similar with a normal plastic-packaged transistor in size and it is suitable for all kinds of infrared remote control and infrared transmission.

Components

– 1 * SunFounder Uno board

– 1 * USB data cable

– 1 * Infrared-receiver module

– 1 * Remote controller

– 1 * 3-Pin anti-reverse cable

Experimental Principle

Control a certain key (for example, Power key) via a remote controller by programming. When you press the key, infrared rays will be emitted from the remote control and received by the infrared receiver, and the LED on the SunFounder Uno board will light up. Connect an LED to pin 13 on the SunFounder Uno board so that you can see remotely whether the Power  key is pressed down.

Experimental Procedures

Step 1: Build the circuit

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorials on our website)

Note: Here you need to add a library. Refer to the description in Lesson 4 previously in the manual.

Step 3: Compile the code

Step 4: Upload the sketch to the SunFounder Uno board

Now, press the Power key of a remote control, and both the LED attached and that connected to pin 13 on the SunFounder Uno board will light up. Then press any other key, and the LEDs will go out.

 Code

/***********************************************
* name:Infrared-Receiver
* function:press the Power key of a remote control,
* and both the LED attached and that connected to pin 13 on the SunFounder Uno board will light up.
* Then press any other key, and the LEDs will go out.
**********************************************/
//Email: support@sunfounder.com
//Website: www.sunfounder.com

#include <IRremote.h>const int irReceiverPin =7; //the SIG of receiver module attach to pin7
const int ledPin = 13;//pin 13 built-in ledIRrecv irrecv(irReceiverPin); //Creates a variable of type IRrecv
decode_results results;void setup()
{
  pinMode(ledPin,OUTPUT);//set ledpin as OUTPUT
  Serial.begin(9600);//initialize serial
  irrecv.enableIRIn(); //enable ir receiver module
}void loop()
{
  if (irrecv.decode(&results)) //if the ir receiver module receiver data
  {
    Serial.print(“irCode: “); //print”irCode: “
    Serial.print(results.value, HEX); //print the value in hexdecimal
    Serial.print(“, bits: “); //print” , bits: “
    Serial.println(results.bits); //print the bits
    irrecv.resume(); // Receive the next value
  }
  delay(600); //delay 600ms
  if(results.value == 0xFFA25D)//if receiver module receive 0xFFA25D
  {
    digitalWrite(ledPin,HIGH);//turn on the led
  }
  else
  {
    digitalWrite(ledPin,LOW);//turn off the led
  }
}