Fareed Mohmed← All projects

Info page · no simulation · Arduino and electronics

Mobile Phone Charger: How It Works and a Safe Li-ion Charger

How a 5 V mobile charger turns mains into USB power, and how a Li-ion cell is charged safely with a TP4056 module.

This topic cannot be run safely or meaningfully in the simulator, so this page explains it with diagrams, calculations and sample code instead. Everything here is original.

What you will learn

  • What the blocks of a switch-mode charger do
  • Why a charger must be isolated from the mains
  • How constant current and constant voltage charging works

In short

A phone charger is a switch-mode power supply. It rectifies the mains to high-voltage DC, chops it at tens of kilohertz, passes it through a small transformer that isolates the output, and rectifies it again to 5 V. A feedback loop through an optocoupler keeps the output steady. The page then shows a safe low-voltage Li-ion charger that you can build and test.

Try this next

  • Measure the voltage of a Li-ion cell every hour while charging and plot it.
  • Add a voltmeter module and show the stage (CC or CV) with LEDs.
  • Build a USB power bank with a boost converter.

Do not build or open a mains charger. The inside of a charger carries 325 V DC after the bridge rectifier. Do not copy the mains side on a breadboard. Use a ready, certified 5 V adapter for your experiments.

Block diagram of a mobile charger

230 V AC mainsFuse + rectifierAC to about 325 V DCBulk capacitorsmooths the DCSwitching ICchops at 50 to 100 kHzTransformerisolates the outputOutput diode + capacitormakes 5 V DCUSB output5 V, 1 to 2 AOptocouplerfeedback to the IC

The transformer is small and light because it works at high frequency. The optocoupler sends the feedback across the isolation gap using light, so no electrical connection joins the mains side and the USB side. This is why a good charger is safe to touch at the USB end, and a broken cheap one is not.

Charging a Li-ion cell: constant current then constant voltage

The TP4056 module is a ready board with the charge chip. A resistor Rprog sets the current: the usual 1.2 k gives 1 A. For a 1000 mAh cell, 1 A is a 1C rate. For small cells change Rprog to a larger value (for example 2 k gives about 580 mA).

A safe test build

// Show the cell voltage with a 10k + 10k divider on A0
void setup() { Serial.begin(9600); }

void loop() {
  int raw = analogRead(A0);
  float cell = raw * 5.0 / 1023.0 * 2.0;    // x2 because of the divider
  Serial.print("Cell voltage: ");
  Serial.print(cell, 2);
  Serial.println(" V");
  delay(2000);
}

Do and do not