Single-wire 24VAC input to Arduino

Kromey:

fungus:
One of those lines is your ground.

One of those lines comes from the output of the transformer and provides 24VAC, the other connects to and drives the zone valve, which in turn does connect to ground. Doing anything in here that could disrupt or alter that 24VAC line (such as rectifying it to DC) could disrupt the proper functioning of the zone valve, which I absolutely must not do because when it's -9°F outside (not bad, actually, a warm day!) my heat must function correctly, no exceptions.

I think the best bet is an optoisolator and a diode connected across those wires. The diode makes sure the current only goes one way through the optoisolator. You'll also need a resistor in series with the diode to control the amount of current reaching the optoisolator.

The optoisolator output will pulse at whatever the AC frequency is but that's not really a problem for detecting whether it's on/off or not. You could always put in a capacitor to filter it.

Kromey:
Thank you, that makes sense. I think, anyway -- not really sure how a magnetic field that is created by an electrical current can continue to exist and then create an electrical current itself when the current that created it cuts out, but then again most of what electricity does doesn't make sense to me. :stuck_out_tongue:

Well, if you think about it, inductors (coils!) impede changes in current. They do this by generating electromagnetic fields. So, obviously, there is some ability to store energy as a magnetic field beyond the immediate current capacity. It starts getting into physics at that point, and that's not my strength... :wink: Someone else will have to explain that further. (Or possibly correct my layman's attempt.)

Kromey:
Is there a way to calculate how much of a spike a given coil might produce? A rule of thumb? Or is this pretty much all guesswork?

Well of course there is! 8) Google returned this as a top result:

Another way to visual it is fully turning on a faucet and turning it off rapidly. You get what they call 'water hammer'. That's the water rushing through the pipe and inertia producing a force that briefly exceeds the nominal water pressure.

The water hammer analogy actually makes a ridiculous amount of sense, thanks John!

...Although water as the go-to analogy for electricity doesn't really work. For example, if I have a 12V wire and then I split it into two, I have 12V on both. Whereas if I have a 12GPM pipe and split it into two, I have two pipes that together add up to 12GPM. This does of course hold up when talking about current in the system, but water doesn't really have any analogous properties to voltage.

Anyway, I don't really understand all the math behind that seemingly-simple equation, but I'm reading up on it and crashing headlong into the physics of this stuff along the way -- really I just want to be able to figure out how to adequately protect my more sensitive components (Arduino now, eventually raw AVR microcontrollers) when I'm using inductive loads like coils and motors. I'm getting there, though...

If I were using a transistor to drive the relay, rather than the Arduino's input pin being on the same line directly, does that in and of itself provide enough protection? Or is there still the risk of that spike "crashing through" the transistor and down the base lead?

You do NOT need a 1000V diode. The diode only needs to withstand the driving voltage. When the contacts open and the circuit is interrupted, the diode is forward biased and only sees its own forward bias voltage.

The maximum current will be exactly what the relay draws when the switch is opened, no more. Then it decays rapidly.

It doesn't have to be a shottkey diode, but it is useful for it to be a fast switching diode. I don't think they make diodes with a PIV rating low enough to be in danger in this circuit. Pick one with a current rating of at least 2x the relay current.

And you absolutely need a diode across a coil with a driver transistor. Without a diode, the voltage spike can easily reach 1kV, destroying the transistor.

Kromey:
...Although water as the go-to analogy for electricity doesn't really work. For example, if I have a 12V wire and then I split it into two, I have 12V on both. Whereas if I have a 12GPM pipe and split it into two, I have two pipes that together add up to 12GPM.

That isn't so far off from voltage. I always imagine voltage as water pressure, and current as volume. Given the same amount of water, if you make the pipe bigger (more current flow), the pressure goes down (lower voltage). This frequently happens with electricity too. It's called load drop. The voltage regulator can compensate for this, just as a water pressure regulator could -- up to the point where more voltage/pressure doesn't exist at the source.

Kromey:
If I were using a transistor to drive the relay, rather than the Arduino's input pin being on the same line directly, does that in and of itself provide enough protection? Or is there still the risk of that spike "crashing through" the transistor and down the base lead?

Yes, you still need a diode. Afterall, the output pin of the AVR is just a pair of transistors.... :slight_smile:

polymorph:
You do NOT need a 1000V diode. The diode only needs to withstand the driving voltage. When the contacts open and the circuit is interrupted, the diode is forward biased and only sees its own forward bias voltage.

While I am willing to be wrong here (in fact, it would make life easier!), isn't the voltage rating of a diode relevant to the reverse bias? In fact, the Digikey sort heading is: "Voltage - DC Reverse (Vr) (Max)" If you spec the diode for 5vDC and it receives a reverse 100v spike, are you telling me that wouldn't cause damage to the diode? Then, frankly, why is the diode necessary at all? Couldn't the transistor indeed cope alone?

I don't argue that 1000v is probably excessive, I admitted to that myself above. It's just that 1000v ratings are not hard to come by, and it nearly completely eliminates any cause for concern or need to calculate margins. You can slap a cheap 1000v diode in there and worry not. If the spike exceeds 1kV, you have bigger problems. All IMHO, of course.

Also, I'm not entirely sure if you're referring to the diode in series with the I/O pin to the relay coil, or the one across the coil. One will experience a high reverse bias voltage, the other will see a high voltage that could be of either or both polarities.

