ESP32

ESP32 Tutorial: Infrared Obstacle Avoidance Sensor with ESP32

Introduction:

The Infrared Obstacle Avoidance Sensor Module with ESP32 is a powerful combination that can be used to create smart robots that can navigate around obstacles. This module uses infrared (IR) technology to detect obstacles and communicate with the ESP32 microcontroller to determine the appropriate action to take.

In this article, we will explore the basics of IR technology and how it is used in obstacle avoidance sensors. We will also examine the features of the ESP32 microcontroller and how it can be programmed to work with the sensor module. Finally, we will provide a step-by-step guide for building a simple obstacle-avoiding robot using these components.

By the end of this article, you will have a better understanding of how the Infrared Obstacle Avoidance Sensor Module with ESP32 works and how it can be used to create intelligent robots that can navigate their environment autonomously




Amazon links:

Esp32 development board

Infrared obstacle avoidance sensors

Breadboard

Jumper wire

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Infrared obstacle avoidance sensor

Infrared Obstacle Avoidance Sensor with ESP32

Infrared obstacle avoidance sensors are devices that use infrared light to detect the presence of objects in their vicinity. These sensors consist of an infrared LED that emits a beam of light, and an infrared receiver that detects the reflected light from the objects in its path. When the light hits an object, it bounces back and is detected by the receiver. The receiver then sends a signal to the microcontroller, indicating the presence of an obstacle.

The Infrared Obstacle Avoidance Sensor Module is a complete sensor system that integrates both the infrared LED and the receiver into a single package. The module consists of two parts: the infrared LED and the infrared receiver. The LED emits a beam of infrared light, while the receiver detects the reflected light. The module also includes a potentiometer that can be adjusted to set the sensitivity of the sensor.

One of the key advantages of the Infrared Obstacle Avoidance Sensor Module is its simplicity. The module can be easily integrated into any microcontroller-based project, making it an ideal choice for robotics applications. The module can also be used in a variety of other applications, such as security systems, automatic doors, and motion detection.

The Infrared Obstacle Avoidance Sensor Module is compatible with a wide range of microcontrollers, including the popular Arduino and Raspberry Pi platforms. It can be connected to these platforms using simple digital input/output pins. The module can also be used with other microcontrollers that support pulse width modulation (PWM), which can be used to adjust the sensitivity of the sensor.

One of the key features of the Infrared Obstacle Avoidance Sensor Module is its ability to detect obstacles at different distances. The module can detect objects at a distance of up to 30cm, making it ideal for use in robots that need to navigate in tight spaces. The module can also be used to detect larger objects at a greater distance, making it suitable for applications such as security systems.

The Infrared Obstacle Avoidance Sensor Module can also be used to detect the direction of an object. By using two or more sensors, it is possible to determine the direction of an object relative to the sensors. This makes the module an ideal choice for applications such as line-following robots.

The Infrared Obstacle Avoidance Sensor Module is also highly reliable. The module is designed to operate in a wide range of temperatures and can withstand harsh environments. The module is also highly resistant to interference from other sources of infrared radiation, ensuring accurate and reliable detection.



Obstacle avoidance sensor module pinout:

The Infrared (IR) obstacle avoidance sensor module typically has three pins, VCC, GND, and OUT.

Infrared Obstacle Avoidance Sensor pinout with ESP32

VCC: This pin is used to supply power to the sensor module. The typical operating voltage range for the infrared obstacle avoidance sensor is 3-5V DC. You should connect this pin to the 3.3V or 5V pin of your microcontroller, depending on the voltage requirements of your project.

GND: This pin is used to connect the ground of the sensor module to the ground of your microcontroller.

OUT: This pin is used to provide a digital output signal when an obstacle is detected. The output signal is typically LOW when no obstacle is present, and HIGH when an obstacle is detected. You can connect this pin to any digital input pin on your microcontroller.

When an object is in close proximity to the sensor module, the IR LED emits an infrared light that reflects off the object and is detected by the IR receiver. This triggers a signal, which is sent to the OUT pin of the sensor module. You can use this signal to trigger an action, such as stopping or changing the direction of a robot.



Infrared Obstacle Avoidance Sensor Specifications:

Detection Distance:

Infrared obstacle avoidance sensor can detect objects at a range of up to 30cm, although the range can vary depending on the specific sensor model.

Operating Voltage:

 The typical operating voltage range for infrared obstacle avoidance sensor is 3-5V DC.

Current Consumption:

The current consumption of infrared obstacle avoidance sensor is generally low, typically ranging from 20-50mA.

Output Signal:

 Infrared obstacle avoidance sensors typically provide a digital output signal, which can be used to indicate the presence or absence of an obstacle. Some sensors may also provide an analog output signal, which can be used to determine the distance to the obstacle.

