Standard servo trouble
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
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
#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
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
UPDATE: I can take the servo controll wire out of the Arduino and touch it and it will work. WTF??
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.
This happens with both boards, both servos, both programs. Bad wiring?!!
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.
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!
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.
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.
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.
It is listed under its formal title "Basic Stamp Syntax and Reference Manual, V2.2"
https://www.parallax.com/tabid/440/Default.aspx