MilikMilik

Build Your Own Smart USB-C Power Controller and Meter

Build Your Own Smart USB-C Power Controller and Meter
Interest|Open-Source Hardware

What You’re Building: A Smart USB-C Power Toolkit

A DIY smart power controller is a small hardware setup that lets you choose USB-C power delivery voltages and monitor live energy use, combining a programmable sink controller, a RISC-V microcontroller, current sensors, and a graphical display into one flexible, open-source power management tool that makers can adapt for chargers, test benches, and efficiency experiments. If you already tinker with microcontrollers and basic electronics, this is worth your time: you end up with a USB-C power delivery voltage selector that cycles from 5V to 20V using a single button, plus an advanced dual-sensor power meter with live graphing and efficiency calculations. The caveat is safety—higher PD voltages can damage gear, so you need to respect ratings and double-check your wiring.

How USB-C Power Delivery and the CH224K Selector Work

Before you start soldering anything, it helps to understand what your DIY voltage controller is doing. Traditional USB ports give you 5V and stop there, while USB-C power delivery (USB-C PD) is a protocol that lets a charger and device negotiate higher voltages and currents over the same cable, commonly 5V, 9V, 12V, 15V, and 20V up to typical PD power levels. This negotiation runs on the CC lines of the USB-C connector: the sink (your board) asks for a voltage and the charger either agrees or offers the closest it can provide. In this build, a CH224K PD sink IC handles the protocol and exposes three configuration pins—CFG1, CFG2, CFG3—that map to those discrete voltage options. You can hard-wire resistors to get a fixed voltage, but driving CFG pins from a microcontroller lets you change those settings on demand, which is where the CH32V003 RISC-V MCU comes in.

The goal is simple and practical: you plug a USB-C PD charger into your board, press one button to cycle through 5V, 9V, 12V, 15V, and 20V, and watch an LED indicator show which voltage is active at any moment. CH32V003F4P6 is WCH’s ultra-low-cost 10-cent microcontroller, and despite that tiny price it provides a QingKe 32‑bit RISC‑V2A core running up to 48 MHz, which is easily enough for button handling, LED control, and pin configuration. The CH224K takes care of the heavy lifting on the PD side, negotiating USB PD 2.0 and 3.0 with your charger and switching its output accordingly. A linear regulator, such as an LM317, then drops the variable PD input—anything from 5V to 20V—to a steady 3.3V rail so the MCU stays happy regardless of which voltage you select. That mix of regulated input and smart control is what turns PD hardware into a safe DIY voltage controller.

Step-by-Step: From USB-C Selector to Smart Power Meter

Once you understand the parts, you can treat the project like two layers: the USB-C PD selector, and the smart open source power meter that watches what it does. The selector board gives you instant, adjustable voltage from a GaN or PD charger, while the meter tracks bus voltage, current, and power over time with enough detail to judge efficiency. The key is to build the simple control path first—USB-C port, CH224K, CH32V003, LEDs, and button—then hang your measurement hardware across the output. This avoids debugging a complex setup all at once and keeps the most dangerous failure mode (miswired high voltage) isolated early. When you take measurements, think like a test engineer: enter at low voltage, validate idle current and readings, then move up through the PD levels only after everything behaves the way you expect.

  1. Design and manufacture a USB-C PD selector PCB that connects a USB-C receptacle to the CH224K sink controller, routes its three configuration pins (CFG1–CFG3) to the CH32V003 RISC-V microcontroller, and includes a row of LEDs and a push-button for status and control.
  2. Wire the CH32V003’s GPIO pins to the CH224K configuration inputs, LED indicators, and the toggle button, then add a regulator such as an LM317 so the MCU always sees a stable 3.3V even when the PD source varies between 5V and 20V on the main VDD rail.
  3. Program the CH32V003 to scan the button, cycle through a table of PD voltage requests (5V, 9V, 12V, 15V, 20V), drive the CFG pins to match each requested voltage, and update the LEDs so the selected PD level is obvious at a glance when a charger is connected.
  4. Validate the selector by plugging in a USB-C PD charger, connecting a multimeter in voltage mode to the board’s output, pressing the button through each mode, and confirming the output matches the expected PD levels while a single LED turns on to indicate the active voltage.
  5. Add a smart open source power meter stage using dual current and voltage sensors, such as INA226-based channels, to measure bus voltage, current, power, and total energy, then connect those sensors to a microcontroller and a graphical display canvas for live dashboards and status views.
  6. Extend the power meter with a custom OS-like menu system that exposes apps for a main dashboard, relay control, power-unit settings, efficiency calculations, automation, a Wi-Fi portal, live power graphs, and configuration, so you can control loads and watch real-time plots of power behavior.
  7. Integrate the selector and meter by feeding the PD board’s output through the meter’s shunt and relay, then use the live sensor data—including bus voltage, current, and accumulated energy—to calculate efficiency and record traces while switching voltages and loads under different test scenarios.

