Pages: [1]   Go Down
Author Topic: This looked so simple  (Read 1023 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Help -- Please

#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);
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
There is no stop though
The servo must stop at some point - does it click when it hits the end-stop?
Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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...
« Last Edit: March 15, 2011, 03:36:23 am by mowcius » Logged

0
Offline Offline
Tesla Member
***
Karma: 148
Posts: 9750
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Sr. Member
****
Karma: 2
Posts: 360
I'm 15. I like making things. I like breaking things better.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Per Arduino ad Astra

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually the expression is

"Stop! Thief!"

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50921
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12717
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: