Potentiometer and map() function

I’m trying to use a pot to return a value from 1-3:

foo = map(analogRead(potPin), 0, 1023, 1, 3);

I would expect to have the pot have 3 ranges:

  • 0-180:1
  • 181-270:2
  • 271-360:3

Yet in reality there is a very small range that actually returns 2. Am I missing something?

Is your pot a linear or log taper?

you could check multimap which helps for non-linear mapping

or write a small function

int mymap(int raw)
{
  if (raw < 250) return 1;
  if (raw < 500) return 2;
  return 3;
}

thresholds adjusted to your needs of course

Hi,
Use a DMM and plot the wiper voltage vs angle of the pot shaft. see if it is linear.
Half way for the pot should produce half the voltage at the wiper the voltage that you have across the whole pot.

Tom.... :slight_smile: