24 volts AC to arduino input

I'm working on a project to monitor a heat pump and log when it's on and off. They way I plan to do this is to send a line from the heat pump up to a digital in on the arduino and have "if (digitalRead(pin) == HIGH), log to flash drive" running. However, the heat pump uses 24v AC and I'm using wall warts for the other bits of my project. I have a couple of questions:

1- can a wall wart (ie cell phone charger) take in 24v? on all of mine it says something like 110-240. I mostly just want it to make DC, I can make a voltage divider really easily to step it down from there.

2- I could use a rectifier, but to my understanding it doesn't make a constant voltage, it bumps up and down. I've heard of using a voltage regulator to fix this, but would a capacitor connected to ground do the same? forgive me if this is stupid, I'm somewhat new to the AC field. :-/

I'd rather use a wall wart just because I have a bunch laying around and I don't have many free diodes.

If there's another easy solution, please let me know. I'm open to any and all suggestions.

Thanks!

Until the real expert come back and help you...

1-Walmart will probably blow up
2-????? (I don't know about rectifier)
3-Plug the Heat pump with his respective power suply, separate from the Arduino.

4-I do believe the arduino Pins only take DC or it would blow up(I like that word) (the reason why you want to convert AC to DC) From my very tiny knowledge base, you should probably use an external device (detector) wired to the Arduino to register if the pump is On or OFF.

And btw, if your heat pump require AC, use AC, not DC.

I don't know how your heat pump is or work, but if I was trying to do that I would try to detect the Heat exchange using a electronic Heat sensor or something similar, but it's probably not the best way to do that and might be unreliable as you will need to do some qualibration...maybe using one sensor to detect the ambiant temperature and the other one beside your heat pump.

This sounds like you're asking two questions:

  1. 24V AC to an Arduino digital input

  2. 24V AC to provide power to the Arduino

  3. Do not put 24VAC directly to an input pin. It will fry the input. You have a few options:
    a) opto-isolator (plus a couple resistors, small diode, and a capacitor)
    b) input protection/level shifting with a diode, resistors, small capacitor, maybe also a zener diode.

I include a capacitor on both of the above because either option will give you a series of pulses when the AC is on. The a capacitor can hold the input high between the pulses, otherwise you'd randomly get a false "off" or would have to deal with that in software.

  1. No, most wall warts will not give you the voltage you need to power the Arduino with only 24VAC input. You can fairly easily build a small power supply with a bridge rectifier, a few capacitors, and a small voltage regulator. All of which are fairly inexpensive. The 24Vac may push the limits for input voltage on many small regulators though.

A voltage regulator and a capacitor are not the same. You really would want both. The output of a rectifier is either just the positive halves of the sine wave (half-wave rectifier) or the positive half and the negative half flipped over (full-wave rectifier). But both will be a series of pulses. The capacitor fills in the gaps, but not perfectly.

The voltage regulator knocks the voltage down further to the value you really want and further smooths out the imperfect output of the capacitor. Normally, you'd also have a second capacitor after the regulator to further smooth out the ripple.

Here is some info on power supply design that google turned up. You would be interested in Fig 16.

Thanks for the reply!

The heat pump is already in place and functioning, I'm just trying to leech a small amount of power out to indicate whether the pump is on or off.

You're right about not sending AC through an Arduino pin, that would not be good. :o That's why I'm converting it to DC.

As for using an external sensor, I'm just trying to step down the 24V AC to <5V DC so a digital in can read it. I'd have to use a digital pin anyway to detect the external sensor, so I don't really see the point in using an extra component? :-?

I'm trying to send 24V AC to an Arduino digital in. I have a separate power source, sorry for the confusion.

My question about the wall warts was whether the output was just a function of the input or if it was only a specific voltage. If input is 120V AC and output is 6V DC, would 60V AC yield 3V DC? if that's the case, 24V AC would yield a little over 1V DC.

I think I'm actually going to go with the rectifier + capacitors. Do I need the voltage regulator if I use a voltage divider? I guess it would protect from spikes... if there are any? Would there be?

Thanks for the link, too.

I'd have to use a digital pin anyway to detect the external sensor, so I don't really see the point in using an extra component?

Me either. I like doing simple things complicate. ::slight_smile:

Until you are experienced enough to answer your own question of methods to convert 24vac to be Arduino digital I/O compatible, might I suggest a method that is simple and safe. Just get a 24vac relay and let the heat pump power the relay coil and wire the relay contacts (one grounded, one to a input pin) to the Arduino.

Lefty

Hmm. I think I'll revise my main question: Can I use a wall wart rated for 110-240 V AC for changing 24V AC to DC?

I'd rather not get a relay just because I'd have to go out and get one. If I can use something I already have, it'd be simpler.

