# How to sense 24V AC (Thermostat) with a 5V Microcontroller

I'd like to detect thermostat events (heat, fan, ac etc) with an Arduino. I've done quite a bit of investigation but haven't found a definitive solution. Most projects I see involve controlling the thermostat however I simply want to detect on/off events.

Based on what I've gathered so far, I'd like to use an optocoupler to protect the furnace/thermostat from damage -- protecting the Arduino is important but of lesser concern. I plan to run a separate wire (cat5) from the thermostat to my project so I don't mess with the furnace wiring.

This is the optocoupler I've seen recommended http://www.digikey.com/product-detail/en/HCPL3700/HCPL3700-ND/401373 via this howto https://www.adafruit.com/blog/2012/10/04/ask-an-educator-how-can-i-measure-ac-voltage-with-my-arduino/

But where I'm confused is how to wire it altogether and what values to select for resistance.

Here's the circuit in HCPL3700 datasheet

• Note that that is a test circuit. In actual use, you would connect the AC inpupt only to pins 1 and 4, with no connection to pins 2 and 3. The ground connection between pin 4 and 5 should also be omitted - otherwise you bypass the optical isolation. – Peter Bennett Jan 11 '14 at 20:30
• Ok, good to know. I'm not sure what value to choose for the resistor between 5V and Vo. Also that cap across Vo and GND. On the AC side would the thermostat pin go in pin 1, then GND pin 4. I'm guessing a current limiting resistor is needed too? – Andrew Jan 12 '14 at 0:34
• High gain transistor input (isolated) could be used. – Ranger1 Jan 12 '14 at 21:49

The same section of the application note provides the calculations for determining Rx and thus the values of the two resistors on the input side, Rx/2 each, based on the desired trigger threshold (see Example 2). A graph to directly obtain Rx values is provided in Figure 7.
For monitoring a 24V AC line and with some margin for low voltage conditions, referring to Figure 7 and considering high and low thresholds of around 25 and 15 Volts yields Rx = 20k: use 10 kOhms 2 Watts resistors to be on the safe side, one on each leg i.e. pin 1 and 4.