Shop OBEX P1 Docs P2 Docs Learn Events
Standard servo trouble — Parallax Forums

Standard servo trouble

annonymousannonymous Posts: 14
edited 2012-10-27 05:51 in General Discussion
I think it would help if I broke down my set up first. Then explained the problem. I have an Arduino Uno and a standard servo from parallax. I have a SPDT momentary switch and a toggle. I hooked up the servo to a specific pin(8), along with ground and 5v. I have the com prong of the SPDT switch, hooked up to a pin that i set to high. So it always pushes out voltage. The N/o prong is set to a pin(7) that waits for voltage. So, when I hit the switch, it closes the circuit sending voltage from pin the constant HIGH pin to the pin waiting for input. Once the pin that is wating for input recieves, it triggers the board to push out voltage to the servo
#include <Servo.h>


const int inPin = 7;
const int servoPin = 9;
const int buttonPin = 11;


void setup( ) {
  pinMode(inPin, INPUT);
  pinMode(servoPin, OUTPUT);
  //pinMode(buttonPin, OUTPUT);
}


void loop( ) {
  int val = digitalRead(inPin);
  digitalWrite(buttonPin, HIGH);
  if(val == HIGH) {
   digitalWrite(servoPin, HIGH);
   delayMicroseconds(2000);
   digitalWrite(servoPin, LOW);
   delay(20);
  } else if(val == LOW) {
    digitalWrite(servoPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(servoPin, LOW);
    delay(20);
  }
  
}

Now the problem is that the servo shakes one way but rotates fine going the opposite way. It worked at first but then stopped worked and started shaking. Sometimes it doesn't work at all. I have to move the whole set up around. I have 2 arduinos. One brand new and 2 servos. Both brand new. Same results with both servos.

Ideas??

https://www.facebook.com/photo.php?fbid=4765238816025&set=a.2608982950976.148761.1447027578

Comments

  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-22 19:31
    Since you include the servo library, why not create a servo object and in setup bind it to the servo pin? Then you can avoid bit banging the pulse and see if it is your code.
  • annonymousannonymous Posts: 14
    edited 2012-10-22 19:39
    OK, I just did and the strangest thing happened. It wouldn't work until i touched the servo pin wire with my finger. Where the wire goes into the arduino pin stack. Both Arduinos do the same.
    #include <Servo.h>
    
    
    Servo myservo;  // create servo object to control a servo
    
    
    int angle = 0;    // variable to store the servo position
    
    
    void setup()
    {
      myservo.attach(9);  // attaches the servo on pin 10 to the servo object
    }
    
    
    
    
    void loop()
    {
      for(angle = 0; angle < 180; angle += 1)  // goes from 0 degrees to 180 degrees
      {                                        // in steps of 1 degree
        myservo.write(angle);    // tell servo to go to position in variable 'angle'
        delay(20);                       // waits 20ms between servo commands
      }
      for(angle = 180; angle >= 1; angle -= 1) // goes from 180 degrees to 0 degrees
      {
        myservo.write(angle);     // tell servo to go to position in variable 'pos'
        delay(20);                       // waits 20ms between servo commands
      }
    }
    

    Come to think of it, the same applies to the other code as well. It worked when I touch the bottom of the board a certain way and would work if I didn't use the if and else if statements. For example, this worked fine
    #include <Servo.h>
    
    
    const int servoPin = 9;
    
    
    void setup( ) {
      pinMode(servoPin, OUTPUT);
    }
    
    
    void loop( ) {
       digitalWrite(servoPin, HIGH);
       delayMicroseconds(2000);
       digitalWrite(servoPin, LOW);
       delay(20);
    }
    

    UPDATE: I can take the servo controll wire out of the Arduino and touch it and it will work. WTF??
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-22 19:58
    Two things. When you are using the servo library you don't need the delay call as the library takes care of that for you. When power is marginal servos sometimes put the microcontroller into reset and cause weird things to happen. Try fresh batteries, I sometimes power the Arduino off a 9 volt and run the servos off 4 AA. Just make sure that the grounds are connected.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-22 20:07
    I agree with Martin. You shouldn't be messing with the servo pin directly. You should do all your servo control through the servo library.

    What are you trying to do?

    What kind of power supply are you using? A lot of servo troubles are caused by inadequate power.

    Another common problem (and the one I do the most) is not having a common ground between the servo and the microcontroller.
  • annonymousannonymous Posts: 14
    edited 2012-10-22 20:15
    I'm powering the board off of the Arduino's usb connection to my computer, and the servo off of the 5v/ground pins on the board. I just made a video -> http://www.youtube.com/watch?v=cxDUnZCg5G8

    T
    his happens with both boards, both servos, both programs. Bad wiring?!!
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-22 20:24
    I believe the USB port is limited to 500 mA which is marginal for an Arduino plus a servo.

    In setup add a line to set up the serial and add a Serial.println in setup. If you keep seeing the message in the debug window the microcontroller is resetting due to the marginal power.
  • annonymousannonymous Posts: 14
    edited 2012-10-22 20:41
    OK, give me a second to hook it up and I'll report back with the results.
  • annonymousannonymous Posts: 14
    edited 2012-10-22 20:54
    It's not resetting. Could it be the wire isn't thick enough and could be loose?? If i move the wire around it works and then doesn't. So, let me change the wire and Ill let you know whats up.

    EDIT:
    Now its working. So, it has to be the wire thickness right? It's sitting next to me on my bed and as I type my elbox is shaking the area a bit and the servo is going crazy.... What do you think?

    EDIT: Maybe it's my IDE because now it's not recognizing either arduino. I tried 2 different cables. My whole **** set is trash! I'm fed up of this **** and jjust going to run everything the **** over with my car!
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-23 00:43
    USB power is limited both by the actual power supply and by wire size. Either way, 500ma is considered the maximum and that is generally too little to drive a servo if it is under even a small load. When the motor hits the end of its rotation it is a stall mode and demanding a lot of current.

    If you really think about what the IDE is seeing - the USB port browned out because of the servo being a power hog.

    So it really has to do with you not providing an independent power supply to the at least the servo.

    IN other words, you need to learn how to properly provide power to your projects and not expect the USB port to be a reliable power supply for all and everything.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-23 08:20
    It's tough gettting started using microcontrollers. There are a bunch of little things you need to know.

    It's not uncommon for someone just starting using a servo to have trouble. We see it a lot here. Very, very frequently the problem is caused by the power supply.

    While it's possible to run a servo from power tapped off the USB supply, it's hit or miss. I generally only try to do this with very small servos (not Parallax's standard servo). When I do attempt to use USB power, I add a large (1000uF or more) capacitor to the servo's power line. I also use a powered hub when doing these type of experiments so I'm hopefully less likely to damage my PC.
  • RDL2004RDL2004 Posts: 2,554
    edited 2012-10-23 09:13
    If you live in the U.S. go to your local Walmart and buy a USB charger that plugs in the wall. Most of these can easily supply 1 amp (1000 mA), but read the package to be sure. I bought one there last month to power a Raspberry Pi and it was less than $12 including sales tax.
  • jtmoralesjtmorales Posts: 7
    edited 2012-10-27 00:22
    hey guys names JT and i am a NOOB i got the basic stamp 2 homework board USB and 2 standard servos and i have no idea what i am doing and I live in Puerto Rico and i can not find any books on the subject here, can anyone tll me where i can go to learn more about programing these servos to do the 180 degree turn back and forth manually and do they stay being used on the board or do i need to use another one to operate it, I want to use these to make a project using the iron man face plate
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-27 00:39
    jtmorales wrote: »
    hey guys names JT and i am a NOOB i got the basic stamp 2 homework board USB and 2 standard servos and i have no idea what i am doing and I live in Puerto Rico and i can not find any books on the subject here, can anyone tll me where i can go to learn more about programing these servos to do the 180 degree turn back and forth manually and do they stay being used on the board or do i need to use another one to operate it, I want to use these to make a project using the iron man face plate

    JT, You're better off starting a new thread if you're asking a question that's not directly related to the original poster's question. You're question has some similarities with the OP but IMO your question should have been asked in a new thread. No big deal through.

    You're in luck because not only does Parallax produce some great books for learning to program the Basic Stamp 2 but the give the books way (in PDF form).

    I think What's a Microcontroller is a good place to start. There's also a lot of other resources.

    You can usually move a servo off the board by making some sort of extension cord for them. I think you'd be safe with a couple of feet of wire beween the BS2 and the servos. I know there are tricks to reduce noise on long servo wires so if your servos don't behave well with longer wires, let us know and I bet someone around here will know how to help.

    BTW, just because a servo can be manually turned 180 degrees, doesn't mean it will turn that far under its own power. Some servos only turn about 90 degrees. You will want to keep this in mind when designing your costume.

    Edit: JT, I see you just posted this same question as a reply to a different thread. It's against the forum rules to ask the same question in more than one place.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-27 05:51
    Down load a copy of the Basic Stamp Manual as well === must have.

    It is listed under its formal title "Basic Stamp Syntax and Reference Manual, V2.2"


    https://www.parallax.com/tabid/440/Default.aspx
Sign In or Register to comment.