# Circuit to convert 24VAC digital signal to 5V DC digital signal

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.

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.

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.

• 24VAC is on and 0VAC is off - how can this work? 24VAC is crossing the zero periodically. Are you going to take some time window to get "on" or "off" state (like an integrator?) I don't see anything like this in your designs – Eugene Sh. Jan 10 at 19:05
• The 24VAC was intended to be driving an AC device with 24VAC turns the device on and 0AC turns the device off. Now a part of this needs to bypassed and some logic needs to be done on an MCU. So in the first design I use a half wave rectifier with a capacitor and NPN transistor to convert the signal to be ON/OFF based the presence of the 24VAC. – Amr K. Aly Jan 10 at 19:12
• Can you afford an optocoupler? – pipe Jan 10 at 19:13
• In the second case it will generate a DC square wave with 60/50 HZ frequency which will be accounted for in code. 5V--> LOW 5V 60HZ Square wave --> High – Amr K. Aly Jan 10 at 19:13
• Sounds like a 60 Hz detector. How long of a time can you afford to wait for an active HI to arrive once the 60 Hz is present? How long of a time can you afford to wait for an active LO to arrive once the 60 Hz is no longer present? – jonk Jan 10 at 19:15

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

Similarly in the second scheme R1 is redundant.

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.

• This design was considered however since there will be a lot of inputs in the circuit using optocouplers on every single one of them would significantly increase the cost of the board. – Amr K. Aly Jan 10 at 20:05
• There is no price specification in your question. EL814 series AC opto-isolator is \$0.12 on Digikey (but for large quantities). Check around for alternate prices or alternate "AC opto-isolator". – Transistor Jan 10 at 22:59

Industrial environments can be harsh from an electrical point of view. If the 24VAC isn't close to the input, the signal can pick up noise and transients, also possible differences in ground potentials, all of which which can cause bad readings or even damage the input. For these reasons, galvanic isolation is often used.

Having said that, for lowest cost, look into using a basic resistor divider with a couple of diodes to clamp to +5V and ground. I would add a small capacitor to reduce noise and help out with transients and ESD.

Functionally, there isn't much difference between the two circuits, except that the first would be better at sourcing current, the second better at sinking current. But since there's a 10k resistor in series with the output, this probably isn't a concern

• Could you elaborate more on the last part "By the way, the first design above probably isn't working the way you think it is. Both B-E and B-C junctions are forward biased; you could replace the 3904 with a pair of diodes and get the same operation" – Amr K. Aly Jan 10 at 20:04
• The circuit is intended to put the transistor in saturation region when it detects 24VAC and Cutoff region otherwise. – Amr K. Aly Jan 10 at 20:15
• @AmrK.Aly - Never mind, I should have checked the numbers.. Will edit – user28910 Jan 10 at 20:15
• Thank you! So my question is there an advantage for design over the other ? – Amr K. Aly Jan 10 at 20:22
• @AmrK.Aly - Not much difference between the two, see edit – user28910 Jan 10 at 21:01

Assuming a $$\5\:\text{V}\$$ DC supply rail and assuming that a broad approach is satisfactory, then something like this might be okay:

simulate this circuit – Schematic created using CircuitLab

It's mostly just a AC high pass filter and resistive divider ($$\C_1\$$, $$\R_1\$$, and $$\R_2\$$), followed by $$\D_1\$$ to protect $$\Q_1\$$'s base-emitter junction from reverse voltages, followed by a 2-BJT shaper ($$\Q_1\$$, $$\Q_2\$$, $$\R_3\$$, and $$\R_4\$$), followed by a simple RC lowpass filter/integrator ($$\R_5\$$ and $$\C_2\$$), followed by a simple saturated switch that normally is OFF unless there is a sufficient number of low-going pulses at the collector of $$\Q_1\$$ to pull down the voltage on $$\C_2\$$. When $$\Q_3\$$ is active, it pulls the output high. Otherwise, $$\R_8\$$ pulls the output low.

I've no idea what your source impedance is, but the values of $$\R_1\$$ and $$\C_1\$$ can be adjusted per need there.

The design is more "slapped together" than it is carefully crafted, because I have no idea if this achieves any of your goals. If the broad strokes are okay, then fine... more could be done to craft it better. If not, then at least this provides enough for you to clearly say so.

So, I finally got around to drawing up a simple circuit using a bridge rectifier.

As mentioned in the comments, there are SMD bridge rectifiers for low current available for about the price of a single transistor. I can order a bridge rectifier that costs less than a 2N3904 from the same supplier.

The blue section represents whatever is generating the 24VAC.

The red section represents the microprocessor input, with clamp diode to 5V and 100 kOhm as the input impedance.

The AC-detector is really just the three resistors, the rectifier bridge, and the capacitor.

The three resistors reduce the 24VAC to something that will be a little over 5V when rectified.

They also limit the current that can reach your processor in case you get more than you expected on your 24VAC.

This is the simulation:

You can't see it, but the current through the clamp is less than 1mA (red line across the bottom.) So, probably safe enough to let the clamp diodes on the processor's input handle it. If not, a schottky diode is pretty cheap.

The voltage builds up a little slowly. That's about 75 milliseconds before it hits 5V. Ought to be fast enough, though. The decay when the 24VAC disappears ought to be similar.

That's a cheap, dead simple AC detector that offers at least some protection against over voltage.

Probably as cheap as if not cheaper than the transistor based circuits.