Operating Temperature:

Infrared obstacle avoidance sensors can typically operate over a wide temperature range, from -20 to 60 degrees Celsius.

Detection Angle:

Infrared obstacle avoidance sensors have a narrow detection angle, typically around 35-45 degrees.

Sensitivity:

The sensitivity of infrared obstacle avoidance sensors can be adjusted using a potentiometer, allowing them to be tuned for optimal performance in different environments.

Interference:

 Infrared obstacle avoidance sensors can be affected by interference from other sources of infrared radiation, such as sunlight or fluorescent lighting. Some sensors may include features to help reduce interference, such as a shield to block out unwanted signals.

Size:

Infrared obstacle avoidance sensors come in a variety of sizes and form factors, from small surface-mount devices to larger through-hole packages.



Infrared obstacle avoidance sensor with ESP32 Circuit Diagram:

Infrared Obstacle Avoidance Sensor with ESP32 circuit diagram

The Infrared obstacle avoidance sensor module typically has 3 pins: VCC, GND, and OUT.

  • Connect the VCC pin of the sensor module to the 3.3V pin of the ESP32.
  • Connect the GND pin of the sensor module to the GND pin of the ESP32.
  • Connect the OUT pin of the sensor module to the GPIO14 pin of the ESP32.

The IR LED of the sensor module emits infrared light, and the IR receiver on the module detects the reflection of that light. When an object is in close proximity to the sensor module, the IR light is reflected back to the IR receiver, which triggers a signal.

The GPIO14 pin of the ESP32 is used to receive the signal from the IR receiver on the sensor module. It is configured as an input with a pull-up resistor to ensure a stable reading.

The IR LED on the sensor module requires power to operate, which is supplied by connecting the VCC pin of the module to the 3.3V pin of the ESP32. Similarly, the GND pins of the ESP32 and sensor module are connected to create a common ground.

Overall, this circuit diagram shows how the Infrared obstacle avoidance sensor module can be connected to the ESP32 board to detect the presence of obstacles and trigger an output signal.




Infrared obstacle avoidance sensor with ESP32 Code:

output:

Infrared Obstacle Avoidance Sensor detected the object and display on ESP32 serial monitor

Infrared Obstacle Avoidance Sensor cleared the object and display on ESP32 serial monitor



Code explanation:

This line declares a constant integer variable called IR_SENSOR and assigns it the value 14, which is the GPIO pin number that is connected to the infrared sensor.

These lines declare and initialize three variables used in the code: lastSt, fixedSt, and smpltmr. lastSt and fixedSt are of type byte and are both initialized to 0xFF, which is a binary representation of a high voltage state. smpltmr is of type unsigned long and is initialized to 0.

This is the setup function that runs only once when the ESP32 is powered on or reset. pinMode() sets the mode of the GPIO pin connected to the infrared sensor to INPUT, which means the ESP32 reads the voltage level on the pin. Serial.begin(115200) initializes the serial communication between the ESP32 and the computer at a baud rate of 115200 bits per second.

This is the main loop function that runs repeatedly until the ESP32 is powered off or reset. The if statement checks if the time elapsed since the last execution of this block of code is less than 40 milliseconds. If true, it returns to the beginning of the loop without executing the remaining code. Otherwise, it updates the value of smpltmr to the current time returned by the millis() function.

This line reads the voltage level on the GPIO pin connected to the infrared sensor and stores it in the variable st of type byte.

This block of code compares the current voltage level on the infrared sensor pin (st) with the previous voltage level (lastSt). If they are equal, cmp is assigned the value of 1, and if they are not equal, cmp is assigned the value of 0. After that, lastSt is updated to the current value of st.

If cmp is 0, which means the voltage level on the infrared sensor pin has changed, the execution of the loop is returned to the beginning of the loop without executing the remaining code.

This block of code executes only if the voltage level on the infrared sensor pin has not changed (cmp is 1) and if the current voltage level on the pin (st) is different from the previous fixed voltage level (fixedSt). It first assigns the current voltage level to fixedSt and then negates st and applies a bitwise AND with 0x01 to extract the least significant bit, which represents the obstacle detection state. If the least significant bit is 1, the code prints “obstacle is detected”



Summary:

This article discusses the basics of infrared obstacle avoidance sensors and the features of the ESP32 microcontroller. The article includes a step-by-step guide for building a simple obstacle-avoiding robot using these components. The Infrared Obstacle Avoidance Sensor Module is a complete sensor system that integrates both the infrared LED and the receiver into a single package. The module can be easily integrated into any microcontroller-based project, making it an ideal choice for robotics applications. The article also provides specifications for the infrared obstacle avoidance sensor and a circuit diagram for connecting the sensor to the ESP32 microcontroller.

Related Articles

Leave a Reply

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

Back to top button