Symmetrical potentiometer value read

Our teacher gave us a homework. His task:

  1. Set potentiometer to the middle value
  2. Write program to read angle in both directions of potentiometer.

It's easy to make a single turn potentiometer angle read, but I have no clue how to start with a symmetrical analog read. Is it even possible?

1 Like

of course not. Your teacher want you feel pain.

What? How? did you able to show me pls?

1 Like

I think you misunderstood the assignment. Symmetrical is based on the center of the resistance being zero angle. Turn one direction for positive angle and the other direction for negative angle.

Thank You for reply.

IMO You can use a simple example program called "ReadAnalogValue" but:

float voltage = sensorValue * (5.0 / 1023.0);

must be changed to:

float voltage = sensorValue * (270.0 / 1023.0);

270 is typical potentiometer angle. Should work fine.

That's full task content:

"Set potentiometer in a middle position and prepare program that display potentiometer angle in CW and CCW position."

is it mean the start position is 135 / 512 ?

That is how I would read it.

I think i have an idea, sth like:
if A0 >= 512 display positive angle
else display negative angle

Would it work?

ANY potentiometer is going to be non-linear. The AD value at the center position is yet to be determined. Likely the OP will need a push button switch to tell the program the save the AD value at the current potentiometer position.

Exactly, but you need to establish the beginning value for the center position. Likely not to be 512, but start with that value.

imagine potentiometer is linear

Ok, i've wrote this:

int voltage = A0;
int value = 0;

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

}

void loop() {
  value = analogRead(voltage);
if (value > 512){
  Serial.println("CCW angle");
  Serial.println(value*135.0/1023);
}
    else
    { Serial.println("CW angle");
      Serial.println(value*135.0/1023);
  }
delay(200);  
}

But i have to figure how to reverse CCW readings. Any ideas? It starts from 0, but should from 135.

Haven't you had Algebra yet?

I forget, is that even Algebra? pre-Algebra? Any maths?

a7

Yes, that will work. I assume you can figure out how to make it show between -512 & +512 with zero in the middle?

Then can you figure-out how to convert to the angle? it's a simple ratio.

Do you know about the map() function? I haven't tried it, but I'd guess you can map a positive range to a negative-to-positive range...

I'm quite new in Arduino, so i have to learn a lot, never heard of "map" but I'll take a look.

Here's a problem at this moment. I cannot figure it how.

how we can show negative value? what is difference between positive and negative numbers?

here are every numbers positive, right?

If it supposed to print as a negative number, print a "-" after the number!

I can simply add a negative sign to equation but that won't solve a problem. In the middle position serial monitor should show "0" value. With this program it showing about 67 and rising up to full potentiometer swing.

ok. what number should be shown if poti in far left end is?