Go Down

Topic: This looked so simple (Read 1 time)previous topic - next topic

melvinprice

Mar 14, 2011, 06:49 pm
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);
}

AWOL

#1
Mar 14, 2011, 06:54 pm
Quote
There is no stop though

The servo must stop at some point - does it click when it hits the end-stop?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

melvinprice

#2
Mar 14, 2011, 07:03 pm
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.

AWOL

#3
Mar 14, 2011, 07:10 pm
Quote
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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

mowcius

#4
Mar 14, 2011, 10:52 pmLast Edit: Mar 15, 2011, 09:36 am by mowcius Reason: 1
Code: [Select]
`void loop(){int pressureval = analogread(0);  if(pressureval == 0)  {    valServo = 90;  }else{  valServo = map(pressureval, 0, 1023, 0, 180);}  myservo.write (valServo);  Serial.println(valServo);}`
Something like that perhaps...

Quote
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...

zoomkat

#5
Mar 14, 2011, 11:23 pm
Quote
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.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

melvinprice

#6
Mar 14, 2011, 11:45 pm
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.

bilbo

#7
Mar 15, 2011, 12:36 am
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.
Alice asked the Chesire Cat, who was sitting in a tree, "What road do I take?"
The cat asked, "Where do you want to go?"
"I don't know," Ali

Groove

#8
Mar 15, 2011, 09:00 am
There is a term for a bicycle with one wheel.
The word is 'knackered'

#9
Mar 15, 2011, 09:19 am
Actually the expression is

"Stop! Thief!"

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

PaulS

#10
Mar 15, 2011, 11:01 am
Quote
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.

MarkT

#11
Mar 15, 2011, 11:52 pm
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.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up

Please enter a valid email to subscribe