tomkrbp
Posts: 4
Joined: Fri Jan 10, 2020 8:12 pm

Is this the best way to sense 24VAC to GPIO Input?

Fri Jan 10, 2020 8:19 pm

I'm new to Pi and also to electronics so I'm struggling a bit with the best way to sense 24VAC from an HVAC zone controller.

Seems the consensus from the posts I've read is to use a relay or optocoupler (preferred) with either a half or full bridge rectifier. See the sketch I worked up today below:
24vac.png
24vac.png (23.87 KiB) Viewed 329 times
Is this the best way to accomplish this? Seems like there should be some sort of pre-built module available that can do this. According to the simulator with a 50u cap I'm going to have voltage flux of about 2 volts which should be fine for the optocoupler however when the 24VAC powers down it takes a tenth of a second to drain the cap. With such a long transition from high to low would I need to debounce the input in code?

Thanks!

tomkrbp
Posts: 4
Joined: Fri Jan 10, 2020 8:12 pm

Re: Is this the best way to sense 24VAC to GPIO Input?

Tue Jan 14, 2020 7:08 pm

Through some refinement I think I have this simplified to the following half wave rectifier. This should give me a very consistent 7.5 mA @ 1.2VDC across the PC817 opto-isolator. I've ordered the parts and will experiment this week to verify the design.
half wave.png
half wave.png (26.19 KiB) Viewed 311 times
If anyone is interested in viewing the simulation you can follow the link below to the design in falstad

http://falstad.com/circuit/circuitjs.ht ... 0+2+2+3%0A

drgeoff
Posts: 10109
Joined: Wed Jan 25, 2012 6:39 pm

Re: Is this the best way to sense 24VAC to GPIO Input?

Tue Jan 14, 2020 7:31 pm

Change the output side of the opto:

Emitter to RPi ground.
2k2 resistor from collector to RPI 3.3 volt.
Resistor (anything between 1k and 10k) between collector and RPi GPIO.

The GPIO input will read LOW when the 24 volts AC is present.

LTolledo
Posts: 2429
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Is this the best way to sense 24VAC to GPIO Input?

Tue Jan 14, 2020 9:09 pm

you just want to sense the presence and absence of 24vAC?
and nothing in between I assume
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

duckredbeard
Posts: 62
Joined: Mon Apr 29, 2019 1:53 am

Re: Is this the best way to sense 24VAC to GPIO Input?

Wed Jan 15, 2020 12:24 am

I think the easiest way to do this is by using a relay. The 24V would operate the relay and the pi would look for continuity through the relay's switched output. Keep that 24V away from the GPIOs!
You can't know your limits until you exceed them.

tomkrbp
Posts: 4
Joined: Fri Jan 10, 2020 8:12 pm

Re: Is this the best way to sense 24VAC to GPIO Input?

Wed Jan 15, 2020 2:17 am

drgeoff wrote:
Tue Jan 14, 2020 7:31 pm
Change the output side of the opto:

Emitter to RPi ground.
2k2 resistor from collector to RPI 3.3 volt.
Resistor (anything between 1k and 10k) between collector and RPi GPIO.

The GPIO input will read LOW when the 24 volts AC is present.
Thanks - yeah on the second drawing I abandoned the simulated opto isolator because it was not accurately simulating the voltage drop as listed on the spec sheet. I just threw in a diode that let me tweak the numbers and thus I had no way to redraw the RBP side. My first drawing was way off.

LTolledo wrote:
Tue Jan 14, 2020 9:09 pm
you just want to sense the presence and absence of 24vAC?
and nothing in between I assume
Yes - digital on or off
duckredbeard wrote:
Wed Jan 15, 2020 12:24 am
I think the easiest way to do this is by using a relay. The 24V would operate the relay and the pi would look for continuity through the relay's switched output. Keep that 24V away from the GPIOs!
At first I thought of a relay however AC relays are expensive and big and I need 4 of these 24VAC inputs monitored. I considered using a 24VDC relay but I'd have to convert from AC to DC so why not try something that isn't mechanical... Based on the signals I read I will be controlling 24 HVAC damper actuators individually with several 8-channel solid state relay modules.

