When i transfer the sketch via usb to the arduino uno, it works when the uno is being powered by usb. When i connect the arduino to the power supply. It doesn't. It just hums a little bit but doesn't move at all. Does anyone know what's going on? do i need an external power supply for the servo? That doesn't seem to make much sense though.
Here's the sketch
#include <Servo.h>
Servo myServo; // Create Servo object to control the servo
void setup() {
myServo.attach(9); // Servo is connected to digital pin 9
}
void loop() {
myServo.writeMicroseconds(1700); // Counter clockwise
delay(2000); // Wait 2 seconds
myServo.writeMicroseconds(1300); // Clockwise
delay(2000);
myServo.writeMicroseconds(1500); // Stop
delay(2000);
}
That is weird it should work with that power pack if it works on USB. You should probably try and measure the board's 5V pin when on USB and then when on external power pack and see if there is a difference.
As a general rule it's just never a good idea to power a servo from the arduino 5V pin no matter what the power source is. Servos should use their independent regulated +5vdc power source with the ground also wired to a arduino ground pin.
I'm very new to electronics so forgive me. Will getting a another 9v reg wall wart, cutting the ends and plugging those into a breadboard with a voltage regulator work and be the cheapest/best option? If so, how would i go about sharing the ground with the arduino? Would i just leave the ground cable from the wall wart unplugged and use a jumper from the breadboard to the ground on the arduino?
You probably don't need another wall wart. What I would try doing, is taking another wire from the 9V of the supply to another regular to supply the servo power supply, separately from using the 5V regulator chip on the arduino board.
dadamssg:
I'm not sure i understand. The wall wart i have plugs straight into the barrel jack of the arduino. How would i get another wire from it?
The shield Vin pin is wired to the barrel jack's positive terminal (through a series polarity protection diode) so it's avalible for your use as a 'raw' 9vdc in your case using that 9v power module you showed. But keep in mind that your servo may still draw more current then the 9vdc module might be able to supply and in any event you can't draw more then 1 amp from the Vin pin because of the polarity protection diode which is rated for 1 amp maximum current.
Servos have motors in them, motors tend to draw lots of current depending on the mechanical load placed on them, so planning proper power management for servo(s) is not a slam dunk easy task sometimes.
Will the board run other sketches while using the 9V supply? e.g. run the LED on pin 13?
What voltage is actually being supplied? you need about 7.5V minimum.
If the current draw is too big for the supply, then the voltage may be collapsing too much and causing the Arduino to reset. Try adding a 100 to 1000 uf cap across the 9V supply as a ballast if the voltage is sagging.