I'm trying to use my arduino to actuate two servos, on pins 9 and 10.
Everything worked fine, until my "lockState" button fell off. I reattached the button, but now whenever the lockserv servo drives, the unlockserv servo also drives in the opposite direction, at the same time.
I've been trying to tweak the code to keep this from happening all day, but with no luck. Does anyone have a suggestion of what may have gone wrong?
Also, I'm fairly new to Arduino coding, so I'll submit my sketch to critical eyes
I forgot to mention, my servo's have been modified to rotate continuously. Their potentiometers have been disabled and glued near the median value. I detach the servos when they're not in use because it's the only way I know to get them to stop spinning.
Another note: I unplugged the servo that was spinning even when detached, and whenever I touch my finger to the pwm (white) wire, the servo spins... Which is weird.
I believe it was grounding, after a few more stressful hours, I simply moved the servo's pin to the opposite side of my breadboard, and it works fine now x.x
I'm still not sure what's going on. Today I had to re-glue the button again, checked that it's working, and now I have the same servo issue. it's as though the entire system just freezes up, and I'm not sure how to fix a grounding problem that I can't see. Both servo's are connected to ground on the arduino. One of them still spins whenever I touch exposed wire on it's PWM pin.
right now I'm contemplating trying to wire a separate 5v power source up for the servos, but it's really out of the way x.x
Does anyone have a suggestion I can try first?
Okay, I re-wired the entire breadboard circuit, this time putting each servo on a separate ground to the arduino. Same deal, still doesn't work.
right now I'm contemplating trying to wire a separate 5v power source up for the servos, but it's really out of the way x.x
Hope you are not powering the servos from the arduino. Below is some servo testr code that might be useful for trouble shooting.
// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.writeMicroseconds(1500); //set initial servo position if desired
myservo.attach(7); //the pin for the servo control
Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
int n = readString.toInt(); //convert readString into a number
// auto select appropriate value, copied from someone elses code.
if(n >= 500)
{
Serial.print("writing Microseconds: ");
Serial.println(n);
myservo.writeMicroseconds(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
myservo.write(n);
}
readString=""; //empty for next input
}
}
zoomkat, Thanks for the test code. Unfortunately, I am powering the servos off of the arduino, one at a time. I know an excuse doesn't make it acceptable, but they're twelve feet from the nearest power outlet, and the only available power near them is one USB for the Arduino. I'm going to make an external power adapter for the servos a priority.
PeterH, I ran a continuity check, but it's difficult to get true readings because it involves unplugging wires from the breadboard, and I suspect it's the breadboard connection that's causing trouble. I uploaded a fairly accurate .fzz of the circuit earlier, once the external power supply is working I'll revise it.
After a few more hours today, I simplified the wiring for my two buttons, soldered better connections to my servos, and ended up getting it to work again only after restarting the USB power supply to the arduino... Three times... I have no idea what's going on any more.
only after restarting the USB power supply to the arduino... Three times... I have no idea what's going on any more.
That is one reason why you don't power servos from the arduino. The current draw from a servo can trip out the USB port on the pc USB port supplying the arduino. Thankfully USB ports usually have internal fuses to prevent damage to the pc.
:-\ I was actually pretty sure that I would need the regulator. I think I have a 12v wall wart laying around somewhere, and passing it through the regulator sounded like a good way to get power for the servos..
BBX:
:-\ I was actually pretty sure that I would need the regulator. I think I have a 12v wall wart laying around somewhere, and passing it through the regulator sounded like a good way to get power for the servos..
Using a 7805 regulator to power a servo might be able to reliably handle a single servo. I always advice to have at least one amp of power supply capacity for EACH servo you will have in operations. Lower then that and you are just asking for problems.
If you use a 7805 regulator chip for servo power, put a diode on the ground leg of the chip to increase the chip output voltage from 5.0v to 5.7v for better servo performance.