Trouble shooting of project Single-Cell Battery Tester

Hello!

I have found a project which looks quite simple:

I have setup everything according to the text and schematics on an Arduino Uno R3. When I uploaded the code on the board the LEDs just flicker randomly one at a time (while the USB is connected). It is supposed that a LED flashes at a certain voltage when a battery is connected (in this case I want to try on an AA-type 1.5V).
Can somebody explain why it doesn't measure anything from the battery? Maybe I should connect the +-side of the battery to the v_in pin (but how should the code then be)?

The battery should be connected between the analog port (battery +) and GND (battery -).

Do not connect the battery to Vin. That would attempt to power the Arduino with the battery, but you're getting your power from the USB port.

Even though this is quite old, I thought I'd give it a bump -- I'm doing the same project and having the exact same problem. Did you ever figure it out? I tried making some changes to the sketch, switched out the 3 LEDs for one RGB LED (added a "setColor" function)... nothing seems to be doing the trick.

Are you ABSOLUTELY sure you have used A0 This is on the opposite side of the board to the digital pins.

Having looked over the code, I believe it should work OK.

Yup, the + test wire is plugged into A0. Here's a picture of the wiring. Maybe you'll see something I don't (I'm very new to this).

battery tester.jpg

Hello,

I have also attempted this project, and am having similar results. I quadruple checked all the connections, schematics, and coding; everything is done as in the book. Upon inserting the USB cable to power up the UNO, the lights begin cycling in the 2 second intervals. It doesn't seem as though the initial state is holding for whatever reason. The two probe wires haven't made contact with each other. Even when I test a battery, the lights still cycle, green, yellow, red. I even went as far as purchasing another UNO, same thing happened right out of the box. I'm a bit perplexed.

This "random flashing LED" behaviour is normal when nothing is connected to an analogue input.

Leaving an input pin "floating" is bad practice.
It picks up hum and hash from the environment, and gives random values.

Adding a high value (e.g.100k) resistor from A0 to ground fixes this.
Leo..

I replaced the 2.2K ohm resistor with a 100K resistor. The only thing it seemed to do was stop the green led from blinking. The leds don't random blink, they cycle through the two second on/off intervals like the code dictates. So it would be green, yellow, red, green, yellow, red, and so on.

I understand that the code initiates the analogValue to be zero when you start sketch. And, I can see the noise from having a floating probe, it just seems as the analog pin isn't reading any inputs (AA batteries I want to test).

Thanks for replying, the help is appreciated. :o)