Infrared Sensor on Arduino  Step by Step Guide ▷ 2020

With the arrival of Arduino, many code developers had access to a practical tool with which it is possible to create any type of electronic program. If you crave programming and need to know what is it and how use an infrared sensor, then continue reading this step by step guide.

Through such technology based on hardware and free software, specific commands are used to design programs that interact with the circuits on the Arduino board.

The board consists of elements necessary to connect input peripherals and output peripherals to a microcontroller, and in this way, be programmed from any operating system.

What is an infrared sensor and what is it for when developing Arduino hardware?

What is an infrared sensor and what is it for when developing Arduino hardware?

Each body transmits a certain amount of radiation, which is invisible to the human eye but not to an infrared light sensor. This is because this type of device is responsible for identifying the spectrum range just below visible light. However, What is an infrared sensor and what is it for when developing Arduino hardware? An infrared sensor is an electronic element which is designed to measure infrared electromagnetic radiation from all bodies in its field of view.

It is simply composed of an LED that emits infrared light and a photodiode that receives the light reflected by the object closest to it. These little devices work with Arduino only with short contact distances, about 5 to 20mm. In addition to that, you should know that the amount of infrared light that is received depends on several factors such as the color, material, shape and position of the impediment.

According to this, do not project with sufficient precision to provide information on the distance to the obstacle. Although this limitation exists, they are widely used, in conjunction with an Arduino board, in other types of applications such as locating the presence of an object in a certain area. They are also used for identify if a door is open or closed, or if an apparatus has reached a certain point in its travel.

Learn step by step how to connect an infrared sensor with Arduino without errors

Learn step by step how to connect an infrared sensor with Arduino without errors

At present, a wide range of applications for Infrared (IR) sensors. Some of them are for: remote controls, preventing obstacles, counting production in assembly lines, presence detection, security systems. In order to create new projects, you must know the step by step of how to connect an infrared sensor with Arduino without errors. The mounting scheme may vary depending on the purpose of the configuration being made.

To see how it works, in the case of detecting obstacles, it is very simple to link the sensor with Arduino, just follow these steps:

  • Supplies power to the module by connecting the Voltage of Continuous current (VCC) and Ground or ground (GND), to the corresponding 5V and GND outputs.
  • Connect the digital output of the sensor (OUT) to a digital input on the Arduino board to read the sensor status.
  • Check if the light is reaching the photoreceptor. The way to do this is by observing if the LED lights up on the sensor. If so, it will send a LOW signal to the outside.
  • Optionally, calibrate the trigger threshold bringing an object closer to the detector.
  • Use the potentiometer to set the sensitivity of the photoreceptor to an average value.
  • Provide the code to run the program.

The code to place is the following:

const int sensorPin = 9;

void setup() {
Serial.begin(9600); //iniciar puerto serie
pinMode(sensorPin , INPUT); //definir pin como entrada
}

void loop(){
int value = 0;
value = digitalRead(sensorPin ); //lectura digital de pin

if (value == HIGH) {
Serial.println("Detectado obstaculo");
}
delay(1000);
}

Discover how to program an infrared sensor connected to your Arduino board so that it works well

Discover how to program an infrared sensor connected to your Arduino board so that it works well

After having the infrared component on the Arduino board, you can start building the code needed to launch the program. The goal is to get an LED to light while the sensor is locating an obstacle ahead. Next, we show you how to program an infrared sensor connected to your Arduino board to work well.

To start coding the required configurations with the Arduino board, you must take the following considerations into account so that the program runs perfectly:

  • To find the obstacle, needed know the distance at which it is placed and the color of it. In case of being very dark, even being close, it will not detect it.
  • Detection distance can be measured with potentiometer that incorporates the sensor.
  • Sensor works with negative logic, that is, when it detects an obstacle in front, it sends a zero to Arduino and when it doesn’t detect anything, it sends 5V.
  • There are two ways to make the program so that the LED lights up when there is an obstacle: deny entry signal or change the conditions on and off.

List of the best Arduino projects with infrared sensors that you can do yourself for practice

It is normal to generate creative ideas when you start working with Arduino boards. In no time you will have your house full of electronic components and cables to make your own Arduino projects.

In this regard, to help you with inspiration, read below a list of the best Arduino projects with infrared sensors that you can do yourself to practice:

Battery checker with Arduino

This is one of the most popular ideas that you can carry out with infrared sensors and Arduino. With it, you can discover the energy level of a given battery. This is possible through three LEDs and a Arduino. In this way, when the batteries are fully charged, they supply a voltage of 1.5V. As the battery wears down, the voltage will decrease.

Smart traffic light

This design with Arduino leaves you direct two traffic lights depending on whether there is a car waiting or not. With this project, you can simulate an intersection with traffic lights. Specifically, the idea is detect the presence of cars to activate or deactivate traffic lights.

Sensor for parking cars

In the case of this project, its role is warn if you are near or far from another vehicle or object at the time of parking. The sensor produces a sound and with the help of lights they will tell you how close or far you are from colliding. As you approach an object, the beep increases in frequency.

If you have any questions, leave them in the comments, we will answer you as soon as possible, and it will surely be of great help to more members of the community. Thank you! 😉

You may be interested:

Rate this post

Leave a Comment