Home > Tech Article Categories > R3actor and Arduino > Battery Charging and Status with R3aktor
All R3aktor products include an integrated LiPo battery charger which can be connected to a single battery cell. The R3aktor will automatically charge a connected battery anytime power is provided through the USB-C connector. Once USB power is removed R3aktor will automatically switch over to using the battery for power.
Battery voltage can be monitored directly by reading the ADC_BATTERY analog input from within the Arduino IDE
IMPORTANT NOTE!
Before connecting the LiPo battery to the R3aktor, make sure the polarity of the battery matches the polarity of the R3aktor’s battery plug. The connector is keyed, which means it can only insert in one orientation.
For this project, you will need:
Connect the R3aktor to your computer via the USB-C cable and then insert the battery into the R3aktor.
When the battery is connected to the R3aktor and the R3aktor is connected to a power source like a computer via the USB-C cable, the battery will begin charging. Otherwise, the battery will be the power source of the R3aktor.
Open the Arduino IDE on your computer and create a new sketch. Copy and paste this code:
Upload the code to the R3aktor board. Open the serial monitor by selecting Tools -> Serial Monitor or by selecting the serial monitor icon in the upper left corner.
In the serial monitor, you will see the voltage of the battery being printed. It should be slowly rising because the battery is being charged. If you could read this value without the R3aktor being connected to a computer, you would see it slowly decrease.
To create a battery level indicator for when the R3aktor is not connected to a computer, set up the circuit depicted below.
Remember to disconnect the battery before connecting components and wires to the R3aktor board.
Each LED will be connected to digital pins 5, 6, 9, and 10.
Once you have connected each LED to the R3aktor, go back to the Arduino IDE and create a new sketch. Copy and paste this code:
Connect your R3aktor to your computer via the USB-C cable and upload this code by selecting the upload arrow.
When the battery is connected to the R3aktor board, the LEDs will light up to indicate the voltage level of the battery, which is a good indicator of its charge level.