Need help detecting AC input with microcontroller

Thread Starter

AverageMoss

Joined Apr 24, 2021
34
Hello, I'm working on a project where I need a microcontroller to detect a couple of 24 VRMS AC inputs from a thermostat. The inputs only need to be read as high or low. It also needs to be physically as small as possible as the circuit board has to fit in a small space.

I've come up with a design but I'm not sure if it would work. It uses a feature of the microcontroller called Analog-to-Digital Converter (ADC) and 113k ohm resisters between the input source and microcontroller pins.

I'm a little new to this stuff so any feedback is greatly appreciated. Here is the schematic:

Screenshot-1.png
 

djsfantasi

Joined Apr 11, 2010
9,188
You may only need one diode to as a half-wave rectifier on the AC input. The voltage would be smaller than with a full-wave rectifier. The input voltage would be smaller (by 1/2) but could still be detected. One diode would be smaller than a bridge rectifier.
 

Thread Starter

AverageMoss

Joined Apr 24, 2021
34
what do you need to do ? to detect a couple of 24 VRMS AC what does detect mean ?
I just need to read the 24 VRMS inputs as high or low (on/off). For example, if the "G" input (pin 5 on the microcontroller) was high then that tells the microcontroller that the "fan-only mode" is selected.
 

crutschow

Joined Mar 14, 2008
34,845
Since the AC from the thermostat is isolated by its transformer, an opto coupler is not needed (at least for safety considerations).
 

Jerry-Hat-Trick

Joined Aug 31, 2022
591
113k ohm resisters between the input source and microcontroller pins.
The peak to peak voltage of 24VAC will be around 34V positive to 34V negative. Even with 113K resistors I expect you will destroy the processor A/D lines. At the very least you would need a potential divider - maybe a diode in series with a 100K reisistor in series with a 10K resistor to ground and sniff the voltage between the two resistors which will be a maximum of around 3V. The diode protects the processor from the negative voltage by appearng like a high resitance value.

Personally, wherever AC is about, I prefer to use an opto coupler to isolate ffrom the comtroller circuit. A similar potential divider (with order of magnitude lower values) will send current through the opto diode whilst protecting that diode from reverse voltage
 

Thread Starter

AverageMoss

Joined Apr 24, 2021
34
@djsfantasi @Jerry-Hat-Trick

After reading all of the replies I came up with a new temporary proof of concept design.
This is new territory for me so I don't know if something like this would work. I would appreciate it if anyone can point out everything wrong with the design. I only have the G input wired for now on purpose.

Screenshot-2.png
 

djsfantasi

Joined Apr 11, 2010
9,188
@djsfantasi @Jerry-Hat-Trick

After reading all of the replies I came up with a new temporary proof of concept design.
This is new territory for me so I don't know if something like this would work. I would appreciate it if anyone can point out everything wrong with the design. I only have the G input wired for now on purpose.

View attachment 295913
I still think you need a pull-down resistor joined to the connection between the optoisolator and the GPIO pin. Forgive the crude drawing; I hope you understand it. Use a 10kΩ resistor on each pin.

IMG_5275.jpeg
 
Last edited:

Thread Starter

AverageMoss

Joined Apr 24, 2021
34
I still think you need a pull-down resistor joined to the connection between the optoisolator and the GPIO pin. Forgive the crude drawing; I hope you understand it. Use a 10kΩ resistor on each pin.

View attachment 295915


Updated the design. I added the 10k ohm resistor as well as a 100k ohm resistor to current limit the AC input to the optocoupler. Something like this for each input (G, Y1, W1, W2, *).

Screenshot_3.png
 

Thread Starter

AverageMoss

Joined Apr 24, 2021
34
Does that work?
100K seems high, that's only .24ma to activate the opto. I would design for 10ma using a 2400 ohm series resistor.

You're absolutely right. Thank you for that!
Correct me if I'm wrong, but I think I'm at the point where I can purchase components and test them to see how this works:

Screenshot_4.png
 
Top