Raymond Genovese
- Joined Mar 5, 2016
- 1,653
Can you run this little experiment://variable int 'total' declared - pin not set input/output - not needed and has worked several times before: - Aref set to 1.099 - int 'voltage' declared:
void battery_sense() { // battery_sense()
total = 0; // Reset value
analogRead(17);
for (int x = 0; x < 16; x++) {
total = total + analogRead(17);
}
voltage = total * Aref / 1023;
//Serial.print("The battery is ");
//Serial.print(voltage);
//Serial.println(" volts");
delay(100);
Use a 10K/10K or 1K/1K divider.
Take Arduino 5V on top and Arduino ground on the bottom and midpoint to A0 [NOTE, no aref connection] and run this code:
C:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(115200);
pinMode(A0,INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1024.0);
// print out the value you read:
Serial.println(voltage);
delay(1000);
}