# Read velocity with a potentiometer

I’ve been wondering as to how I could obtain the velocity of a potentiometers rotational speed. I thought it would be as simple as obtaining the potentiometers resistance followed by the time for an initial and a final values. But I’m not getting any change in speed when I adjust the pot.

Here’s my code:

``````  long t1 = 0;
long t2 = 0;
int v1 = 0;
int v2, pot, cal, speed, start, potval;

void setup()
{
Serial.begin(9600);
pinMode(A0, INPUT);
}

void loop()
{
potval = analogRead(A0);
pot = map(potval, 0, 1023, 0, 200);
if(t1 = 0){
t1 = micros();
v1 = pot;
t2 = 0;
}
if(t2<t1){
t2 = micros();
v2 = pot;
}
cal = (v2-v1)/(t2-t1);
speed = abs(cal);
t1 = 0;
v1 = 0;
Serial.println(speed);
}
``````

I hope you realize that you are trying to measure angular velocity, not just plain velocity

1.) Use == instead of = in your first if statement

2.) Either make pot a float, or just use potval and not pot

3.) Use comments to make your logic easier to understand

4.) Double check your logic (remembering that you are measuring angular velocity)

Remember, potentiometers may come in linear models or logarithmic models. You can get 10-turn models.

Paul