The expected result is a tool that behaves more like lab equipment than a hobby board: you plug in a USB-C PD charger, press the button to cycle through 5V, 9V, 12V, 15V, and 20V, and the matching LED lights up to show the active voltage while your meter plots live traces. During bring-up, measuring idle current at low voltage before jumping straight to the charger output helps catch wiring mistakes or misconfigured pins. On the meter side, the firmware tracks sensor data fields such as bus voltage, current in amps, power in watts, and total energy in watt-hours so you can see how different devices respond when you change PD modes. One quotable design detail from the meter is that the live graph uses dual traces and a tick rate around 500 ms to keep real-time power plots responsive but readable.

Build Your Own Smart USB-C Power Controller and Meter

Inside the Smart VA Meter: Dual Sensors, Graphs, and Automation

With the PD selector working, the smart VA meter becomes the part you use every day. The design uses two INA226-based channels so you can watch both low and high current paths, each reporting bus voltage, current, and computed power. Firmware keeps running totals like g_totalEnergy_Wh so you can track energy used during a test run. A canvas-based display system draws dashboards and menus, and a theme engine can switch between dark and light modes while keeping a consistent palette of cyan, blue, yellow, pink, green, red, purple, and grey for UI elements. On top of that, a relay output gives you power switching control, combined with menu entries such as RELAY CTRL and AUTOMATION, so you can turn loads on or off and schedule behavior. Wi‑Fi support and a web server interface turn the meter into a networked open source power meter you can check from a browser.

The meter’s UI is organized as a small custom OS with named apps—DASHBOARD, POWER UNIT, EFFICIENCY, EFF RESULTS, WIFI PORTAL, LIVE GRAPH, SETTINGS, and more—each mapped to its own state in the firmware so navigation feels like using a dedicated instrument. Global variables track relay state, current measurement mode, screen brightness, buzzer volume, and sleep settings; paired with rotary encoder input and buttons, this lets you build a surprisingly rich control surface around the PD selector. According to the project’s firmware, the LIVE GRAPH app uses boolean flags to control recording and a tick-rate variable to time plot updates, while the dashboard focuses on telemetry and energy totals. By combining dual sensors, a relay, and that UI, you get not only measurements but power control, making this meter a practical partner for your DIY voltage controller.

Is It Worth It? Using and Extending Your DIY Power Controller

Once everything is assembled and tested, you have a compact setup that makes USB-C PD far more useful on the bench. Instead of hunting for a specific charger, you plug one in, tap a button to choose the voltage, and watch your open source power meter show the impact on current draw, power, and efficiency. The main gotcha is remembering that 20V PD levels can stress small circuits; always check what downstream hardware can handle, and treat the PD output more like a lab supply than a phone charger. The reward is a device you’ll keep reusing: debugging custom boards, characterizing battery chargers, or automating relay-based tests. Because the firmware exposes menus and states for live graphs, dashboards, and Wi‑Fi access, you can continue refining the meter and controller as you learn more about RISC-V microcontroller projects and power electronics.

Milik earns a commission when you shop through our links, at no extra cost to you. This article was generated with AI from published sources and product data.

Related Products

You May Also Like

Comments
Say something...
No comments yet. Be the first to share your thoughts!