LM317 variable power supply
Turn a 12 V adapter into an adjustable 1.25–10 V supply for your experiments.
Shop by category
Shop all componentsA phone does not charge at a steady rate. The INA219 in the USB lead logs the current every 30 seconds, with the date and time. The graph shows fast charging at first and a long gentle tail at the end, and explains why the last 20 % takes so long.
Only for low-voltage USB leads. Never connect to mains.
Tick anything you already have and the total updates.
Connects the Uno to your computer to upload code and power it
Measures voltage, current and power of a DC circuit up to 26 V and 3.2 A through a tiny shunt resistor, and reports them over I²C.
Temperature-compensated real-time clock (±2 minutes a year) with a coin-cell backup, so the time survives power cuts.
Stores readings on a microSD card as a CSV file you can open in Excel or Google Sheets.
Follow the colours: red is power, dark grey is ground, blue is a signal.
class_phone_charge_current_curve.inoVerify & upload in Electrolark// How a phone charge current changes over time
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "class-phone-charge-current-curve"
#include <Wire.h>
#include <Adafruit_INA219.h>
#include <RTClib.h>
#include <SPI.h>
#include <SD.h>
// ---- pins ----
const uint8_t SD_CS = 10;
Adafruit_INA219 ina;
RTC_DS3231 rtc;
// ---- latest readings ----
float busV = 0;
float currentMa = 0;
float powerMw = 0;
const unsigned long LOG_EVERY_MS = 30000UL; // one row per 30 s
unsigned long lastLog = 0;
bool cardOk = false;
void writeRow() {
File f = SD.open("LOG.CSV", FILE_WRITE);
if (!f) { Serial.println(F("Write failed")); return; }
DateTime t = rtc.now();
char stamp[20];
snprintf(stamp, sizeof(stamp), "%04d-%02d-%02d,%02d:%02d:%02d", t.year(), t.month(), t.day(), t.hour(), t.minute(), t.second());
f.print(stamp);
f.print(',');
f.print(busV, 2);
f.print(',');
f.print(currentMa, 0);
f.print(',');
f.print(powerMw, 0);
f.println();
f.close();
}
void setup() {
Serial.begin(115200);
if (!ina.begin()) Serial.println(F("INA219 not found"));
if (!rtc.begin()) Serial.println(F("RTC not found"));
if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // set from the upload time
cardOk = SD.begin(SD_CS);
Serial.println(cardOk ? F("SD card ready") : F("SD card not found"));
if (cardOk && !SD.exists("LOG.CSV")) {
File f = SD.open("LOG.CSV", FILE_WRITE);
if (f) { f.println(F("date,time,Voltage(V),Current(mA),Power(mW)")); f.close(); }
}
}
void loop() {
if (millis() - lastLog < LOG_EVERY_MS && lastLog != 0) return;
lastLog = millis();
busV = ina.getBusVoltage_V();
currentMa = ina.getCurrent_mA();
powerMw = ina.getPower_mW();
Serial.print(F("Voltage="));
Serial.print(busV, 2);
Serial.print(F("V"));
Serial.print(F(", Current="));
Serial.print(currentMa, 0);
Serial.print(F("mA"));
Serial.print(F(", Power="));
Serial.print(powerMw, 0);
Serial.print(F("mW"));
Serial.println();
if (cardOk) writeRow();
}
The sketch above runs here on a simulated Arduino Uno. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
Check SDA and SCL. An I²C scanner should show 0x40.
The + wire must pass through VIN+ to VIN−; measuring on the GND side does not work.
The coin cell is flat or missing. Some modules need the charging resistor removed when using a CR2032.
Check the card is FAT32, fully inserted, and CS is on the pin in the sketch.
Open the Serial Monitor at 115200 baud and check for messages. Make sure you chose the right board and port in the Arduino IDE.
Close other programs using the serial port, try another USB cable (some are charge-only) and press reset just before uploading.
Use a spare phone or power bank, and log from a low charge to full. Plot the file in a spreadsheet and compare a fast and a slow charger.
Yes. Most of the code works unchanged on an ESP32 with the ESP32 board package. Watch for 5 V modules: ESP32 pins are 3.3 V, so 5 V output signals need a resistor divider.
Use a 5 V USB phone charger or a power bank into the board's USB port.
8 parts: Uno R3 CH340G ATmega328p Compatible Development Board, Arduino USB-A to USB-B Data Cable for UNO/MEGA, INA219 Current and Power Monitor Module, DS3231 Precision RTC Module with EEPROM, DFRobot Fermion MicroSD Card Module – SPI, microSD Memory Card Class 10 (16GB), Solderless Breadboard (830 points) and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 2 hours. The build on this page has 8 steps.
No. This page has the complete, tested code (class_phone_charge_current_curve.ino). Install these libraries first: Adafruit INA219, RTClib and SD.
Yes. The Run it panel under the code runs this exact sketch on a simulated board. Move the sliders or press the buttons for the sensors it reads, and the Serial monitor, display and outputs react as they will on the real build. It is a simulation, so real readings depend on your parts and wiring.
About ₹1,607 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Battery charging; Reading graphs.
Only for low-voltage USB leads. Never connect to mains.
Ideas that reuse this build: Battery discharge and Wi-Fi charger monitor. They are listed under Take it further on this page.
Turn a 12 V adapter into an adjustable 1.25–10 V supply for your experiments.
Build your own USB power bank and learn how lithium charging works.
Free power for outdoor sensors: sunlight in, 5 V USB out.
Beeps when the mains goes off at night, so the fridge and the alarm clock do not quietly die.
Learning project. Check every circuit and the datasheet of each part before you power it up.
Voltage=12.01V, Current=448mA, Power=5407mW Voltage=11.98V, Current=450mA, Power=5387mW Voltage=11.99V, Current=451mA, Power=5398mW Voltage=11.99V, Current=449mA, Power=5402mW
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.