Introduction to IR Sensors
If you are a beginner and new to Electronics and Robotics, you might have heard the name of this sensor multiple times – The IR Sensor. But you might not know what it is. This is one of the most widely used sensors in hobby projects like a burglar alarm and line follower robots.
Why not make a PCB for your Project?
Making a PCB for your DIY project is not hard nowadays. PCB helps to get rid of all messy wires and stuff and give your project an awesome look. And its cool to make your own PCB for your project right?
Designing a PCB for your Project – The Easy Way
I use Altium Designer to draw the circuit and design the PCB. It is a powerful tool that can be used to design and create your own PCBs for your project as well as complex and multiplayer PCBs for industrial use. Here is the link to the Altium trial version. So make sure you check it out.
I usually order our PCBs from PCBWay. PCBWay is a PCB manufacturer specializing in PCB prototyping, low-volume production, and neat and tidy PCB Assembly for a very low price. They have a very friendly customer support team and even perform a free PCB Design Review before payment and inform us if there is some issue with the design. Feel free to check out their website below.
What is an IR Sensor?
IR sensor mainly consists of an IR transmitter (IR LED) and an IR receiver (Usually a photodiode).
IR LED always emits IR rays to the direction it is pointing to.
Now let us bring it closer to a surface. When the IR rays hit a surface, some rays will be reflected back depending upon the color of the surface. Means, the brighter the color is, the more IR will be reflected back.
Darker the color is, more IR will be absorbed by the surface and lesser IR rays will be reflected back.
These reflected rays are received by the Photodiode and depending upon the intensity of the received IR rays, the resistance of the photodiode varies which will, in turn, varies the output voltage.
Thus it is possible to sense the color of the surface where the robot is running by looking into the reflected IR rays. So it is very easy to measure how bright the surface is which will make it easy for us to track the line.
There are so many cheap IR sensors available online; you can purchase any of them. You will need at least two of them for making the line follower robot.
Setting up the IR Sensors
Most of the individual sensors will be somewhat like this.
It will be having 3 pins. One for VCC (5V), GND (0V) and Vout (Output Voltage). VCC will power up the sensor circuit. The Vout pin will give us an output of 5V when the IR light is reflected back to the IR detector.
In some IR sensors, there will be analog output which will give you the voltage reading between 0 and 5 V. You should connect the analog output of this sensor to analog input pin of arduino like A0.
Connections – IR Sensor to Arduino
- IR Sensor ——- Arduino
- Vin —–5V of Arduino
- Gnd —– Gnd of Arduino
- Vout —– D13 of Arduino
- Vout (Analog) —– A0 of Arduino
IR Sensor Arduino Code
int ir_analog = A0;
ir_digital_val = digitalRead(ir_digital);
Serial.print("Analog Value - ");
Serial.print("Digital Value - ");
Just select the board and upload the sketch. Thats it Guys. Your IR Sensor is now ready to use. Just point the IR sensor to something and it will start showing you the values corresponding g to the colour of the object in front of it.