Some test code you can try. Powering a servo from the arduino can cause problems. Also, the servo power supply ground and the arduino ground must be connected.
// 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
}
}
Hello. thanks for your feedback but the problem still on.
I have try to connect the servo on external power supply(battery) and the zzzz sound still come from the servo although the both Arduino
and servo on the common ground.
any other options ??? because I think that the servo need to be change, so I will go tomorrow to the store for change it.
Hello, thank you Shredder but I did the same thing and it didn't work. so I think maybe the usb can't power the Arduino enough, is it Possible that if I power it with 9v battery will work???
Because if didn't thats mean that the Arduino have problem and need to be changed.
MRLUCKY:
Hello, thank you Shredder but I did the same thing and it didn't work. so I think maybe the usb can't power the Arduino enough, is it Possible that if I power it with 9v battery will work???
The USB is fine for powering the Arduino board, but not the servo because it can't provide enough current for both. You will need either a separate AC adaptor or a battery dedicated to powering the servo just as zoomkat suggested earlier.
A 9V battery is not a good idea for two reasons. First, and most importantly, servos aren't just electrical motors they have integrated electronic controls that are built to tolerate a certain voltage level. Exceeding that voltage level by too much can damage the electronics. Second, 9V don't have a lot of charge capacity, even when compared to other common sizes like AA and AAA. All the "Latin letter" sized alkaline batteries (AAA, AA, C, & D) are nominally 1.5 VDC so you can connect them serially to get higher voltages. In fact you should be able to find cases for 4 AAA or AA batteries wired this way fairly easily.
MRLUCKY:
Because if didn't thats mean that the Arduino have problem and need to be changed.
Far-seeker:
All the "Latin letter" sized alkaline batteries (AAA, AA, C, & D) are nominally 1.5 VDC so you can connect them serially to get higher voltages. In fact you should be able to find cases for 4 AAA or AA batteries wired this way fairly easily.
Note, rechargeable Nimh batteries are 1.2 volts, not 1.5 volts. Also alkalines start out at 1.5 volts, but they do drop voltage as the battery gets depleted.
I did what zoomkat said and I used 4*AA Batteries and I connect the signal to pin9 and the batteries to red wire (servo) and the both servo ground and Arduino ground are connected to the batteries ground (common ground), But it keeps making the sound zzzz.
Note: if I remove the signal wire the sound stops.
Good, because if everything was functional correctly there really shouldn't be a difference. There's more than one GND pin for two reasons, first to increase the total current that can be sunk through the board's power supply and second to make bundling wires easier (because there are grounds on both sides that have rows of pins).
Solution found. Had the same problem. There is an error in the diagram. It suggests to put - on 26, + on 27 and A0 on 28 whereas servo pins are arranged as Ground-Control-Positive. Switch 27 and 28 (including capacitor) and it will work!