How does SN-IRS-01 work?

IR sensnor set(SN-IRS-01)-280x373

Hello everyone! Today, I am going to discuss about a very special light (drumrolls), the INFRARED SENSOR! Many people have been asking about the operation of the infrared sensor. The most common questions are “How do I use it?” and “Do I need to use any comparator for this sensor?” I hope, with this tutorial, you can get a clearer picture on how this sensor works.

The figure shows the Infrared sensor set, SN-IRS-01. These sensors are actually diodes. The black one is the infrared receiver, which is the sensor while the white one is infrared LED which act as the transmitter. Infrared light is not visible under naked eye. However, if you are very curious about what the light looks like, you can see the light through a camera. A simple mobile smartphone camera can do the trick! You will see a pink light. That is the infrared light.

When the infrared light is shined on a surface of an object, it will be reflected. The angle of reflection depends on the colour of the surface of the object. The receiver will receive the signal once it is reflected. By using an LED (i.e. the IR transmitter) which produces light at the same wavelength as what the sensor (i.e. the IR Receiver) is looking for, you can look at the intensity of the received light. When an object is close to the sensor, the light from the LED bounces off the object and into the light sensor. This results in a large jump in the intensity, which can be detected using a threshold.

A Comparator is a circuit built to compare the voltages between the 2 inputs at the op-amp and outputs either a HIGH or LOW. In other words, we can say that it acts as an ANALOG-TO-DIGITAL converter. The figure shows a simple comparator circuit with the IR Sensor. The voltage value of the IR sensor at the ‘+’ pin is compared with the voltage reference at the ‘-‘ pin. If the voltage of the IR sensor is lower than the threshold voltage, which means the positive value is less than the negative value, the output of the OP AMP is LOW. If the voltage of the IR sensor is higher than the threshold voltage, which means the positive value is higher than the negative value, the output of the OP AMP is HIGH.

hello

There is an existing tutorial about the IR sensor. It shows the basic steps to connect the sensor. If you’re interested to see it, please check it here. Here I’m going to show how to display the value of the IR receiver by using a microcontroller. I will be using a CT-UNO. Since we want to display the analog value of the sensor, so we are not going to use comparator in this circuit. Of course, if you really want a clean results, the output from the sensor should be filetered to eliminate external noise. If you don’t want to read the analog value of the sensor, you can build a simpler circuit by using the comparator without using a microcontroller. 😀

Hardware needed:

DSC00183

Part 1:

Let’s do something simple. We see the analog value of this sensor. The connection are as shown below:

Coding:

[code lang=”c” highlight=””]
#define reading A0
unsigned int value;

void setup() {
// put your setup code here, to run once:
pinMode(reading,INPUT);
Serial.begin(9600); //set the baud rate of the serial monitor
Serial.print(“Value”);
Serial.println (“\tVoltage”); //”\t” create spacing of a tab
}

void loop() {
// put your main code here, to run repeatedly:
value = analogRead(reading); //take reading from sensor
float raw_voltage = value*0.00488; //convert analog value to voltage
Serial.print(value); //display analog value in serial monitor
Serial.print(“\t”);
Serial.println(raw_voltage); //display value of voltage in serial monitor
delay(1000); //create a delay of 1s
}[/code]

value
Overview:

  • Based on the results printed on the serial monitor, the left column shows the analog value from the analogRead(pin) command, which is the 10-bit ADC value, display in decimal format.
  • I further convert the value of the analog value to the voltage by multiplying the analog value with 0.00488. How did I get this value? Since it is a 10-bit value, the total number of steps is 2^10 = 1024 steps. So to calculate the voltage drop of one step: 1/1024 * 5 = 0.00488V/step.
  • We can see that the voltage decreases as the object goes nearer to the sensor. The voltage increases as the object is at farther area. With this deduction, we can start to customize the code and set some conditions.

Part 2: Detecting an object distance

In this program, I will be using a buzzer to detect the distance of an object. The maximum distance an object can be detected is around 30-32 cm (based on observation. It is not a specific value).

Should the object be 8cm from the sensor, the buzzer will beep once.

Should the object be 7cm from the sensor, the buzzer will beep at a shorter period of times.

Should the object be 4cm from the sensor, the buzzer will beep in a long pulse.

Set up

Coding:

[code lang=”c” highlight=””]
#define reading A0
#define buzzer 12
unsigned int value;

void setup() {
// put your setup code here, to run once:
pinMode(reading,INPUT); //declare pin A0 as input
pinMode(buzzer,OUTPUT); //declare pin 12 as output
Serial.begin(9600); //set the baud rate of the serial monitor
Serial.print(“Value”);
Serial.println (“\tVoltage”); //”t” create spacing of a tab
}

void loop() {
// put your main code here, to run repeatedly:
value = analogRead(reading); //take reading from sensor
float raw_voltage = value*0.00488; //convert analog value to voltage
Serial.print(value); //display analog value in serial monitor
Serial.print(“\t”);
Serial.println(raw_voltage); //display value of voltage in serial monitor
delay(100); //create a delay of 0.1s
if(raw_voltage>4 && raw_voltage<4.2){ //object is less than 8cm form sensor digitalWrite(buzzer,HIGH); delay(1000); digitalWrite(buzzer,LOW); delay(500); }else if(raw_voltage>3 && raw_voltage<4){ //object is less than 7cm from sensor
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
delay(100);
}else if (raw_voltage<3) //object is less than 4cm from sensor
digitalWrite(buzzer,HIGH);
}[/code]

Code overview:

  • I have set some conditions for the sensor. Note that this is just some rough estimation. It may vary for you.
  • The object that I used to reflect the sensor is a white paper. p/s: White colour has better reflection.

This sensor is a 4 pin sensor, unlike the previous one but the components are the same. In the previous module, we connect both emitter of the receiver and the cathode pin of the transmitter together as GND. In this 4 pin socket sensor, you need to manually connect the emitter and the cathode pin.

Enjoy! Thank you so much for reading this tutorial! If you have any comments or question please feel free to post them in our technical forum! 😀

Attachment code: IR SENSOR

Inside the zip file, there are 2 file names:

1. To read analog value of the sensor –> open Arduino_IR_Serial

2. To use buzzer along with the sensor –> open Arduino_IR_Buzzer

Buy

, , , ,

Related Post

Getting Started with Colour Sensor Module (SN-COLOUR-MOD)

Getting Started with Tilt Sensor (SN-TILT)

Getting Started with Vibration Sensor Module (Normally Off) (SN-VIBRATE-MOD)

Getting Started with IR Distance Click

4 thoughts on “How does SN-IRS-01 work?

Leave a Reply

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