"Until you are experienced enough to answer your own question of methods" ;D right now the only way to get experience in this is to plug it in and hope it doesn't start smoking

I'm trying to send 24V AC to an Arduino digital in. I have a separate power source, sorry for the confusion.

As stated before, you can't do this directly. You know this.

My question about the wall warts was whether the output was just a function of the input or if it was only a specific voltage. If input is 120V AC and output is 6V DC, would 60V AC yield 3V DC? if that's the case, 24V AC would yield a little over 1V DC.

It really depends on how the wall-wart is designed; if its one of the newer switched-mode supply wall-warts, then no, it won't work. If it is a linear-regulated wall-wart, then it probably wouldn't work, either. If it is a linear un-regulated wall-wart, it may work, depending on its design.

What would be better would be to remove the transformer from such an unregulated wall-wart, then build your own step-down rectification system, then place a small regulator after that (with appropriate capacitors and such - they -are- needed). The regulator would need to be matched to the output of the transformer, so that it will work (for instance, if you were using a 7805 for the regulator, then your output of the rectification would have to be 7 volts or greater, because the 7805 has something like a 2 volt dropout, IIRC).

Something you could try, though, would be to detect voltage indirectly by a coil around one of the 24 VAC wires. Make a small coil on a form (like a soda straw or a piece of a plastic ball-point pen body), wrapping say 100-200 turns of 20-24 gauge wire around it. Laquer it up or otherwise seal it. Pass one leg of the 24 VAC line through the coil. When it is "on", the coil should generate a low voltage that you can measure. This voltage will be AC, too, so you'll want to rectify and filter it with caps, depending on its amount, you might need to rectify it, but it should be detectable - you would have to experiment with it.

I think I'm actually going to go with the rectifier + capacitors. Do I need the voltage regulator if I use a voltage divider?

If you are going to use a rectifier, try to find a 2:1 step-down transformer to place before the rectifier, so that you turn the 24 VAC into approximately 12 VAC, then into 12 VDC - then use a 7809 regulator (with appropriate caps) to regulate that down to 9 VDC, then a 7805 regulator (with caps) to take it down to 5 VDC; I would then use that to drive a small 4N26 optocoupler (put a resistor in place to limit current to the LED), and the output of the optocoupler to signal the Arduino (don't couple the grounds - this will isolate the Arduino from the AC side completely).

You want to take these steps (12 VDC->7809->7805) because if you just went with 12 VDC to a 7805, the excess voltage (7 volts) is dumped as heat from the regulator, and you would need a large heatsink to keep from frying the regulator. By doing it in stages, you don't have this heat issue.

If you wanted to spend the money, there also exist miniature switched-mode regulators to replace a 7805, that can easily take high voltages and convert them down to 5VDC (they also come in other values) - they aren't cheap, though; a 7805 replacement device costs around $15.00.

Another possibility would be to hook up a 24 VAC SPST relay in parallel with the output you want to monitor, then use the contacts of that relay to switch an input on the Arduino to ground (activate the internal pull-up first). That would be simple and fairly cheap (if you can get the relay).

:slight_smile:

Wow, cr0sh, I'm impressed with the thought behind your answer. Thanks! However, I was hoping for something much simpler, like Richard Crowley's. I do kind of like the coil idea, just for bonus cool points :sunglasses:

Richard's idea sounds well and good, but I was under the impression that under no circumstances may one send more than 5V into an arduino pin. 18V is a lot more than 5. It would make things a lot better if I was wrong on this point, though. :wink:

EDIT: re capacitors, if a circuit calls for a capacitor rated at 10V, will any cap rated at or above 10V work, as long as the capacitance is sufficient? Also, does a simple two resistor voltage divider work on AC?

Ok, so if I understand correctly now, you already have power for the Arduino and just wanted to use a wall wart as a pre-made method of converting 24VAC to 5VDC for the digital input....

As other posters have mentioned, that depends on the design of the wall wart, so without a good bit of detailed info about it, I'd have to give the easy answer: no. (Although I've done this with sensing 120VAC on/off.)

You can however build a fairly simple input circuit quite easily:

Get: any typical diode with at least 50V PIV (peak inverse voltage), a good example is 1N4001; a 5.0 V Zener diode (5.1 should be ok); small electrolytic capacitor rated at least 35V (say 10 uF), and a resistor 10Kohm to 47kohm, 1/4W. All are inexpensive and can probably find at the nearest Radio Shack (do they still have components?)

24VAC --->|----*-----/\/\/\-----*-------  Digital In
                     |                 |
                     C                Z
                      |                 |
 24VAC(gnd)----*----------------*------- Ard Gnd

