Analog input example for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32)


If not already done so already, install Arduino software and make basic connections, as described in page for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32).


In contrast to digital input or output, analog input is a much more complicated function. Thanks to Arduino, the software hides the complexity behind one simple function: analogInput(). If You try to perform analog read for an ARM microcontroller, You will start to appreciate the simplicity of this function very much. Our task will be to read analog values.


Take a look at the booard's pinout one more time and decide which pin we will use. The possible candidates have pink labels "ADCx y". x and y don't matter much for us now, let's just check the blue label in front of each pink. For example, pink "ADC1 0" is prefixed by blue "IO36". 36 is GPIO number of that pin and let's use this one (leftmost of the topmost blue row).

We also need a device which will be producing variable voltage between 0 and 3.3 V. In this example, we will take a MRMS LIDAR 2m VL53L0X, analog output (mrm-lid-an). Additionally to the basic hardware connection, as depicted in home page for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32), we will connect the sensor. The image here shows just this board and the lidar, not the other parts of the basic connection (power supply and battery), which are also necessary.

Connect 0 and 3.3 V voltage inputs of MRMS LIDAR 2m VL53L0X, analog output (mrm-lid-an) to appropriate voltage Dupont pins. Connect sensor's "ANA" pin to ESP32 GPIO pin 36.


Here is the simplest code.

void setup() {

void loop() {
It reads GPIO 36 and prints its value to console. As ESP32 uses 12-bit ADC, the values are in range 0 - 4095 (212).

We could use any other of the 16 analog pins, as long as no other device uses them, but read the next paragraph.


Some pins are not available or are limited in usage. Check this list.