PWM with a relay and heating element

I have a heating element hooked up to a relay that I can turn on and off. Issue is when it comes to boiling I’d like to control the power, I’ve read using PWM with a generous value to give the relay some chance is a good solution.

I’m using an Arduino UNO.

I have no idea how to implement this, today I have on/off and would like an additional slider for the PWM value. But can settle for just the slider so 0 is off and 100 is max power.

A thermostat where I could set the value in blynk would also be real handy but have found 0 info on it…

PWM is going to be tough to do with a relay… You should be looking into transistors and probably a transistor driver.

How about switching it off for say 10 second then on again for 10? Being able to change the values independany so only on, on for 10 seconds and off for 20…

You could probably make that work.
I’ve done something similar for controlling a heat gun or LN2 solenoid, using a solid state relay.
Basically you set a command, then calculate on/off times based on the error.
PID tuning works well for this.

I’ve done something similar with some LDR’s and automatic lights. It’s not entirely the same, but I think the same principles apply:

  1. Measure each LDR 9 times and calculate average value over a given time period (each 10s or so)
  2. Set the lights and at the same time but change the timer to a longer period (5 minutes, so the lghts won’t go flickering on and off when critical measurement is reached)
  3. Keep measuring and when lights is not needed, turn it off, and start checking every 10s again

I hope it’s a bit clear what I did. I can post the code for my entire home automation, but it’s a but lenghty (600+ lines).

Hi there Lichtsignaal, i would love to see your code. Maybe a zip file would be better? I like reading code and am always after ideas from others ways of implementation.


I’ve posted it here: Home Domotics

Better to have in a separate topic. I’ve made minor adjustments to the code since that release, but nothing world shocking, just some LED’s which display different, so knock yourself out. :wink:

Thanks, i just found it after i posted. You have structured your code very well.

Thank you very much, I like order in things. It makes it much easier to find stuff when something goes wrong. Also, when I need to search too much for things I just start from scratch. Sometimes it makes for some good ideas to clean stuff up :slight_smile: