Let's Make Robots!

Powering an Arduino: batteries/USB

I have an Arduino, with a Sharp IR sensor connected to it, and code that basically says:

If analog value from Sharp > certain value, turn LED on.

else, turn LED off.

When I plug my Arduino into my computer, and power it via USB, this works perfectly.

However, when I power it by batteries (4 x AAA), the LED is always on, even when there is nothing near the Sharp at all. Can anyone give an explanation of why this happens, or a solution to this problem?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Actually I discovered that the problem wasn't the power supply. For test purposes, when I had the Arduino connected to my pc, I made it output the sensor values to the serial monitor. So in the code after if read the ADC, it had: Serial.println(input, DEC);

But when I plugged in the batteries, to use it on the ground, I commented that line out. And it didn't work. Then I stuck it back in, used batteries, it worked. Removed it, it doesn't.

This has happened on another project before (requiring the Serial output for the code to work). I have no idea why. Heard of this problem before?

Does it work with the line commented out when powered by USB? If not, then it is a timing thing. If it does, then I still think it may be power. I was told here that 6v was the absolute minimum for the VR and as you can see by what I was reporting, I was having all kinds of crazy things happen (even without the motor shield - having it just made the problems really obvious).  Changing code that should have nothing to do with other parts of the system seemed to break or magically fix them running that way.

I haven't tried that one, should give it a go.

Also, when I had this kind of problem before, it was where the Serial.println was in the code. When it was directly after reading a certain value from the serial monitor, it was fine. But anywhere else in the code, even like after a delay, it failed and read false values.

I'm guessing you need to replace the Serial.print line with a delay(). But I would need to see your loop code to be sure.

The Arduino doesn't seem to use an LDO VR; you want at least 7v going into the barrel jack to get a solid 5v on VCC.

I like the 7.2v NiMH or 7.4v LiPo batteries. They have enough juice to run it even when they start to run down, but the VR doesn't heat up much. At 9.6v and above the VR gets pretty hot. I have never tried more than 12v. I tried a 6v NiCad I had scavenged from an RC toy and had much the same experience as you. If you want to save money, you can get a NiCad and cheap charger (for LiPos and NiMH you want smart chargers) and if you are very careful about charging only when it runs down and not charging too long they work fine. 

I just discovered that the power is still a problem. I just had multiple problems.

So using something more than 4 x AAA should fix this problem? (the constant high analog readings)? I was plugging the batteries into the GND and Vin ports on the Arduino, not the barrel jack. Would using a 9v fix it?

 

EDIT:  I just used a 9v, works fine. Thanks heaps for the advice :)

You plugged the 9v into the barrel jack right?

Well, not the barrel jack, the GND and 5v (the power goes through a VR first) pins on the Arduino, but yeah, plugged in right

Saw your note above, glad to hear it is fixed. Yes, straight to VIN is pretty much the same thing though I am not sure if you get the polarity protection that way and you might get power from both it and the USB when plugged in (really shouldn't cause any problem, but not best practice), I am not sure whether that switch is mechanical in the barrel jack or not. I am actually doing the regulation to 5v and providing VCC on most of my projects. If you use a lot of power hungry modules and a servo or two you can push the limits of the standard VR. For really heavy use, you want an external separate power bus but its nice to have an amp or two available on VCC.