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
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
- A Li-ion cell is full at 4.2 V. It must never be charged above that.
- Stage 1 (CC): the charger gives a fixed current (1 A for the TP4056 default) until the cell reaches 4.2 V.
- Stage 2 (CV): the voltage is held at 4.2 V and the current falls. The charge ends when the current is about 1/10 of the set value.
- A protection board (DW01 chip with two MOSFETs) cuts the cell off if it is over-charged, over-discharged or shorted.
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
- USB 5 V supply, 1 A or more.
- TP4056 module with protection (the board has the extra DW01 chip).
- One protected 18650 cell.
- A voltmeter module or Arduino analog pin through a 10 k + 10 k divider (cell 4.2 V gives 2.1 V).
// 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
- Do use a protected cell and a charger board with protection.
- Do charge on a non-flammable surface and stay nearby.
- Do check that the cell polarity is right before you connect it.
- Do not charge a swollen, hot or damaged cell.
- Do not charge a Li-ion cell with a lead-acid charger.
- Do not leave a cell charging overnight.