By Hakimu Maganda | Category: Power Electronics | Published: 2026-11-08
Tired of hunting for a 12V adapter that fits your project? A modern USB-C PD charger already has the power you need: 5V, 9V, 12V, 15V and 20V at up to 65W or more. The catch is that a PD charger outputs only 5V until your device asks for a higher voltage. Without a USB-C Power Delivery sink controller, your 12V fan, LED strip or ESP32 project never receives it.
In this guide you will build a programmable USB-C PD sink controller using the CH224K PD trigger chip and an ESP32. Press a button and the board requests a new voltage from the charger. An OLED shows the requested voltage, the measured voltage, current in mA, power in mW and a power-good status. It works as a compact USB-C bench power supply and is a solid base for DIY chargers, soldering irons, LED drivers and portable test rigs.
What you will learn:
Safety first: 15V and 20V can destroy loads that are rated for 5V or 12V only. Always check your load's maximum input voltage before enabling high-voltage profiles.
| # | Component | Qty | Key Spec and Notes | Where to Buy | Approx. Price |
|---|---|---|---|---|---|
| 1 | CH224K USB-C PD trigger module with CFG1, CFG2, CFG3 and PG pads | 1 | Must expose the CFG pads; fixed-voltage PD sink | Alibaba, AliExpress, LCSC (bare chip), local electronics shops | 1.5 to 4 USD |
| 2 | ESP32 DevKit (30 or 38 pin) | 1 | 3.3V logic is required (see warning below) | Alibaba, AliExpress, local suppliers | 4 to 7 USD |
| 3 | INA219 current and voltage sensor module | 1 | 26V bus maximum, 0.1 ohm shunt, about 3.2A maximum | Alibaba, AliExpress | 1 to 3 USD |
| 4 | SSD1306 OLED 128x64, I2C (address 0x3C) | 1 | 3.3V compatible | Alibaba, AliExpress, local shops | 2 to 4 USD |
| 5 | Buck converter module (Mini360 or LM2596), set to 5.0V | 1 | Input rating must be 23V or higher | Alibaba, local suppliers | 1 to 2 USD |
| 6 | Resistor 6.8k ohm, 1/4W | 1 | CFG1 safe default (requests 9V at power-up) | Any electronics shop | Under 0.1 USD |
| 7 | Tactile push button | 1 | Voltage cycle button | Any electronics shop | Under 0.1 USD |
| 8 | USB-C PD charger, 45W or higher | 1 | Must advertise 9V, 12V, 15V and 20V profiles | Local phone and laptop accessory shops | 8 to 20 USD |
| 9 | USB-C cable rated 3A or higher | 1 | A weak cable causes voltage drops | Local shops, Alibaba | 2 to 5 USD |
| 10 | Breadboard, jumper wires, 2-pin screw terminal | 1 set | Wiring and load output | Any electronics shop | 3 to 5 USD |
Sourcing tips for East Africa: Bare chips and modules are cheapest on Alibaba, AliExpress or LCSC, but shipping takes time. For faster builds, check electronics markets such as Kariakoo in Dar es Salaam and River Road in Nairobi for ESP32 boards, OLEDs and buck modules. Buy PD chargers from reputable sellers, because fake 65W chargers are common.
Compatibility warning: The CH224K datasheet limits the CFG2 and CFG3 input voltage to 3.7V, so use a 3.3V microcontroller such as the ESP32, Raspberry Pi Pico or ESP8266. Do not connect those pins directly to a 5V Arduino Uno or Nano without level shifting.
| From (Board / Pin) | To (Component / Pin) | Function / Description |
|---|---|---|
| PD charger USB-C | CH224K module USB-C input | PD negotiation and 5V to 20V power input |
| CH224K module VOUT (+) | INA219 VIN+ | Power rail into the shunt (high-side sensing) |
| CH224K module VOUT (+) | Buck converter IN+ | Powers the ESP32 from the PD rail |
| INA219 VIN- | Load (+) / screw terminal (+) | Rail to your load, measured by the INA219 |
| CH224K module GND | Common GND (ESP32, INA219, OLED, buck, load) | Single shared ground |
| Buck converter OUT+ (5.0V) | ESP32 VIN (5V pin) | Powers the ESP32 (adjust the buck to 5.0V before connecting) |
| ESP32 3V3 | INA219 VCC and OLED VCC | 3.3V power for the sensors |
| ESP32 GPIO21 | INA219 SDA and OLED SDA | I2C data |
| ESP32 GPIO22 | INA219 SCL and OLED SCL | I2C clock |
| ESP32 GPIO25 | CH224K CFG1 | Voltage select bit 1 (HIGH requests 5V) |
| ESP32 GPIO26 | CH224K CFG2 | Voltage select bit 2 |
| ESP32 GPIO27 | CH224K CFG3 | Voltage select bit 3 |
| ESP32 GPIO32 | CH224K PG | Power-good input (active LOW) |
| ESP32 GPIO33 | Push button, other leg to GND | Cycles the voltage profile (internal pull-up used) |
| CH224K CFG1 | 6.8k resistor to GND | Safe default: requests 9V while the ESP32 is not running yet |
| CFG1 | CFG2 | CFG3 | Requested Voltage |
|---|---|---|---|
| 1 | any | any | 5V |
| 0 | 0 | 0 | 9V |
| 0 | 0 | 1 | 12V |
| 0 | 1 | 1 | 15V |
| 0 | 1 | 0 | 20V |
Why the 6.8k resistor matters: If CFG1 is left floating before the microcontroller boots, the CH224K can request 20V. The 6.8k resistor to GND forces a safe 9V request at startup, and the firmware starts in the matching 9V profile so no re-negotiation glitch occurs.
Module warning: Many CH224K boards have solder jumpers or onboard pull-up and pull-down resistors on the CFG lines. Open or remove these before wiring the ESP32. With the ESP32 disconnected and only the 6.8k resistor fitted, confirm with a multimeter that the module outputs about 9V before connecting any load.
flowchart LR
CHG["USB-C PD Charger 45W+"] -->|"USB-C cable"| MOD["CH224K PD Sink Module"]
MOD -->|"VOUT 5V to 20V"| INA["INA219 VIN+"]
MOD -->|"VOUT 5V to 20V"| BUCK["Buck 5.0V IN+"]
INA -->|"VIN-"| LOAD["Load (+) Terminal"]
BUCK -->|"5.0V"| ESP["ESP32 VIN"]
ESP -->|"GPIO25"| CFG1["CH224K CFG1"]
ESP -->|"GPIO26"| CFG2["CH224K CFG2"]
ESP -->|"GPIO27"| CFG3["CH224K CFG3"]
MOD -->|"PG (active LOW)"| PG["ESP32 GPIO32"]
ESP -->|"3V3"| PWR["INA219 + OLED VCC"]
ESP -->|"GPIO21 SDA / GPIO22 SCL"| BUS["INA219 + SSD1306 I2C"]
BTN["Push Button"] -->|"GPIO33 to GND"| ESP
R1["6.8k resistor"] -->|"CFG1 to GND"| CFG1
GND(("Common GND")) --- MOD
GND --- ESP
GND --- BUCK
GND --- LOAD
ASCII power-rail view (works without JavaScript):
PD Charger --USB-C--> [CH224K] ---VOUT(5V-20V)---+---> [INA219 VIN+ ... VIN-] ---> LOAD (+)
| |
CFG1/2/3 + PG +---> [Buck 5.0V] ---> ESP32 VIN
| |
+<------- GPIO25/26/27 , GPIO32 -------------------+
ALL GROUNDS TIED TOGETHER (CH224K GND = ESP32 GND = INA219 GND = Load GND)
6.8k resistor: CFG1 ---/\/\/\--- GND
Libraries to install (Arduino IDE, Library Manager): Adafruit SSD1306, Adafruit GFX Library and Adafruit INA219. Also install Adafruit BusIO if prompted.
Board package: esp32 by Espressif Systems. Select the board "ESP32 Dev Module".
/*
USB-C Power Delivery Sink Controller
Tech Circuit Guide - techcircuitguide.com
Author: Hakimu Maganda
Hardware: ESP32 + CH224K PD module + INA219 + SSD1306 OLED
Behavior:
- Boots in the 9V profile (matches the 6.8k resistor on CFG1).
- Button press cycles through allowed voltage profiles.
- 15V and 20V are BLOCKED unless ALLOW_HIGH_VOLTAGE is set to true.
- OLED shows target voltage, measured voltage, current, power and status.
*/
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_INA219.h>
// ---------------- Pin configuration ----------------
#define I2C_SDA_PIN 21
#define I2C_SCL_PIN 22
#define PIN_CFG1 25 // CH224K CFG1
#define PIN_CFG2 26 // CH224K CFG2
#define PIN_CFG3 27 // CH224K CFG3
#define PIN_PG 32 // CH224K PG (active LOW = power good)
#define PIN_BTN 33 // Push button to GND
// ---------------- Display configuration ----------------
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDR 0x3C
// ---------------- Safety settings ----------------
// Set to true ONLY if your load is rated for 15V and 20V.
const bool ALLOW_HIGH_VOLTAGE = false;
// Set to false if your module does not expose the PG pin.
const bool USE_PG_PIN = true;
// ---------------- PD profile table ----------------
// Matches the CH224K level configuration truth table.
struct PdProfile {
uint8_t volts;
uint8_t cfg1;
uint8_t cfg2;
uint8_t cfg3;
};
const PdProfile PROFILES[] = {
{ 5, HIGH, LOW, LOW }, // CFG1=1 gives 5V
{ 9, LOW, LOW, LOW }, // CFG1=0, CFG2=0, CFG3=0 gives 9V
{ 12, LOW, LOW, HIGH }, // CFG1=0, CFG2=0, CFG3=1 gives 12V
{ 15, LOW, HIGH, HIGH }, // CFG1=0, CFG2=1, CFG3=1 gives 15V
{ 20, LOW, HIGH, LOW } // CFG1=0, CFG2=1, CFG3=0 gives 20V
};
const uint8_t PROFILE_COUNT = sizeof(PROFILES) / sizeof(PROFILES[0]);
const uint8_t DEFAULT_PROFILE = 1; // 9V, matches hardware default
// ---------------- Globals ----------------
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_INA219 ina219;
uint8_t currentIdx = DEFAULT_PROFILE;
unsigned long changedAt = 0;
unsigned long lastDraw = 0;
unsigned long lastPress = 0;
bool wasDown = false;
// ---------------- Apply a PD profile ----------------
// CFG2 and CFG3 are written first, CFG1 last, to reduce transient states.
void applyProfile(uint8_t idx) {
const PdProfile &p = PROFILES[idx];
digitalWrite(PIN_CFG2, p.cfg2);
digitalWrite(PIN_CFG3, p.cfg3);
digitalWrite(PIN_CFG1, p.cfg1);
currentIdx = idx;
changedAt = millis();
Serial.printf("Requested profile: %uV\n", p.volts);
}
// ---------------- Find next allowed profile ----------------
uint8_t nextIndex(uint8_t idx) {
for (uint8_t i = 1; i <= PROFILE_COUNT; i++) {
uint8_t n = (idx + i) % PROFILE_COUNT;
if (ALLOW_HIGH_VOLTAGE || PROFILES[n].volts <= 12) {
return n;
}
}
return idx;
}
// ---------------- Status evaluation ----------------
const char* statusText(float busV) {
uint8_t target = PROFILES[currentIdx].volts;
if (millis() - changedAt < 1500) return "NEGOTIATING";
bool vOk = fabsf(busV - (float)target) <= ((float)target * 0.15f);
bool pgGood = USE_PG_PIN ? (digitalRead(PIN_PG) == LOW) : true;
if (pgGood && vOk) return "OK";
if (!vOk) return "V MISMATCH";
return "PG FAULT";
}
// ---------------- Button handling ----------------
void handleButton() {
bool down = (digitalRead(PIN_BTN) == LOW);
if (down && !wasDown && (millis() - lastPress > 50)) {
lastPress = millis();
applyProfile(nextIndex(currentIdx));
}
wasDown = down;
}
// ---------------- OLED update ----------------
void updateDisplay() {
float busV = ina219.getBusVoltage_V();
float curmA = ina219.getCurrent_mA();
float powmW = ina219.getPower_mW();
const char* st = statusText(busV);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("PD Target: ");
display.print(PROFILES[currentIdx].volts);
display.println("V");
display.setCursor(0, 14);
display.print("Measured : ");
display.print(busV, 2);
display.println("V");
display.setCursor(0, 26);
display.print("Current : ");
display.print(curmA, 0);
display.println("mA");
display.setCursor(0, 38);
display.print("Power : ");
display.print(powmW, 0);
display.println("mW");
display.setCursor(0, 52);
display.print("Status: ");
display.print(st);
display.display();
Serial.printf("Target=%uV Bus=%.2fV I=%.0fmA P=%.0fmW Status=%s\n",
PROFILES[currentIdx].volts, busV, curmA, powmW, st);
}
// ---------------- Setup ----------------
void setup() {
Serial.begin(115200);
delay(200);
// CFG pins start as outputs at the 9V profile (all LOW),
// matching the hardware default set by the 6.8k resistor.
pinMode(PIN_CFG1, OUTPUT);
pinMode(PIN_CFG2, OUTPUT);
pinMode(PIN_CFG3, OUTPUT);
pinMode(PIN_PG, INPUT_PULLUP);
pinMode(PIN_BTN, INPUT_PULLUP);
applyProfile(DEFAULT_PROFILE);
Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
Serial.println("ERROR: SSD1306 not found. Check wiring and address 0x3C.");
for (;;) { delay(1000); }
}
if (!ina219.begin()) {
Serial.println("ERROR: INA219 not found. Check wiring and address 0x40.");
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("INA219 NOT FOUND");
display.println("Check I2C wiring");
display.display();
for (;;) { delay(1000); }
}
// 32V range, 2A max calibration (suits 0.1 ohm shunt modules)
ina219.setCalibration_32V_2A();
Serial.println("USB-C PD Sink Controller ready.");
}
// ---------------- Main loop ----------------
void loop() {
handleButton();
if (millis() - lastDraw >= 250) {
lastDraw = millis();
updateDisplay();
}
}
Next step: Learn more about the sensor in the ESP32 and INA219 Power Monitor Guide, and set up your regulator with the LM2596 Buck Converter Setup Guide.
Why does my CH224K only output 5V?
Common causes are a charger that does not offer the requested voltage profile, a low-quality cable, or CFG1 being held HIGH by a leftover jumper or pull-up. Try a different PD charger and confirm its label lists the voltage you want.
Why did my board output 20V at startup?
A floating CFG1 can lead to a 20V request. Fit the 6.8k resistor from CFG1 to GND for a safe 9V default before the microcontroller boots.
Can I use an Arduino Uno or Nano with the CH224K?
Not directly. CFG2 and CFG3 are limited to 3.7V on the CH224K, so use a 3.3V microcontroller such as the ESP32 or Pico, or add level shifting.
My OLED stays blank. What should I check?
Run an I2C scanner. The OLED is normally at 0x3C and the INA219 at 0x40. Check that SDA and SCL are not swapped and that both modules share GND with the ESP32.
The ESP32 resets when I change voltage.
The buck converter input is probably dipping during the transition. Add a 100uF to 470uF capacitor on the buck input and use short, thick wires on the PD rail.
The INA219 shows 0 mA or negative current.
Check that current flows from VIN+ to VIN-. Swapped terminals give negative readings.
Error: Adafruit_INA219.h: No such file or directory
Install "Adafruit INA219" from the Library Manager, along with Adafruit BusIO.
Error: SSD1306 allocation failed, or display not found
Check the I2C address (0x3C or 0x3D) and the wiring, and make sure you selected an ESP32 board rather than an Arduino board.
Upload stuck on "Connecting........"
Hold the BOOT button while uploading, use a data-capable USB cable, and install the CP210x or CH340 driver for your board.
How do I get 12V from a USB-C charger?
Use a PD trigger or sink chip such as the CH224K, set CFG1, CFG2 and CFG3 to 0, 0 and 1, and use a charger that supports 12V PD.
Does the CH224K support PPS or adjustable voltage?
The CH224K selects fixed PD voltages (5V, 9V, 12V, 15V and 20V). Variants such as the CH224Q and CH224A add I2C control. Check the datasheet for the exact part you buy.
What is the maximum current?
It depends on your charger and cable. Standard cables carry 3A, and 5A needs a suitably rated cable and charger. This build is limited to about 3.2A by the INA219 shunt, so use a different current sensor for heavier loads.
Can I power a 12V LED strip directly?
Yes, if the strip is rated for 12V and within your charger's wattage. Test at 9V first and watch the current on the OLED.
Affiliate disclosure: some links below may earn Tech Circuit Guide a small commission at no extra cost to you. We only recommend parts we would use ourselves.
Get the USB-C PD CFG Pin Cheat Sheet, a printable truth table and wiring checklist: download the cheat sheet.
Built this project? Share your result or ask a question in the comments, and subscribe to Tech Circuit Guide for the next power electronics build.