Hi there,
A quick question after trying out a simple voltage reading sketch from "Arduino Workshop - John Boxall":
#define LED_NEW 9
#define LED_OK 10
#define LED_OLD 11
int d = 100;
int battery_charge ;
float voltage ;
void setup()
{
Serial.begin(9600);
Serial.println("Starting");
pinMode( LED_NEW , OUTPUT );
pinMode( LED_OK , OUTPUT );
pinMode( LED_OLD , OUTPUT );
}
void loop()
{
digitalWrite( LED_NEW , HIGH);
digitalWrite( LED_OK , HIGH);
digitalWrite( LED_OLD , HIGH);
delay(d);
battery_charge = analogRead(0);
Serial.println(battery_charge);
voltage = battery_charge * 0.0048 ;
Serial.println(voltage);
}
It works OK, well I guess its working as I am getting readings when testing on batteries I picked up around the house. The weird thing is that when nothing is connected I am still getting some sort of reading. I thought it might be some sort of loop in the LED's that are also connected but unplugging all the wires except for the two with the ground and A0 still gives output. Wondering if someone could point me in the direction as to why this is happening?