Ok, pardon the horrible ascii sketch....
C = capacitor (+ pin on top)
Z = zener diode (cathode at top... arrow symbol pointing up)
-->|-- = rectifier diode (cathode at right)
--///--- = resistor

The capacitor will smooth out the pulses from the rectifier diode, and the resistor and zener diode will limit the voltage to 5VDC to the Arduino input.

Your other options are as mentioned: a relay with 24VAC rated coil, or an opto-isolator such as 1N26 or equiv.

For the opto-isolator though, you would still need a diode and two resistors at minimum, and I'd recommend a capacitor so you don't end up with a pulse train.

Whoops.... that ascii sketch didn't work out very well.... the "*" was supposed to be junctions to the vertical components.

Yes to both... a simple two resistor divider works with AC. Its output of course will still be AC. Keep in mind when you rectify AC to DC that you need to multiply the AC voltage by 1.414 to get the peak voltage.

And, yes a capacitor with higher voltage rating is fine. The voltage rating is the maximum voltage the the capacitor can withstand (see note about peak voltage above).

Richard: nice example. I just don't like to trust things like AC or high voltage directly to a pin.

okay, cool. the radioshack near my house has a limited selection of components, but more often than not I can find what I'm looking for, or a replacement, there.

I do like dilbert's sketch. I know I have a 1n4003 laying around somewhere, radioshack.com says its PIV is 200 V. as I understand it, zener diodes let current through when the reverse-biased voltage is greater than the zener diode's rating? that doesn't make sense with your explanation, though.

right. I'll see if I can get a zener diode tomorrow. incidentally, are there any products that have usually have zeners in them? I've got a bunch of old electronics that I've scrounged for parts. Also, do they say the voltage on them or do you just have to test and see?

Well, actually. Couldn't I just rectify it and put it into a voltage divider? according to my calculations... if you have to multiply it by 1.414, the AC voltage is ~34v. so, a 1k and 10k resistor would do it (or any other 1:10 ratio). is 34 volts too much to be sending through a resistor?

let's see, I'd use 1/4 watt resistors. W = VA, so 1/4 = 34A, A would have to be 1/136 (~.00735) amps or less. A digital pin is high-impedance, equivalent to about 100M ohm of resistance, so it's barely going to draw any current. I think it'll be okay, right?

Kevin:
Your understanding of Zener diode is correct. When biased in the forward direction it acts like a normal diode. When biased in the reverse direction it will conduct when the voltage reaches its rated value. This allows it to limit the voltage to the Arduino input.

For example: with 24VAC into the regular diode, the capacitor would have about 34VDC on it. (24 * 1.414) The Zener diode would conduct enough current to keep the voltage across it at 5.1 V, so there would be about 29V dropped across the resistor. If the resistor is 22kohm, that would be about 1.3mA (29V / 22kohm) through the resistor.

If you had 12VAC into the rectifier diode, then the zener would still limit the output to 5.1V, but would only have to conduct 0.55mA through the same resistor. ( 12 * 1.414 =17; 17 - 5 = 12; 12/22k = 0.55mA approximately)

Richard is correct about discharging the capacitor. You could put a resistor in parallel... say 4.7k or so. Or you could reduce the capacitor value. I probably overkilled because I didn't want to run calcs at the time. A 1uF or even 0.1uF might actually be enough.

The only reason I included it was that otherwise you'd see pulses at the Arduino input, about 8.3 mS on and about 8.3mS off. Depending on exactly when your code samples the input you might get a LOW even though the heat pump is actually on. You could also compensate for this in code. I tend to like to fix things like that in hardware, but that's just a personal choice. You could omit the capacitor, and instead have the program test the input several times... ie 10 times at 1mS intervals... if it's LOW all of the time, then the power is off; if it's HIGH on any of the samples, then the power is on. I just think the hardware solution is cleaner and the software solution slows down your program execution by having to do all the samples & timing.

I'm not sure what you might be able to scrounge one out of, but typically they're small enough that you'd only find a part number (if you're really lucky it might even be readable) then have to look it up.

oof. I think your post and my edit missed each other. if you missed it:

Well, actually. Couldn't I just rectify it and put it into a voltage divider? according to my calculations... if you have to multiply it by 1.414, the AC voltage is ~34v. so, a 1k and 10k resistor would do it (or any other 1:10 ratio). is 34 volts too much to be sending through a resistor?

let's see, I'd use 1/4 watt resistors. W = VA, so 1/4 = 34A, A would have to be 1/136 (~.00735) amps or less. A digital pin is high-impedance, equivalent to about 100M ohm of resistance, so it's barely going to draw any current. I think it'll be okay, right?

great. If I measure it with a multimeter, will it give the correct voltage? if half the time it's going to not be getting anything, will it display lower than it really is? I'm using a really great old analog voltmeter.

Thanks so much for everyone's help on this!