In my house (and the vast majority of others) the thermostat wiring runs at 24V AC. There's a live wire (or two, depending on the setup) coming into the thermostat, and several others leaving to control the different components of the HVAC system. The thermostat's job is to close the circuit between the live wire and the appropriate control wire based on the temperature. A relay is an easy way to do it, but I find relay's cumbersome with their (usually) breadboard unfriendly pin layout and larger-than-can-be-supplied-by-gpio switching current requirements.
I have found, in my opinion, a much better way of switching AC current: the TRIAC. If you've ever used a MOSFET for DC current switching, a TRIAC is similar in application (but not physics), only for AC current. There are some important differences, however. Probably the biggest difference is that once a TRIAC is activated, it will not deactivate until the current through it drops below some small threshold current, and I'm not talking about the gate current. Because of this the TRIAC is pretty useless for DC since once there's current flowing it will never drop (unless you have another switch somewhere, which kinda defeats the purpose, or the battery dies...). In AC, the voltage (and hence current) will go to zero twice every cycle, so shutting the thing off is not an issue. An important side effect of this is that it's impossible to switch a TRIAC faster than the frequency of the AC line it's connected to, so you can forget about using it for PWM. But you CAN control when in the cycle it turns on to control the average current flow available to whatever it's connected to, and this is exactly what light dimmer switches do.
The 3 pin device is connected in line with the wire you want to switch, and a current is applied to the gate to turn the switch on. But TRIAC's are a little more complicated than MOSFET's. If you want to switch any appreciable amount of current (I was very surprised to learn that my HVAC control lines draw nearly 1.5A at 24V AC) you probably can't switch the TRIAC directly with a gpio. You need a second, smaller TRIAC as an intermediary. But don't fret, it's a very simple circuit.
The two TRIAC's are connected together as shown in the schematic, with the smaller one connecting the live wire to the gate of the larger TRIAC. Since the smaller one is actually quite small, R2 is necessary to limit the amount of current that would rush through it once it's activated. It is also important to get the order of the AC wires correct. Just because it's AC doesn't mean the wires are interchangeable!
Getting back to the thermostat, my house has 3 control wires that I'm interested in: the blower fan, heater, and air conditioner. That means I need 3 of these TRIAC circuits. The live 24V AC wire feeds into each of them, and the control wire goes on the load side. Connect the 3 opto's to 3 gpio's on the Raspberry Pi and voila! I have control.
In my setup I've used the following components:
R1 - 560 ohm
R2 - 100 ohm
Opto-TRIAC - MOC3063
TRIAC - BT134
The two TRIAC's are pretty cheap, $1.27 for the pair at the time of purchase from Digi-key. For all three channels I came in less than $5 for everything I needed to interface with the Raspberry Pi.
If you would like all 3 channels on a PCB instead of a breadboard, check out here.
Not sure when this was posted but there's a typo. It should be voila.
ReplyDeleteAnyway, great tutorial! I feel ready to do this project now!
Thanks! Fixed now.
DeleteGreetings!
ReplyDeleteI'm trying to make a similar circuit, which controls a water heater via 230VAC. Could you tell me, how you calculated R2? The heater uses 2kWatts, which means 8,7A. I use a 12A triac, but does it matter any other way?
The value of R2 is not very critical. It's only purpose is to prevent so much current flowing through the opto-triac to burn it out. This can happen because the gate of a triac can sink (or source, depending on AC phase) a significant amount of current. Without R2 just as much current would try to flow through the gate as would through the triac, causing the opto to burn up. If you're doubling the voltage I would double R2.
DeleteThanks! Now it's working properly!
DeleteI looked at the Eagle PCB design and I see that the BT134 uses the 'nich' library? Where did you find the component for Eagle? I can't seem to find it myself in the list.
ReplyDeleteI've made my own library for parts I can't find in any of the existing Eagle libraries. I've updated the .zip file to include my library.
DeleteIt seems like the BT134 is being phased out @ digikey. It looks like T405Q-600 would be a good replacement for it. Albeit with different packaging options. Thoughts?
ReplyDeleteThe L4004D3RP seems like another viable option. Again thoughts?
DeleteTheoretically, any triac with enough current capacity should work. The two you suggested have way more than enough capacity for this application.
DeleteI'm not seeing any indication on Digi-Key of them being phased out. Was there an announcement I missed?
My mistake, I don't see it anymore. Personally, I was looking at the surface mounted versions so maybe I did a mistake there. The current capacity for T405Q-600 is actually the same as the BT134 (4A/1.3v)
DeleteThanks for sharing Raspberry pi thermostat with us.
ReplyDeleteHeating and Air Conditioning Oakville
I'm wondered how this beautiful article written. Thanks for sharing.
ReplyDeleteHeating and Air Conditioning New Market
Call takers and dispatchers should start the service agreement sales process by stating at the appropriate point, “I’m required to inform you that we give priority service and discounts to our s house furnace
ReplyDeleteGreat post, you have pointed out some excellent points, I as well believe this is a very superb website.
ReplyDeleteKalorimetre
This comment has been removed by the author.
ReplyDeleteCreate this charitable of companions you consideration about precisely what therefore grief-favored beside contemplates to most of these tows which are fact produced. Infrared repeater
ReplyDeleteVERY INFORMATIVE ARTICLE. Thanks
ReplyDeletewww.cosmopolitanmechanical.ca
Thanks very interesting. Thanks for sharing!
ReplyDelete