polymorph:
The maximum current will be exactly what the relay draws when the switch is opened, no more. Then it decays rapidly.

When did we start talking about current? I agree, current demand will be low. Usually tens of mA.

So I've gone ahead and worked up a schematic for my thermostat monitor, based pretty much entirely on the one SirNickity drew up. First time using Eagle, and I didn't spend a lot of time trying to find the exact right components/symbols to use, so consider this largely illustrative rather than an exact representation; about the only specific component on here that matches what I intend to use is the two 1N4148 diodes, simply because that's what I have on hand and it seems they'll be sufficient (especially as they were provided in the kit specifically to offer protection when using a relay, and in fact a relay that more than meets my needs here and is likely what I'll end up using).

I added an LED so that I have a nice visual indicator to show when the thermostat is on; I intend to have a second one controlled via software that will be turned on when the Arduino logs that the thermostat is running, and turned off when it logs that it isn't. Since I intend to poll every ~30 seconds, there will be some delay, but it should still give an adequate and quick visual cue that things are/aren't working properly. Also not shown is the el cheapo temperature sensor that will be being logged alongside everything else.

If anything here looks stupid or dangerous, please shout! I hope to whip this thing up this weekend and be logging data through next week.

thermostat_monitor_schematic.png

The LED part is wrong. You'll need a separate 220R (or so) resistor driving the LED straight to ground. Put that in parallel to the 1K resistor going to the digital in.

Digital ins are high impedance and won't draw enough current to light your LED.

Otherwise, I think you're good to go!

SirNickity:
Digital ins are high impedance and won't draw enough current to light your LED.

But isn't that how Charlieplexing with an Arduino works? By switching digital IO pins to input to draw current across the correct LEDs and light them?

Obviously not the highest-quality source, but this page seems to think it'll work (admittedly not the exact setup I've drawn out here, but seems to be the same principle).

...Er, okay, looking at that again, it seems it's actually digital output set to low used for "ground" in Charlieplexing. So I could switch that pin to input, read state, then switch to output with state low to almost-instantly re-light the LED. Or I could just put it and a separate resistor in parallel as you suggest, probably best as it means a) I can adjust the resistor to get the brightness I want without affecting my ability to read state, and b) no need for silly software tricks when a dead-simple hardware tweak is all that's necessary.

Thanks for pointing out my error!

Yeah, I'd go for option B.

BTW, the 1K resistor is there to limit the current of any potential faults, spikes, or static discharge. There are internal protection diodes that shunt excess voltage to the PSU rails (+5 and Gnd, depending on the polarity of the excess voltage), but they can't take much current. The 1K tries to minimize potential damage. Otherwise, the input receiver is already high impedance and so adding 1K has negligible effect under normal conditions.

For an output pin, 1K is quite a bit of resistance for an LED current limiter. It'll still light, but as you say, you can tweak its current draw by picking a suitable resistor.

I mentioned current because small signal diodes are being specified, rated for 100mA. What current does the relay require?

With a diode across the relay coil, where in the cycle do you think high voltage spikes will occur?

Ignoring D1: The contacts close, 5V (BTW, mistake in the schematic puts a ground symbol at "+5V") appears across the relay and across D2, reverse biasing it to 5V. Being an inductor, current rises asymptotically to the relay design current.

Contacts open, the magnetic field collapsing causes the relay coil current to continue to flow, initially at the same current as the one that created the field. Since the coil is now the source of current, polarity reverses. The diode D2 is now forward biased and so goes into conduction at about 600mV. Current dies down asymptotically to zero.

D1 is unnecessary because if D2 were to fail, the voltage spike is -negative- and so it would forward bias D1 anyway.

Having a fast switching diode is important, more so than diode forward bias voltage. When D2 is forward biased, any delay in the diode turning on translates to a rising negative voltage spike.

Any bounce that might happen would have to be due to parasitic capacitance resonating with the coil inductance. However, the resistance of a relay coil is relatively high, and the parasitic capacitance is very low. So very little energy gets stored, and there is a lot of resistance to absorb it.

http://www.4qdtec.com/catch.html

polymorph:
(BTW, mistake in the schematic puts a ground symbol at "+5V")

You know, I thought that symbol was ground, but it's what Eagle offered as one of (absurdly many) options for "+5V" (most of which were variations on this same symbol), so I went with it.

If I understand the rest of your post correctly, your assertion is that the flyback diode D2 is in and of itself sufficient to eliminate (or at least sufficiently mitigate it to the point of removing the risk) the inductive kickback and protect my Arduino?

As for the current, that's something I should measure, or at the very least check the datasheet for the relay I'm going to use; don't have the part numbers of the two different relays I have on hand at the moment, though.

polymorph:
With a diode across the relay coil, where in the cycle do you think high voltage spikes will occur?

(etc.)

4QD-TEC Electronics Archive

Thanks for the follow-up and reference. I'll check it out and look into this some more. I've been dragging along conventional wisdom and throwing cheap parts at it, and after a casual glance, it seems it may indeed have been unwarranted. Never hurts to learn something new. Cheers!

This is probably overkill, but it's not too expensive and you can stick it inline with your wire:

This little board (or something like it) looks handy enough to have a few in my toolbox for who knows what.

Though maybe it's not quite sensitive enough for you to identify the low amperage that the thermostat wire would carry, but the example code seems to show some pretty decent resolution.

I'm not saying that a 1000V diode is a -bad- thing. But using a fast diode is more important.