ArduinoMotorCarrier - BATTERY

Returns information about the battery connected to the carrier.

Syntax

battery.getRaw()
battery.getConverted()
battery.getFiltered()

Returns

  • getRaw(): returns the raw ADC read from the battery as an integer.
  • getConverted(): returns the battery voltage converted to volts as a floating point.
  • getFiltered(): returns the battery voltage converted to volts and filtered in the last 10 seconds.

Example


#include <ArduinoMotorCarrier.h>

//Variable to store the battery voltage
float batteryVoltage;
...
void loop() {
  batteryVoltage = battery.getRaw()/236.0; //236 for Nano, 77 for MKR.
  Serial.print("Battery voltage: ");
  Serial.print(batteryVoltage,3);  
  Serial.print("V, Raw ");
  Serial.println(battery.getRaw());
  delay(5000); //wait for a few seconds  
}