Need help programming a servomotor :)

Here's the situation, I programmed the servomotor to do a sweep from 0 to 180 then 180 to 0, I have two potentiometers, when potentiometer 1 is increasing the servomotor does 180 to 0 then when it is decreasing it goes to 0 to 180, however if the value of potentiometer 1 becomes equal to potentiometer 2, the servomotor must stop regardless of the position of the shaft during the sweep, is it possible? Thank you!

Yes it is absolutely possible.

Delta_G:
Yes it is absolutely possible.

Of course it's possible, but we don't know what hardware the OP has, nor what software they are using to control it with. So it's hard to say if it's easy or not. Could be, they are expecting too much from a toy servo, or perhaps there are some easy errors in their code. Might be the phase of the moon for all that matter. There are a lot of variables, and the OP has given very scant details to go by.

I am using MG995 servomotor and Arduino Uno :slight_smile: basically what i want to happen is that potentiometer 1 controls the movement of the shaft then potentionmeter 2 is like a filter =, when the value of potentiometer 1 is equal or greater than potentiometer 2, the servo stops and when potentiometer 1 is less than potentiometer 2, the movement resumes :slight_smile:

acesagcal:
I am using MG995 servomotor and Arduino Uno :slight_smile: basically what i want to happen is that potentiometer 1 controls the movement of the shaft then potentionmeter 2 is like a filter =, when the value of potentiometer 1 is equal or greater than potentiometer 2, the servo stops and when potentiometer 1 is less than potentiometer 2, the movement resumes :slight_smile:

Please read the post at the top of the listing that describes how to present your information and you will get the best help available on the internet. Textual descriptions are nice as supplements to data, but they don't convey unambiguous information very well. If you follow the guidelines, then misunderstanding will be minimized.

Remember in theory the result of reading a pot will always change by +/- one least significant bit. Add servo noise and that will be at lease +/- 2 least significant bits.

Have you considered what you want to do when your readings are very close to each other and noise takes it in and out of the thresholds? It will keep nudging the servo and it will appear to buzz.

One way round this is to introduce some hysteresis into the control. The abs function is also helpful to you here allowing you to not worry about the relative difference but concentrate on its absolute amplitude.

if( abs(pot1 - pot2) > threshold) { // do stuff