# What analogRead() does to unlinear joystick potentio value?

Hi, I just start to work on my final project which sensor that I used is simple Joystick module with two potentiometers that constructs (x,y) value. The resistance of the potentiometers is not linear but how Arduino make it linear with just analogRead()? because I need to know the method to make it linear in another MCU just like Arduino did. Any help will be so helpful for me. thanks in advance.

analogRead() will read the actual voltage on the centre pin of the potentiometer. It is up to your program to do the maths necessary to linearize the range.

I'm not even sure what mathematical transformation you want to make?

...R

The case is Arduino gave me a very good value that I want from the joystick. the neutral gave me 512, the lowest value is 0 and max value of the widest range from the joystick is 1023 even the resistance is not linear. When I read the value using my target MCU (stm32f4) it gave me an honest nonlinear value. I don't know how the linearization math formula to get linear value for my target MCU

don't know how the linearization math formula to get linear value for my target MCU

Don't. Just get a joystick with linear pots, and toss that piece of garbage in the trash.

The case is Arduino gave me a very good value that I want from the joystick. the neutral gave me 512, the lowest value is 0 and max value of the widest range from the joystick is 1023 even the resistance is not linear.

If that means that it gives 0 at one end of the travel of the pot and 1023 at the other end and 512 when the pot is in the middle of its travel then you have a linear potentiometer.

…R

analogRead() does absolutely NOTHING to linearize the readings. How could it possibly know whether it is reading a linear or non-linear device? How could it possibly know what non-linear function is being applied?? You have a LINEAR joystick. Nearly all joysticks are linear. What makes you think yours is NOT linear? Have you measured and plotted it's resistance vs position?

Regards,
Ray L.

It sounds like the actual issue here is that OP is having problems with analog read on an STM32, and hence he would get better answers from a forum dedicated to those. If using STM32 through the Arduino IDE, there's a forum for the STM32 core iirc - that would probably be a better place to inquire.

I don't suppose you have 5v across the pot? STM32's are normally 3.3v - though they often have 5v tolerant pins, the ADC is still just 0~3.3v.

Robin2:
If that means that it gives 0 at one end of the travel of the pot and 1023 at the other end and 512 when the pot is in the middle of its travel then you have a linear potentiometer.

...R

but when I test the resistance using a multimeter, the resistance (in Ohm) show non-linear, because the max resistance is not at the end of the joystick

What kind of voltage readings do you get if you measure from GND to the analog input pin in question?

Actually, I've found my mistake in powering the joystick with 5v which I should use 3v. thank you guys for the help especially user DrAzzy for showing my mistake