arduino reads only values from 0 to 500


it’s the first time I use the arduino and I’ve connected a membrane potentiometer ( Ground is connected with one of the outer pins of the poti, 5V with the other outer pin, between this connection ist integrated a resistor of 1KOhm. The middle Pin is connected to Pin 2. Now the Arduino software gives me values from 0 - 500, when I press the potentiometer. But I measurd the voltage at the input Pin and it’s 0 - 5 V. So there has to be values in the software from 0 - 1023, or not?
Another problem is that the arduino software gives random values for the case when I’m not pressing down the poti because the circle is open then, and the arduino gets no value. Is there a solution in programming it? (for example: the arduino gives 0, if there is no input).

Thanks for help, sorry for my bad english, I hope you understood my problem,

Use a pull down resistor of about 100K from the input to earth should stop it from giving random numbers when not pressed.

Not sure why you are not getting the full range especially as you are measuring the right voltage change on the input.

You can also use the internal pull-up to cause it to read 5 V when nothing is connected (a good test would be to enable this pull-up and perform an analog read to see if you get 1023). The internal pull-up is only around 20k or 30k, I believe, so it might influence your analog readings more than a 100k pull-up to ground or Vcc.

  • Ben

Are you sure you can enable a pull resistor when a pin is in the analogue mode? You can't on other processors I have seen.

Analog mode actually has no effect on the pin on the mega168, all it does is multiplex the pin voltage to the ADC module. You can even use the pin as a digital output while reading its analog voltage (it's just that the result is not typically very exciting when you do this, unless you trying to drive high while shorted to ground or vice versa).

Note that if you're sure you want to use a pin as an analog input only you can manually disable its ability to be used as a digital input using the DIDR0 (Digital Input Disable Register). The PIN value for the disabled input will always read zero, regardless of the voltage on the pin. Doing this decreases power consumption of the digital input buffer.

  • Ben

Hello, thank you for your help. I hoped, that there is a software-solution, something like that: if there's no signal give me 0. It would be better for me because I want to use the values in flash and 0 would be better than 1023. But it will work, too. Thanks, janas

[snip informative reply]

  • Ben

You really are an endless fount of useful information. :-) Thanks for your continued contributions to the Arduino community.


And thank you for your thanks; it means a lot to me!

  • Ben