Infrared Proximity Sensor
| ||
Overview
Introduction
An infrared Proximity Sensor is an infrared proximity sensor that emits infrared light and also receives reflected infrared light and feedback on the presence of obstacles ahead.
Principle: Infrared transmitter tube is composed of an infrared light-emitting diode moment luminous body, with infrared radiation efficiency of the material (commonly gallium arsenide) made of PN junction, forward bias to PN junction injection current to excite infrared light. The infrared receiver tube is the infrared light signal in electrical signal semiconductor devices, its core component is a special material PN junction, and with the infrared light intensity increasing the current also increases the output analog signal. When the detection direction encounters an obstacle (reflective surface), infrared light is reflected back to be received by the receiver tube, after the LM393 comparator processing output a digital signal, while the green indicator lights up, the detection distance can be adjusted through the potentiometer knob.
Features
- Emitting a beam of infrared, and receiving the reflected beam
- Features wide range voltage comparator LM393
- Adjustable sensitivity
- Signal output indicator
Specification
- Power: 3.3V ~ 5V
- Dimension: 39mm × 15.5mm (including the IR LED)
- Mounting holes size: 3mm
- Detection range: 2cm ~ 30cm (depending on the obstacle's color, farthest for white)
- Detection angle: 35°
- Recommended environment: indoor, to avoid the sunshine effect.
Pinouts
Pin No. | Symbol | Descriptions |
---|---|---|
1 | DOUT | Digital output |
2 | AOUT | Analog output |
3 | GND | Ground |
4 | VCC | Positive power supply (3.3V-5.0V) |
Use with Pico
Configure Pico
MicroPython and C examples are provided for this sensor, to use it with Pico, you need to first flash firmware to the Pico according to the example.
Please refer to the guides of Raspberry Pi about how to flash the firmware. We recommend you use the firmware from the Demo codes archive.
Hardware connection
Infrared Proximity | Pico | Description |
---|---|---|
VCC | 3.3V | Power input |
GND | GND | Ground |
AOUT | GP26 | Analog data output |
DOUT | GP22 | Digital data output |
Examples
Download the example
Open the terminal of Raspberry Pi and run the following command to download the example:
sudo apt-get install p7zip-full cd ~ sudo wget https://files.waveshare.com/upload/0/05/Infrared_Proximity_Sensor_Demo.7z 7z x Infrared_Proximity_Sensor_Demo.7z -o./Infrared_Proximity_Sensor_Demo cd ~/Infrared_Proximity_Sensor_Demo cd Pico/c/build/
C
Here we use the Raspberry Pi board to flash the Pico.
- Compile the c examples.
- Go into the directory of C examples.
cd ~/Infrared_Proximity_Sensor_Demo/Pico/c/
- Generate Makefile by the cmake command:
cmake ..
- Compile the codes by the command:
make -j9
- Note: If you use Pi zero, please run make only.
- After compiling, a uf2 file is generated.
- Hold the button of the Pico board, and connect the Pico board to Raspberry Pi by USB cable.
- After connecting, release the button, and a portable disk (RPI_RP2) is recognized.
- Copy the main.uf2 file generated which locates in the build folder to the portable disk (RPI-RP2).
cp main.uf2 /media/pi/RPI-RP2/
Python examples
- In Windows PC
- Hold the BOOTSET button of the PICO board, and connect the Pico board to Raspberry Pi by USB cable.
- After connecting, release the button, and a portable disk (RPI-RP2) is recognized.
- Copy the rp2-pico-20210418-v1.15.uf2 file to the portable disk (RPI-RP2).
- Open the Thonny IDE (Please install the newest version which supports the Pico board or update).
- Choose Tools -> Options ->Interpreter, choose the Pico and the port.
- Download the demo codes, unzip and find the MicroPython example
- Choose File -> Open -> Infrared_Proximity_Sensor.py and run it.
- Flash the uf2 file to the Pico board just like in the Windows PC.
- Open the Thonny IDE of Pi, make sure that it is the newest version, or update it.
- Choose Tools -> Options... -> Interpreter
- Choose Pico and the Port
sudo apt upgrade thonny
- Choose File -> Open... -> python/Infrared_Proximity_Sensor.py and run it.
Expected result
- When a barrier is placed near the sensor, the signal indicator will turn on or else turn off.
- The serial output will change according to the distance between the module and the barrier.
Use with STM32
The examples provided are based on the STM32F103RBT6 and the STM32H743, the connection provided is based on the STM32F103RB.
If you want to use other STM32 boards, please change the connection and you may need to port the codes yourself.
Hardware connection
Infrared Proximity | STM32 | Description |
---|---|---|
VCC | 3.3V | Power input |
GND | GND | Ground |
AOUT | PA6 | Analog data output |
DOUT | PA4 | Digital data output |
Examples
The examples are based on the HAL library. Please download the demo codes, unzip them and find the STM32 examples.
- Open the project from Infrared_Proximity_Sensor_Demo\STM32\STM32F103RB\MDK-ARM by Keil.
- Build the project and program it to the STM32 board.
- connect the UART1 of the STM32 board to the PC and check the serial data by SCCOM software.
Expected result
- When a barrier is placed near the sensor, the signal indicator will turn on or else turn off.
- The serial output will change according to the distance between the module and the barrier.
Use with Arduino
The examples provided are based on the Arduino UNO, if you need to use other Arduino boards, please check if the board is compatible with the UNO.
Hardware connection
Infrared Proximity | Arduino | Description |
---|---|---|
VCC | 5V | Power input |
GND | GND | Ground |
AOUT | A0 | Analog data output |
DOUT | D2 | Digital data output |
Examples
- Please download and install Arduino IDE to your PC.
- Download the demo codes, unzip them, and find the Arduino examples.
- Open the Infrared_Proximity_Sensor.ino file by the Arduino IDE.
- Build and upload the codes to the UNO board.
- After uploading, you can open the Serial Monitor of IDE and check the data.
Expected result
- When a barrier is placed near the sensor, the signal indicator will turn on or else turn off.
- The serial output will change according to the distance between the module and the barrier.
Resources
FAQ
{{{5}}}
{{{5}}}
Support
Technical Support
If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)