Beginners Guide To IR Sensor and how to use it with Arduino

Hey guys! Today we are going to learn how to use or how to interface an IR sensor with Arduino. So here is your Beginners Guide To IR Sensor.

Beginners guide to IR sensor
Beginners guide to IR sensor

IR Sensor or Infrared Sensor has two main parts. IR Transmitter and IR Reciever. The work of IR transmitter or Infrared transmitter is to transmit the infrared waves whereas the work of IR receiver is to receive these infrared waves. IR receiver constantly sends digital data in the form of 0 or 1 to Vout pin of the sensor.

Working of IR transmitter and receiver on White Surface
Working of IR transmitter and receiver on White Surface
Working of IR transmitter and IR Receiver on Black Surface

Img Source: Circuit Digest

 

If there is an object in front of  IR sensor, the transmitted infrared waves from IR transmitter reflects from that object and is received by the IR receiver. IR sensor gives 0 in this condition. Whereas, if there is no object in front of the IR sensor, the transmitted infrared waves from IR transmitter is not received by the IR receiver. And IR sensor gives 1 in this condition.

Pinout of an IR sensor:

1)  Ground

2)  5 volt

3)  Enable

4)  Vout 

**IR receiver constantly sends digital data in the form of 0 or 1 to Vout pin of the sensor.

Pinout of 3 Pins IR sensor
Pinout of 3 Pins IR sensor

Img Source: henrysbench

 

Pinout of 4 Pins IR sensor
Pinout of 4 Pins IR sensor

Img Source: Osoyoo.com

 

Watch this video for a detailed explanation :

 

 

Program: LED Control using IR Sensor input

 

void setup() {

pinMode(7,INPUT);
Serial.begin(9600);
pinMode(13,OUTPUT);

}

void loop() {

Serial.print(“IRSensorip “);
Serial.println(digitalRead(7));

if(digitalRead(7)==0)
{
digitalWrite(13,HIGH);
}
else{
digitalWrite(13,LOW);
}

}

 

 

 

DOWNLOAD THIS CODE

 

 

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: