Reversing the analogue input.

As the resistance increases in potentio meter, my dc motor speed is reducing. how to inverse this. that is as resistance increases, the analogue input value should be reversed and motor should run fast as resistance increases. can any body help me out in solving this. i am completely new to arduino.
enclosing the url and general prog.

int potentioValue = 0; //Value of Potentiometer
void setup()
{
pinMode(9, OUTPUT); // we select any PWM pin the ones with this sign “~”
}
void loop()
{
potentioValue = analogRead(0); //0 means Read Value from Analog A0
potentioValue = map(potentioValue, 0,1023,0,255); //as we know LED’s brightness ranges from 0 – 255
analogWrite(9, potentioValue); //Show output at 9 pin according to potentio’s value
}

Hi,

A potentiometer has 3 connections. As the resistance increases between the left and middle connections, it decreases between the middle and right connections. So when you say the resistance is increasing, it depends which direction you are turning it and which of left and right is connected to 5V and 0V. So just swap the 5V and 0V connections to the pot!

Also, when posting code, always use code tags (use the# button). Please edit your original post and fix that.

Paul

1 Like

Or do some simple arithmetic (hint: "-")

potentioValue = map(potentioValue, 0,1023,0,255); //as we know LED’s brightness ranges from 0 – 255

Suppose the to range was 255 to 0, instead. What would that result in the LED (or motor, since you don't have an LED) doing?

void loop()
{ 
potentioValue = analogRead(0);
potentioValue = map(potentioValue, 0,1023,255,0);
analogWrite(9, potentioValue);
}

or

void loop()
{ 
potentioValue = analogRead(0);
potentioValue = 1023 - potentioValue
potentioValue = map(potentioValue, 0,1023,0,255);
analogWrite(9, potentioValue);
}

?

Why bother with map?
Divide by four is simpler.

void loop()
{ 
  potentioValue = analogRead(0);
  potentioValue = potentioValue / 4;
  potentioValye = 255 - potentioValue;
  analogWrite(9, potentioValue);
}