In this project, you will learn about a versatile, exciting sensor that can detect the presence of an object up to a certain distance in front of the sensor. This is a simple project in terms of both the code and the wiring to complete it.
But even though it only requires a few wires and one sensor, the sensor in this project is a very powerful tool for helping your Arduino interact with things in its immediate environment. In a way, you are teaching your Arduino to “see” the world around it.
What you will learn:
We will wire up and experiment with an infrared sensor that can “see” an object from a short to a medium distance in front of it. When it detects an object, it lights up the onboard LED of your Arduino.
We are also using the Serial Monitor in this project, like we did in some previous projects. When the sensor detects an object, it will tell you that it has a “hit” on the Serial Monitor; otherwise, it says that it detects a “miss.”
The sensor for this project is designed to detect whether an object is (or is not) present in front of the sensor. Because of that, this sensor is widely used for obstacle avoidance.
You will be using an infrared (IR) sensor, but there are several different types of IR sensors, so let’s talk about how this one works.
Looking at the sensor, you will see two “bulbs” soldered to the front end of the sensor. These “bulbs” are actually a transmitter and a receiver.
The clear “bulb” is the emitter which sends the IR signal out; the dark “bulb” is the receiver which listens for a signal to come back.
When an object within the range of the sensor is hit by the emitted signal, the object reflects that signal back towards the sensor and the receiver detects this. The sensor knows that something is in front of it and sends a digital signal back through the “Out” pin to the Arduino.
Because this IR sensor shoots out a signal and waits for a response (the reflected signal), it is known as an “active” IR sensor. Other types of IR sensors just look for heat emitted by some object in the environment around them; these don’t emit their own signals, and are called “passive” IR sensors.
You can adjust the range of your sensor by turning the potentiometer in the little blue box on the sensor body. The range for this sensor is between 2 and 30 centimeters (cm), or between approximately 3/4 inch and 12 inches.
When you have wired up your project, it’s time to find out how good your Arduino’s vision is!