LTolledo
Posts: 2429
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Is this the best way to sense 24VAC to GPIO Input?

Wed Jan 15, 2020 10:21 am

ever considered using this?
fod814_pin_kairo.jpg
fod814_pin_kairo.jpg (16.62 KiB) Viewed 231 times
Photocoupler Bipolar input FOD814A300W

you'll only need to put series resistor to the LED side ( you'll have to compute the resistance value yourself)

hmm. I think I have some here..............
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

tomkrbp
Posts: 4
Joined: Fri Jan 10, 2020 8:12 pm

Re: Is this the best way to sense 24VAC to GPIO Input?

Wed Jan 15, 2020 4:18 pm

LTolledo wrote:
Wed Jan 15, 2020 10:21 am
ever considered using this?
fod814_pin_kairo.jpg
Photocoupler Bipolar input FOD814A300W

you'll only need to put series resistor to the LED side ( you'll have to compute the resistance value yourself)

hmm. I think I have some here..............
Really? Would that actually work? I thought about that briefly while looking through the isolators but I figured I'd end up with a 60hz DC signal on the other side. The typical rise/fall time on that thing is 3 to 4 μs so surely it would be affected by the ac sine wave. I suppose that could be fixed in software but...

User avatar
rpdom
Posts: 15929
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Is this the best way to sense 24VAC to GPIO Input?

Wed Jan 15, 2020 5:08 pm

tomkrbp wrote:
Wed Jan 15, 2020 4:18 pm
I figured I'd end up with a 60hz DC signal on the other side.
You could put a smallish smoothing capacitor on the output.

User avatar
davidcoton
Posts: 4419
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Is this the best way to sense 24VAC to GPIO Input?

Wed Jan 15, 2020 10:26 pm

tomkrbp wrote:
Wed Jan 15, 2020 4:18 pm
I figured I'd end up with a 60hz DC signal on the other side.
[pedant mode] 60Hz 120Hz[/pedant mode]
Proceed as per rpdom's suggestion, effectively making an RC low pass filter. But take care that as the opto output discharges the capacitor, the cap value is not high enough to overload the opto output. Similarly, use a high enough resistor (from the 3V3 supply) so that the 3v3 line is not overloaded. Here be design dragons. :o
Signature retired

j_hof
Posts: 13
Joined: Sun Jul 24, 2016 11:58 pm

Re: Is this the best way to sense 24VAC to GPIO Input?

Thu Jan 16, 2020 1:09 pm

If you use the dual diode opto and a suitable resistor on the secondary to sense the presence of the AC voltage you don't really need the capacitor. Instead of sensing a voltage level you will get two pulses per cycle. Just sense the period between pulses. If the pulses stop there is no AC.

User avatar
davidcoton
Posts: 4419
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Is this the best way to sense 24VAC to GPIO Input?

Thu Jan 16, 2020 3:36 pm

j_hof wrote:
Thu Jan 16, 2020 1:09 pm
If you use the dual diode opto and a suitable resistor on the secondary to sense the presence of the AC voltage you don't really need the capacitor. Instead of sensing a voltage level you will get two pulses per cycle. Just sense the period between pulses. If the pulses stop there is no AC.
It's the old trade-off between h/w and s/w. In this case, IMHO, the hardware solution is simpler (and more testable) than trying to time interrupts caused by the pulse edges.
Signature retired

LTolledo
Posts: 2429
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Is this the best way to sense 24VAC to GPIO Input?

Thu Jan 16, 2020 9:37 pm

I'd go with the hardware solution recommended by davidcoton.
for the same reasons

and its "newbie friendly" ;)
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

Return to “Beginners”