Pour mesurer l’état de la batterie reliée à l’Arduino :
Importer la librairie Vcc.zip (Box) <voltage>
Sketch exemple :
#include <Vcc.h>
const float VccMin = 0.0; // Minimum expected Vcc level, in Volts.
const float VccMax = 5.0; // Maximum expected Vcc level, in Volts.
const float VccCorrection = 1.0/1.0; // Measured Vcc by multimeter divided by reported Vcc
Vcc vcc(VccCorrection);
void setup()
{
Serial.begin(9600);
}
void loop()
{
float v = vcc.Read_Volts();
Serial.print("VCC = ");
Serial.print(v);
Serial.println(" Volts");
float p = vcc.Read_Perc(VccMin, VccMax);
Serial.print("VCC = ");
Serial.print(p);
Serial.println(" %");
delay(2000);
}
Sketch avec un écran LCD I2C téléchargeable ici (Box)
Votre commentaire