ESP32-C3 superMini analogRead() wrong values

Hi everybody,

I use this board: esp32-c3-supermini and cant get correct values for joysticks with analogRead().
Joystick voltage output is 2.53V but analogRead() returns ~3500-3700 range values.
Board and Joysticks powered with 5V both.
Any ideas what is wrong?

the code:

map_joystick_value(analogRead(pin_x1), mid_x1, false);

uint8_t map_joystick_value(int16_t value, int16_t mid_value, bool isYAxis) {
Serial.println(value);
}

setup:

It sounds like you have a 12 bit ADC which will return values in the range of 0 to 4095. You can map those to whatever range you desire.

its 12 bit ADC for sure,
the 2.5V (5V / 2) value should be ~2045 (4090 / 2),
but analogRead() returns ~3500 so that is wrong value

Is 5V your Vref?

1 Like

Have you tried swapping parts?

ESP32 is a 3.3 device.
It returns 4095 at 3.3 volts. So at 2.5 it should read approximately 3100.

Everything is correct with your readings.

Don't feed more than a 3.3 volts to its ADC: anything above 3.3 will read as 4095.

i see,
so should I divide joysticks output or what is the solution?

If your joystick output is 0..5v then you need a voltage divider: two resistors 1k and 2k.

image

2 Likes

thanks for your explanations,
is divider the only solution for that hardware?

A voltage divider is the standard and highly recommended solution.

Is not possible to connect the sticks to the 3.3V line?

not sure,
can I power ky-023 joysticks with 3.3v?

The joystick doesn't contains any elements that sensible to supply voltage:
Screenshot from 2024-09-04 14-09-16

So you can use it even with 1.8v logic level

2 Likes

Most folks just use the map function.

I powered board and joysticks with 3.3V and it looks like it works fine.
Thank you guys for your help.

1 Like