Analogread show to high values on Nano

Hi!
I recently got a arduino nano esp 32. im trying to make a small remote controll with a joystick and a NRF24 radio. i got this to work with a uno and a pro micro but when i try this with a arduino nano i get weird results.
The analogread on the joystick shows values from 0 to 4095. the board is powered via USB C.
i uploaded a simple joystick reading code.

int YPin = A0;
int XPin = A1;
int YValue = 0;
int XValue = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  YValue = analogRead(YPin);
  XValue = analogRead(XPin);

  Serial.print("Yvalue = ");
  Serial.print(YValue);
  Serial.print(" Xvalue = ");
  Serial.println(XValue);

  delay(100);
}

The Joystick is conected to VCC, GND, A0 and A1.

what am i doing wrong here?

You told us you re using a nano. But you analog read value tells us you are not using a nano. A nano is the same as the Arduino uno.
But, what is wrong with reading 4095 with your setup? That is what you should be getting!

not sure what you mean. I’m definitely using a Arduino nano….

Its not the same board as a uno.

I’m expecting a value from 0 to 1023 when I do a analogread.

also the centervalue of the joystick seems to be around 3050 not 512

But in the first post you wrote...

"Arduino Nano" and "Arduino Nano ESP32" are completely different things. The latter has a ESP32 family controller, that uses another programming core than "classic" Arduino Nano.
Most key parameters of both chip are incompatible with each other, and one of them is that the range of analogRead() function on your new board is 0-4095

1 Like

Okay now we are getting somewhere. It is a nano esp32. Which analogreads 0-4095. Still the value seems of to me.
Shouldn’t the center value be something like 2047 (4095/2)? Mine is 3045 ish which gives me a weird range.

What is the voltage to the joystick? You should use 3.3V. If you use the 5V, your results can be explained.

2048 x 5 / 3.3 = 3100

PS
5V into an analogue input can damage your 3.3V board.

If you are using Arduino Nano ESP32 or any other ESP32 board,

You need to do two following thing to make it works with Joystick:

  • Connect the VCC (labeled as 5V) of Joystick to 3.3V
  • In the code, set analog Attenuation to ADC_11db to enable 3.3V voltage reference.

The below are instructions on how to do it:

This is not enough for ESP32 ADC.
The ESP32's ADC has 1.1V voltage reference by default. We need to enable 3.3V voltage reference

1 Like

I wasn't aware of that; I'm still happily living in an AVR world.

1 Like

i got it to work!
thanks for the info.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.