Electronic – Circuit to convert 24VAC digital signal to 5V DC digital signal

circuit-designdesignmicrocontrollertransistors

I am designing a circuit to convert 24VAC signal to 5V DC signal.
The 24VAC signal is designed where 24VAC is on and 0VAC is off. The signal needs to be fed to an MCU which is 5V DC.

The circuit designed has to be very cheap so more expensive ICs and full wave rectifiers are not options.

There are two designs that I came up with

The first design outputs a 5V DC signal for high and about 0VDC for LOW.
enter image description here

The second design eliminates the capacitor but outputs a 5VDC for low and 5VDC square wave for high which will be accounted for in code.
enter image description here

I would like to know if there is an advantage for one over the other considering that the circuit needs to be as cheap and safe as possible since it will be used in an industrial environment and will be heavily affected by dust, debris, and humidity.

Best Answer

enter image description here

Figure 1. R4 is redundant as R1, R3, Q1 and R2 shunt it.

Similarly in the second scheme R1 is redundant.

schematic

simulate this circuit – Schematic created using CircuitLab

Figure 2. Solution with component count of 2.

If you use a bi-directional opto-isolator and series resistor you can cut the component count to two. The opto-isolator output transistor will pull low every half-cycle if you use the MCU internal pull-up resistor. Your software will need a timer to check that AC has been lost for 10 ms or so before determining that AC is off.

I have written more on opto-isolators here.