Charge an 18650 from USB-C
A USB-C charger into a TP4056 module charges a 30 percent 18650 at about 1 A, red while charging and blue once the cell is full. There is no microcontroller in it: the simulator solves the 3 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
Teaching? Assign it to your class in one click.
Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $4.20. On Mokxi they're free.
What you'll learn
- Analog
- Using the USB power
- Using the TP4056 charger
- Using the Battery: AA
- Difficulty: Beginner
- Time: About 10 minutes
- Parts: 3
How it works
A USB-C charger into a TP4056 module charges a 30 percent 18650 at about 1 A, red while charging and blue once the cell is full.
There is no code. The simulator solves USB power, TP4056 charger, USB-C, Battery: AA, coin cell, LiPo as it is wired, so change a value in the editor and watch the result.
Parts list
3 parts, plus the jumper wires. They retail for about $4.20; on Mokxi they're free.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| TP4056 charger, USB-C pin IN+ | USB power pin VBUS |
| USB power pin GND | Ground |
| TP4056 charger, USB-C pin IN- | Ground |
| Battery: AA, coin cell, LiPo pin V+ | TP4056 charger, USB-C pin BAT+ |
| Battery: AA, coin cell, LiPo pin V- | TP4056 charger, USB-C pin BAT- |
The notes that come with it
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// Charging an 18650 from USB-C with a TP4056 module.
//
// There is no microcontroller here. Press Run and the simulator solves the
// circuit.
//
// WHAT IT IS. A USB-C charger into the TP4056 charger board, and one 18650
// lithium-ion cell on BAT+ and BAT-, at 30 percent charge.
//
// THE NUMBERS. The module's readout is the charge current: about 1000 mA,
// the most its 1.2 k program resistor allows (1200 V over the resistor).
// The red lamp is lit while it charges.
//
// THINGS TO TRY. Set the cell's charge to 100 percent: at 4.2 V the current
// tapers off, and once it is under a tenth of the programmed current the
// blue lamp lights and the red one goes out. Set the USB supply's source to
// computer: a USB 2.0 port gives half an amp, so the cell charges at what
// the port can give, not at 1 A.
//
// ON THE BENCH. This board has no protection chip and no OUT pads: a load
// on BAT+ can run the cell flat. Use a cell with its own protection, or the
// module version with OUT+ and OUT-.
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The voltage is not what you expect. A plain USB breakout gives 5 V only, and a PD trigger asks the charger for a set voltage like 9, 12 or 20 V. USB power
Set the trigger to the voltage your circuit needs, and check it with a meter before connecting parts. A 5 V part on 12 V will burn. - The board resets or the charger shuts off when the load is heavy. USB power is limited to about 500 mA to 3 A, and cheap cables drop voltage. USB power
Use a good cable and a charger rated for the current. Add a 100 uF capacitor on the supply. Join the grounds of every board you power. - The battery is wired backwards, or the voltage is too low or too high for the circuit. A fresh AA is about 1.5 V, a LiPo is 3.7 V nominal and 4.2 V full. Battery: AA
Match the plus and minus marks. Check the voltage your parts need. Two AAs make 3 V, four make 6 V. Never feed a LiPo to a 3.3 V chip directly at 4.2 V. - The circuit resets or browns out when a motor or servo starts. A battery has internal resistance, so the voltage sags under load. Battery: AA
Use a fresh pack with enough current rating. Add a 100 uF or larger capacitor near the load. Power motors from their own pack and join the grounds.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.