Servo control with two potentiometers

Hi, i have a question regarding the control of a servo with two potentiometers, the first pot will control the servo over the full range as normal the second pot will set the point at which the first pot will be able to make the servo move. So if the second pot is positioned halfway at 2.5v input the first pot will not make the servo move until it has reached half way and so on.

This is taken from a simple servo and pot sketch

val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)

So firstly would changing the map to val = map(val, 512, 1023, 0, 179); would this make the servo move only when the potentiometer is rotated past half way?

If so how could I make a second potentiometer control the first potentiometer map?

Thanks Gareth

Hey Gazman79,

1) From the map() reference I read this:

"map(value, fromLow, fromHigh, toLow, toHigh) .... .... Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The constrain() function may be used either before or after this function, if limits to the ranges are desired."

2) For another pot to have any influence on this, I guess you should be using a second analog input in your map() call.

On second thought, I'm also not sure if the map() function will cover what you're trying to do here. If I'd be coding it, I'd try to do something like this:

if(pot1 >= pot2)

//Servo code here, maybe with a call to map(), maybe not
Serial.println("Run Forrest, run!");

Serial.println("pot 2 is set to a higher value than pot1; I ain't going anywhere.");

Please let us know what the results of your experiments are.

Best regards, Marv

Hi, thank you for the reply.

Unfortunately I am working away from home for several weeks so I don't have access to my arduino I'm just trying to get the relavant information together.

Also I'm very new to arduino and I really don't understand it yet, I have only uploaded pre made sketches and made servos move etc.

I'm struggling to understand what you are suggesting in your post.

Thanks Gareth

Hey Gareth,

No problem, I’ll try and explain again in another way.

The map() function performs a scaling (and possibly also an addition) to the numerical range you hand it. It will not perform any limiting.

For example if I do this:

y = map(x, 0, 10, 0, 100);

then the value of x in the range 0 to 10 will be scaled to the range 0 to 100. So for example if x=5 then y will equal 50.
When x is outside of the range 0 to 10, the map function will not limit anything. It’ll just extrapolate the value, so:

x=15 -----> y=150
x= -3 -------> y=-30

Please try grasp this (mathematical) concept. When you do, please re-read my previous post and let us know if it makes any sense yet.

Best regards,