SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
User avatar
By viskr
#113869
Basically measure the voltage divider, it should be 1/2 the battery voltage. If its not then the AD input is loading down the divider too much and you'll need to decrease the resistor values.

Is your supply 5V or 3.3? If 3.3, then those analog switches don't like to be pulled above the supply.
If it is 3.3V, divide by 3, with 20M and 10M.

With resistances that high you're starting to get into the realm of very high impedance circuits. By the time you get to 100M, your circuit turns from being something useful to being an antenna picking up any stray signals. Also at those levels, just touching the resistors will leave enough perspiration to affect the values.
By cbabilotte
#114777
I got mine to work with 3 resistors of 10 M in series. If you take the attachement I previously posted you just add a new 10 M resistor and that should work. I have also a resistor from the analog pin to gnd

I think if I play with the map function I can get it to what the measurement is suppose to be. Also maybe the resistor that is from the analog to gnd might not be the right value so I can still teak it that way. With the code below I am off but it is very minimal. I will try to post a picture when I am done.

Here is the code I am using

// variables for input pin and control LED
int analogInput = 1;
int LEDpin = 13;
int prev = LOW;
int refresh = 1000;
float vin = 0.0;

// variable to store the value
int value = 0;


void setup(){

// declaration of pin modes
pinMode(analogInput, INPUT);
pinMode(LEDpin, OUTPUT);

// begin sending over serial port
Serial.begin(9600);
}

void loop(){
// read the value on analog input
digitalWrite(analogInput, LOW);
value = analogRead(analogInput);
Serial.print("value=");
Serial.println(value);

// blink the LED
if (prev == LOW) {
prev = HIGH;
} else {
prev = LOW;
}
digitalWrite(LEDpin, prev);

vin = map(value,0,1023,0,8690)/100.0;

Serial.print(vin);
Serial.println(" volt");

// sleep...
delay(refresh);
}
By MobileWill
#114778
Thanks that would be helpful. Even though mine works it seems to not be accurate enough to monitor battery level. I was hoping to shutdown attached systems/sensors based on battery level.