I have a sketch that runs fine when it's powered by USB from the computer. But it will not work properly on external power.
My project has a seeeduino board with the their brick shield on top. I'm using it to read a diffuse reflection IR sensor, and then manipulate a servo. It works fine when it is connected to the computer and receiving power through the USB port. However, I need it to work on battery power. I have the board installed on a 9V harness (seeedstudio's).
The seeeduino has a mini-switch to choose external or USB power. I select EXT and plug in the battery. It just twitches the servo. Everything I read says that a 9V should be able to power a micro-servo. Another strange thing is it tries to drive it in the wrong direction.
So I used the wall wart and little adapter (available from seeedstudio). It doesn't work either. I tried switching back to USB and plugging it in to another computer (without the sketch running, or the drivers installed). I also tried using a straight USB battery charger (like for a cell phone). All of those methods cause the servo to pulse rapidly (but not really move). It kind of has a decaying amplitude where the pulses get less intense over about a 10 second period.
The IR sensor has an LED on the back of it that lights when it detects a signal. That light also flashes in sync with the servo twitches. Note there is nothing in front of the sensor to trigger it. So obviously, something weird is being output on all the digital pins to cause this.
Regardless, it doesn't work anything like it should when powered by USB on the computer running the sketch. Unfortunately, this project is a Valentine's Day box that my son and I made for his school party this Friday. It senses the presence of someone, and then opens a door for them to put their Valentine inside. I don't think I'm going to be able to drag my computer along with it!
Am I missing something obvious? Is there something I was supposed to do with the bootloader? This is my first Arduino experiment so I'm hoping it's something very simple.
I really, really would appreciate some advice. I can upload pictures etc. if you want more information.
Well it should work just by changing the power switch to the external position and plugging in a voltage source greater then +6vdc or so.
Why don't you try a quick experiment that will eliminate your software and external loads (servo, etc). Just load the blink program from the example library and then see if it blinks the pin 13 LED while on USB power. Then unplug your USB and plug your 9vdc source into the external power connector and switch to external power. If the pin 13 still blinks then the problem is with your loads (too much current draw).
Thank you. I disconnected the servo and ran another sketch. I used the one provided for the IR sensor. It read the status of the sensor and turned LED 13 on and off properly. I disconnected USB and ran it on battery power. It worked just fine!
So back to the servo. Again, that sketch uploaded fine and ran properly on the computer with the FTDI drivers. It will not work on another computer that doesn't have those drivers installed. Nor will it work on battery power, or DC via the 2-pin battery terminal sourced by a wall adapter.
So I'm guessing the voltage regulator works on the battery terminal, but not on the USB? Although this really isn't a voltage issue, but a current draw problem (at least I hope so).
So it looks like I have to rig up an external power supply to the servo. At least that's my next step unless anybody has better ideas. Please, please, have a better idea!!!
If the Arduino won't pass enough current, do you think the 9V battery directly connected would do it?
So I'm guessing the voltage regulator works on the battery terminal, but not on the USB? Although this really isn't a voltage issue, but a current draw problem (at least I hope so).
Correct, when on USB power, +5vdc comes directly from the PC and is protected with a 500ma thermal fuse. External power has no such fuse and is limited by the on-board +5vdc regulators built in current and temperature shutdown limits.
So it looks like I have to rig up an external power supply to the servo. At least that's my next step unless anybody has better ideas. Please, please, have a better idea!!!
Your problem most likely is that +9vdc battery can't supply enough current, they are pretty wimpy. You can still use batteries. I would consider using the 9vdc battery to power the processor board and use 4 good alkiline AA batteries in series to power the servo's power and ground pins. Be sure the negitive terminal of the AA battery is also wired to a Arduino ground pin.
If the Arduino won't pass enough current, do you think the 9V battery directly connected would do it?
+9vdc is too high a voltage to wire to a servo, they require +5-6vdc only. You could wire +9vdc to an external +5vdc voltage regulator but a standard 9 volt battery is still too wimpy in current to supply a servo.
So to condense, a servo has a specific voltage (5-6vdc) requirement and a somewhat unknown current requirement, I usually recommend 1 amp per servo from it's power source. An Arduino type board fails to meet that second requirement in most cases when trying to power servo(s).
Well this thing is really annoying. I've about given up. I used an external power supply for the servo (4 AA's). I'm only using the arduino to get the signal and to connect the grounds together.
This works just fine when it is powered by USB. But when I swap over to battery power it misbehaves. The setup() program has a line to place the servo in its correct starting position. Instead, it will throw the servo in the other direction and "chirp" at it.
On two occasions, it actually worked properly on the battery. I've no idea how to replicate that situation, or what was unique about it.
I uploaded a video of it working properly to my facebook page. I'm thinking about uploading a misbehaving version to see if anyone has any insight.
// read the proximity detector
value = digitalRead(switchPin);
if (LOW == value) {
// proximity switch detects object
if (myservo2.read() == door_closed) {
// the door is closed
//lamp_on();
for (pos = door_closed; pos <= door_open; pos += 1)
{
myservo2.write(pos);
delay(20);
}
previousmillis = millis();
delay(5);
}
else {
//the door is already open
previousmillis = millis();
}
}
else {
// proximity switch does not detect object
if (myservo2.read() != door_closed) {
if (millis()-previousmillis > interval) {
// time to shut the door
//lamp_off();
//sweep_dish();
for (pos = door_open; pos >= door_closed; pos -= 1)
{
myservo2.write(pos);
delay(20);
}
delay(500);
}
}
else {
// nobody detected and the door is shut idle
}
}
}
For what it's worth, I tried to execute the servo sweep example that's provided online. I got the same problem. Works with USB, fails with battery power.
I also reduced my code down to nothing. I get the problem at the absolute beginning with the servo.attach() function. I've tried multiple pins--no difference.
I'm wondering if there's something different in the ground between the usb connection and the battery connection...late night musings. Or maybe my board is toast.
If you could post a electrical drawing and/or good photos I'm sure some useful suggestions could be offered. I still am suspecious of the 9vdc battery powering the board, is it fresh? Can you measure it's voltage (between Vin pin and ground) while it's operating and make sure it's supplying around or better then +7 volts or so at all times?
Regarding the previous inquiries: yes, the servo does move when it is powered up via the battery. Because of the external power, the center wire on the servo is getting about 6 volts.
I haven't checked the voltage from the Vin pin to ground on the arduino board. I'll do that next, but I don't think it is a problem (I've tried several 9v batteries just in case). Besides, all I'm attempting to do now is send the signal from Pin 9 and not draw any power to the servo from the board.
I'm thinking it has something to do with the bootloader. Not that I know anything about it, but here's why. The sketch only works when it is hooked up to the computer with the proper drivers. Another computer, which I presume would be able to supply just power, won't work. Nor will a USB wall charger.
I reduced the code down to a single servo.attach() function in the setup() module. That caused it to "fail." So it really has nothing to do with power levels or being able to write to the servo. Nothing that happens in loop() matters.
The seeeduino board has a switch that allows you to go from manual to auto reset. One time, and I can't remember the exact sequence, I changed the position of that switch. I don't know if I pushed reset before or afterwards....but it worked!!! Then I unplugged it and it went back to its old ways. I've not been able to repeat it.
Let me describe the "failure." Instead of moving the door to a closed position in setup(), nothing happens for about 5 seconds. Then the door moves in the opposite direction till I think the servo arms mechanically prevent it from going any farther. Then it pulses at maybe 3 cycles per second. It feels like it just can't get initialized properly.
BTW, I tried 3 different servos to see if the problem was there. No joy. Same issue.
Thank you for letting me ramble on about my little problem. Even though it's not solved, I've learned a great deal.