top of page

IR sensor with arduino and relay

Hi I am here to help you with creating this project. here you will know how you can connect Ir sensor with arduino and relay. Dont worry about code i will give code here only. so lets beagin.


Here is the video for help:





STEP 1:

Collect things you will need.

1. IR sensor

2. jumper wire

3. arduino

4. relay

5. remote


Step 2:

CONNECTING IR SENSOR


Begining with ir sensor. Here is how ir sensor looks like.

It has three pins -pin will go to negative on arduino.

middle pin is for positive current connect it to +5v on arduino.

and s pin is for signal connect it to pin 11 on arduino.


STEP 3:

CONNECTING RELAY


Connecting relay = relay has signal pin which are labelled as IN1, IN2, IN3 and so on. so connect these pin to pin2, 3, 4, 5 on arduino board. and vcc to +5v and gnd to ground or negative on arduino.

STEP 4:

UPLOADING CODE


Before uploading code make sure that your arduino software has IR sensor library added to it. If it is not added your code will not compile. IF you doesnt have Ir sensor library added dont worry from here you can download library https://www.arduinolibraries.info/libraries/i-rremote

And now question arises that how to add library to arduino software here is the answer just follow these simple steps and you are ready to go:

Do not unzip the downloaded library, leave it as it is. In the Arduino IDE, navigate to Sketch > Include Library > Add.ZIP Library. At the top of the drop down list, select the option to "Add .ZIP Library''.



Here is the arduino code:


#include <IRremote.h>


int RECV_PIN = 11;


IRrecv irrecv(RECV_PIN);


decode_results results;


void setup() {

irrecv.enableIRIn();

pinMode(2, OUTPUT); //Relay one

pinMode(3, OUTPUT); //Relay two

pinMode(4, OUTPUT); //Relay three

pinMode(5, OUTPUT); //Relay four


digitalWrite(2, HIGH);

digitalWrite(3, HIGH);

digitalWrite(4, HIGH);

digitalWrite(5, HIGH);

}

void loop() {

if (irrecv.decode(&results)) {

irrecv.resume();

}


if (results.value == 0xFF22DD) {

relay_one();

results.value = 0x00000000;

}


if (results.value == 0xFF02FD) {

relay_two();

results.value = 0x00000000;

}


if (results.value == 0xFFC23D) {

relay_three();

results.value = 0x00000000;

}


if (results.value == 0xFFA857) {

relay_four();

results.value = 0x00000000;

}

}


void relay_one() {

static int m = HIGH;

m = !m;

digitalWrite(2, m);

}


void relay_two() {

static int m = HIGH;

m = !m;

digitalWrite(3, m);

}

void relay_three() {

static int m = HIGH;

m = !m;

digitalWrite(4, m);

}

void relay_four() {

static int m = HIGH;

m = !m;

digitalWrite(5, m);

}


Here is the circuit diagram. I added only IR sensor not ky-022 module because i dont have its model. Red wire is for positive and black wire is for negative. and yellow wire from sensor is for signal which is connected to pin 11 of arduino.


92 views0 comments

Recent Posts

See All
bottom of page