Hacker News new | ask | show | jobs
by jareklupinski 1226 days ago
I'm not sure I would use PWM to control the flow of power to an AC appliance. That's more of a technique for getting analog approximations from digital sources.

If the purpose is to make a temperature-controlled water heater, you would probably be alright with just using that regular relay and switching power on/off to the element every few seconds. It takes a while for electricity to heat up water, and with some hysteresis / a PID loop you will get very accurate results, even switching once every five seconds.

2 comments

Thanks (and thanks to petre down below). The Arduino PID libraries I found want to use PWM, but part of the appeal of the project was understanding PID in the first place, so perhaps I could adapt it to something like a 0.1Hz modulation rate and see where that gets me.

I assume it's hard to do proper AC PWM if you don't know when the AC sine wave's phase starts, preventing you from maintaining a consistent pulse amplitude over time. But I was hoping that something simple like a resistive heater wouldn't be too fussy about it.

And then there's the small matter of my home being constructed from flammable materials....

You can do PID using a discrete output instead of analog/PWM. It's a common use case. I think I've seen an Arduino library that allows for this. Or, you can use whatever library you're already using and convert the PWM value to OFF or ON. Slow down the loop so you don't get a lot of chatter on the output; add hysteresis if necessary.

If you actually want to do AC "PWM" (it's not really PWM), use a triac as suggested by another poster, and make sure it does zero crossing detection.

One could definitely use PWM on AC with a triac.

For the water heater he doesn't need PWM, Tasmota has a thermostat mode with hybrid PID control. There's Sonoff TH2 device that can do that. Dunno what temperatures does sous vide use but it can be definitely done with a Pt1000 or a thermocouple if not the regular digital sensors.