Using PID on an Arduino to control an electric heater


Trusty old oil-fin heater





The HeaterMate (image from HeaterMate website)
The HeaterMate (image from HeaterMate website)




Anyway, onto the implementation.









  • Add a few buttons to the controller
  • Add timer functionality (because why not)
  • It could control multiple heaters in a zone



12 thoughts on “Using PID on an Arduino to control an electric heater”

      1. Wire.h is an Arduino library for communicating with I2C devices (a common 2-wire protocol). I2C is used in this project for talking to the display, so I think the Wire library is there as a dependency of the display library.


  1. Thanks for this post, I implemented control of our nursery oil fin heater using openhab and a sonoff TH16 (which has a temperature sensor) and had the exact same problem with overshoot. I’m not using hysteresis though, rather just setting minimum on and off times to prevent flapping. This means that once the room settles close to setpoint (after initial overshoot) it stays relatively close with a minimum on time of 60 seconds and off time of 5 mins (effectively minimum duty cycle of 20%, if it’s going to turn on at all).

    I was just thinking about implementing a duty cycle with PID as a better option to compensate for the residual heating. I take your point about destruction of relay though… Currently I’m using the 16A relay in the sonoff to control a 1kW heater, so there’s plenty of headroom there. I guess I’ll come back to post if implementing this kills my sonoff. An SSR would be a neater option, though would require heatsinking etc and I really want to apply a slightly higher threshold of known safety in the nursery than my average projects…

    Of course as summer sets in (also in NZ!) I might have to start thinking about solutions to cool the nursery at night instead…


    1. Hi, I like the details of this project especially going from problem to solution, giving the pitfalls you have encountered. I use SSR units at work and they are very reliable but have one flaw , they nearly always fail in the on position and continue to heat. Because of this a second relay or control circuit to factor this in is essential. You could have an overheat sensor or something that cuts the power to the ssr. This is just information don’t take it as any form of negative. I am impressed with your solution. I am looking at the NodeMcu which is for controlling things via wifi.


  2. With those PI values, how long does it take to ” settle in” on startup?
    I’m doing something vaguely similar and I get serious oscillation (due to the integral term) before settling in.

    I guess it’s serious oscillation in the output, not on the input, so you wouldn’t even notice unless you were watching, so maybe it doesn’t matter…


    1. Hi Rick,

      On first startup, we get a slightly annoying spike of a degree or two, as the integral term reaches 100% before the setpoint is reached, then takes a while to come back down again.

      I have not timed how long this phase lasts but I would guess an hour or so. I think it could be solved with better tuning.

      Once it’s up to temperature, there is no discernable oscillation in the room temperature. However, I have desired to but never got around to measuring and graphing the oscillation in actual output.

      The startup phase was not a great concern to me as for us the intended purpose was to leave it on for extended periods of time. It also does not occur if the room starts off above the setpoint, and then gradually drops (e.g. You turn it on before the room starts getting cold). It only happens if the room is significantly below the setpoint when the unit is turned on.


Leave a Reply


You are commenting using your account. Log Out /  Change )

Google photo


Twitter picture


Facebook photo


Connecting to %s