ESP8266 firmware examples for driving 24 VAC sprinkler solenoids with USB-C
Power Delivery. The repository is one PlatformIO project containing four
independently buildable drive methods that share a local CH224 driver in
lib/CH224/src.
See the companion article for the circuit and an explanation of each drive method.
Prototype circuit board used for the experiments:
Circuit schematic:
Install PlatformIO Core, then run commands from this repository's top-level directory.
| Environment | Program |
|---|---|
method1_pwm |
Full-voltage activation followed by P2 low-side holding PWM |
method2_dualvoltage |
Dual-voltage drive using P2 low-side as the switch |
method3_acsynthesis |
Timer1 sine synthesis without debug output |
method4_squarewave |
Bipolar square-wave drive |
Compile one program:
pio run -e method4_squarewaveCompile every program:
pio runUpload one program to the automatically detected serial port:
pio run -e method4_squarewave -t uploadIf automatic port detection fails, specify it explicitly:
pio run -e method4_squarewave -t upload --upload-port /dev/ttyUSB0PlatformIO stores generated firmware under .pio/build/<environment>/. For
example, the Method 4 binary is .pio/build/method4_squarewave/firmware.bin.
The .pio directory is ignored by Git. Before creating a source-only ZIP, omit
that directory or remove generated builds with pio run -t clean.
Each program keeps its user-adjustable voltage, current, timing, and frequency
constants near the top of its main.cpp. PlatformIO builds the AC-synthesis
program at 160 MHz and the simpler programs at 80 MHz as required by their
source code.
Before connecting a solenoid, verify all four bridge-control signals and the polarity-reversal dead time with an isolated oscilloscope. Disconnect external VBUS while flashing unless the programming and power paths are known to be isolated.
This project is licensed under the MIT License.

