Infrared obstacle sensor
Tells whether something is right in front of it, a few centimetres away: for robots that avoid walls.
The test program
Test this part on its own before you build the rest: if it works alone, the rest is built on something you know works.
10 LED red, off
20 IF SENSOR("obstacle")=1 THEN LED red, on
30 WAIT 100
40 GOTO 10What you should see: Bring your hand within a few centimetres of the sensor: the red light comes on.
▶ Try it in the IDEWhat to buy
- IR obstacle sensor
How to wire it to an ESP32-S3
- OUT → ESP32-S3: GPIO41
- VCC → ESP32-S3: 3V3
- GND → ESP32-S3: GNDCommon ground: this link is mandatory.
If it does not work
- The program runs but nothing happens
- The sensitivity screw is set wrong, or sunlight confuses the infrared. Turn the screw on the module until its LED lights with your hand at 5 cm; try away from the window.
What you can adjust
- The distance at which it triggers: the screw on the module.
Which boards it works on
- ESP32-S3 Freenove: yes
- Nordic nRF54LM20 DK: yes
- Arduino UNO R4 WiFi: yes