Analog sensor: potentiometer or light
A value that changes smoothly, from 0 to 4095: a knob, or the light in a room.
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 AREAD() > 2000 THEN LED red, on
30 WAIT 100
40 GOTO 10What you should see: Turn the potentiometer, or change the light on the sensor: from halfway on, the red light comes on.
▶ Try it in the IDEWhat to buy
- Analog sensor (potentiometer or LDR)
How to wire it to an ESP32-S3
- Signal → ESP32-S3: GPIO9
- 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 signal wire is not on the analog pin, or the potentiometer's middle pin is swapped with a side one. The middle pin goes to the analog pin in the diagram, the two side pins to 3.3 V and GND (never 5 V).
What you can adjust
- The threshold: the value, from 0 to 4095, above which the program reacts.
Which boards it works on
- ESP32-S3 Freenove: yes
- Nordic nRF54LM20 DK: yes
- Arduino UNO R4 WiFi: yes