Line sensors (TCRT5000)
Three sensors that look at the floor and tell black from white: for line-following robots.
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 LED yellow, off
30 LED green, off
40 IF SENSOR("line-left")=1 THEN LED red, on
50 IF SENSOR("line-center")=1 THEN LED yellow, on
60 IF SENSOR("line-right")=1 THEN LED green, on
70 WAIT 100
80 GOTO 10What you should see: Pass black tape under the sensors: on the left the red light comes on, in the middle the yellow, on the right the green.
▶ Try it in the IDEWhat to buy
- 3 × Line sensor (TCRT5000)
How to wire it to an ESP32-S3
- L → ESP32-S3: GPIO38
- C → ESP32-S3: GPIO39
- R → ESP32-S3: GPIO40
- 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 sensors are too far from the floor, or their screw is set wrong. Keep them a couple of centimetres above the floor and turn each one's screw until its LED changes between black and white.
What you can adjust
- The sensitivity of each sensor: the screw on the module.
Which boards it works on
- ESP32-S3 Freenove: yes
- Nordic nRF54LM20 DK: yes
- Arduino UNO R4 WiFi: yes