# This looked so simple

I’m really to this so my project has no real purpose. It was a way to take two lessons and try and combine them. It looked simple enough but I’m stumped.

I have a continuous rotation servo. When the angle is set at 90 degrees the servo stops, less than 90 - it rotates anti-clockwise and of course greater than 90 and it goes clockwise. That works great.

I have a second circuit, it’s a variable resistor. I can’t remember what they’re called, it’s a flat pad and the resistance goes up us you apply pressure. I hook it up, open the Serial Monitor can see the values. 0 when I’m not touching it up to around 1,000 if I squeeze really hard.

The servo is looking for a value between 0 and 180 so I map the analog read from the resistor to these values.

Perfect. The servo rotates one way, as I squeeze the resistor and the value goes past 90, the servo rotates the other way. There is no stop though. This is the part I thought would be simple. That’s what the “if” statement is for. If the resistor is reading 0, no one is touching it so send a rotation angle of 90 degrees to stop the servo.

It doesn’t happen that way. The servo never runs and when I look at the serial monitor it reads 0 all the time, no matter how hard I squeeze the resistor.

#include <Servo.h>
Servo myservo;
int valServo = 0;

void setup()
{
myservo.attach(9); // Servo pin is on 9
myservo.write (90); // Set to 90 degrees
Serial.begin(9600);
}

void loop()
{
valServo = map(analogRead(0), 0, 1023, 0, 180);

if(valServo == 0);
{
valServo = 90;
}

myservo.write (valServo);
Serial.println(valServo);
}

There is no stop though

The servo must stop at some point - does it click when it hits the end-stop?

That was my bad grammer. What I mean is:

The servo never stops. When I’m not touching the resistor it reads 0. As I squeeze it goes up, up to a maximum of 180. The only time the servo should stop is when it is sent a value of 90. As you gently squeeze the value slowly rises. At 90, the servo stops and past that it changes direction. What I want is an analog read value of 0 to also send the servo a value of 90 so when the resistor isn’t being touched, the servo is at rest.

I hope this is somewhat clearer. There is no mechanical stop on a continuos rotation servo, you remove it.

There is no mechanical stop on a continuos rotation servo,

Ah! I missed that, sorry.

You don't have a servo, you have a motor with a single wire interface. It is pointless calling it a servo.

``````void loop()
{
if(pressureval == 0)
{
valServo = 90;
}
else
{
valServo = map(pressureval, 0, 1023, 0, 180);
}

myservo.write (valServo);
Serial.println(valServo);
}
``````

Something like that perhaps…

You don’t have a servo, you have a motor with a single wire interface.
It is pointless calling it a servo.

Yeah but nothing’s correct in this world and that’s what people call them.
I suppose if you take a bike and remove a wheel it’s now a unicycle?
No - it’s a bike with one wheel…

You don't have a servo, you have a motor with a single wire interface. It is pointless calling it a servo.

Hmmm..., that is a little simplistic. It is a variable speed bi-directional motor.

AWOL decided to not answer my question and start playing semantics, of course this has muddied the whole post and now it's about whether a continuous rotation servo is really a servo. Thanks AWOL.. I would just like an answer to my question. No matter what I call my motor and whether I'm right or wrong for calling it what I do, does anyone know what is wrong with my sketch?

Thank you.

Take out the semicolon in if(valServo == 0);

Also, be a bit kinder, sometimes discussions get off topic but problems usually get solved in the end. No need to bash AWOL.

There is a term for a bicycle with one wheel. The word is 'knackered'

Actually the expression is

"Stop! Thief!"

Rob

No matter what I call my motor and whether I’m right or wrong for calling it what I do, does anyone know what is wrong with my sketch?

There is a reason for pointing out that what you have is NOT a servo. The reason is that the Servo::write() function works properly for servos, but not for bi-directional, variable speed motors.

For bi-directional, variable speed motors, you need to use Servo::writeMicroseconds() with the appropriate value (above ~1500 to go one way, and below ~1500 to go the other way). Of course, you need to figure out the exact value for your motor to make it hold still.

There is no way, with your non-servo, to command it to go to a specific position. Which, of course, is why people are trying to explain to you that you don’t have a servo. It is not strictly a matter of semantics.

Of course, that semi-colon isn’t helping. Embedding one function call (analogRead) inside another (map) isn’t helping either. You have no way of knowing exactly what value was returned by analogRead.

If the motor and the Arduino are sharing a power supply then this is probably a hardware problem - the analog input is picking up lots of noise from VCC. Never a good idea to share power supply between a motor/servo and the microcontroller.

You certainly need to test all your assumptions by printing out every important value to the Serial monitor.