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)?
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.
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.
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).