Index>Arduino>Ultimate Starter Kit for Arduino UNO R3>Lesson 31 Control a Relay by IR Remote Controller

Lesson 31 Control a Relay by IR Remote Controller

2281

Overview

In this experiment, we will program the Arduino UNO to control a relay by remote controller.


Components

- 1 * Arduino UNO

- 1 * USB Cable

- 1 * IR Receiver HX1838

- 1 * Remote Controller

- 1 * NPN Transistor (S8050)

- 1 * 1kΩ Resistor

- 1 * 220Ω Resistor

- 1 * 1N4001 Diode

- 1 * Relay

- 1 * LED

- 1 * Breadboard

- Several jumper wires


Principle

The remote IR receiver connected to the Arduino UNO is used to receive IR signals from remote controller. If you press the different keys (key 0 or key 1) on the remote controller, the relay state will be toggled on/off.


Procedures

Step 1: Build the circuit

a.png


Step 2: Program

_31_control_a_relay_with_IR_remoter_controller.ino

Arduino-IRremote-master.zip

/***********************************************************
File name: 31_control_a_relay_with_IR_remoter_controller.ino
Description: When you press the 0 and 1 keys on the remote 
             control, you will hear the sound of the relay.
Website: www.adeept.com
E-mail: support@adeept.com
Author: Tom
Date: 2015/05/02 
***********************************************************/
#include <IRremote.h>
int RECV_PIN = 5;//The definition of the infrared receiver pin 5
const int relayPin = 8; //the base of the transistor attach to pin 8
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
   pinMode(relayPin, OUTPUT); //initialize the relayPin as an output
   irrecv.enableIRIn(); // Initialization infrared receiver
} 

void loop() 
{
  if (irrecv.decode(&results)) { 
    if(results.value==0xC101E57B)//0
    {   
       digitalWrite(relayPin, LOW); //drive the relay is closed off
    }
    if(results.value==0x9716BE3F)//1
    {
      digitalWrite(relayPin, HIGH); //drive relay closure conduction 
    }
    irrecv.resume(); // Receiving the next value
  }  
}


Step 3: Compile the program and upload to Arduino UNO board

Now, press the button 0 on the remote controller, and the LED will be off.

Then press button 1, and the LED will be turned on. At the same time, you will hear the sound of relay toggling. 

b.jpg