24 V AC Input Interface

hippy

Ex-Staff (retired)
Depends what you mean by "valid". Most opto-coupler circuits I've seen have had the opto low-side rather than high-side. There should probably be a current limiting R in series with the AC signal.

However it's wired, with an AC input the signal LED will be on for one half of the cycle and not the other. If it's an opto with two LED's back-to-back and reversed, there will still be a brief off-period as the AC crosses through 0V. A capacitor on the opto output line may be enough to overcome that.

Depending on what the 24 VAC signal is referenced to ( eg, PICAXE 0V ) it may be possible to connect it directly to a PICAXE input pin with a suitable current limiting resistor.
 

pilko

Senior Member
Hippy,Thanks for the quick response.When you said I can apply 24V AC to the picaxe through a current limiting resistor,did you mean to rectify and filter first?
 

Andrew Cowan

Senior Member
No. With a suitable current limiting resistor, you can apply the raw 24VAC to the PICAXE pin.

That is basically how the download circuit copes with 12V/-12V.

A
 

jglenn

Senior Member
That looks scary. If you don't use an opto, at least have, besides the input
resistor, a grounded diode to clamp it, I would just use a 5V zener, the anode
goes to ground, the cathode to your input resistor and picaxe input. This limits the input to the chip to -.5-5V, a little more sane. Depending on the clamp
diodes in the chip will get you in trouble.

You can also add a cap across the zener to eliminate the pulsing with the 60HZ input, a 1uF might be good.
 
Last edited:

pilko

Senior Member
jglen--won't your suggestion still produce a series of 0's and 1's. I just want to input a 1 when the switch is closed.
 

SilentScreamer

Senior Member
Diode in series to half wave rectify it, then add a cap and resistor to keep it high (when relevant) and at a safe level. Surely that is simpler?
 

jglenn

Senior Member
Either way will work, but the 5V zener also protects against transients on the
line. The mains can sometimes inject lightning into your circuit!

What do you mean by 0's and 1's? If you have a decent time constant on
the input RC filter, it will stay high as long as 60HZ ac is present. Only with
a fast response will you see the transitions. You can actually detect the edge
if you want, zero crossing detector.
 

BCJKiwi

Senior Member
@ Pilko
The first circuit posted is fine PROVIDED the correct optoisolator is selected - this would conform to the caveats that Hippy outlined in his post.

Posts 4 and 5 are OK too PROVIDED the correct quality resistor is selected but look here http://www.picaxeforum.co.uk/showthread.php?t=11696&highlight=230V post #12 then post#23 and following for discussion on AC supply to PICAXE ports. Have a look at the Microchip App Note referenced there as well.
 
Last edited:

BeanieBots

Moderator
Your originally posted diagram (with LED series resistor) will produce the same "series of 1's and 0's" as any of the other suggestions.
Fitting a suitably sized (~100nF) to the PICAXE input of your diagram will smooth it out to a "1" when 24V ac is present.
The other suggested circuits all require a diode + cap to do the rectification/smoothing. The transistor in the opto does the rectification for you but still requires a cap.
 

Dippy

Moderator
pilko, check the performance of optos to see what BB means. i.e. how things perform wrt input voltage. LEDS are not little light bulbs.

Jglenn can you explain the position and purpose of zener as I don't follow (it's early in the morning here). A bidirectional arrangement of LEDs naturally limits LED Vr - or have I misunderstood your idea? Where does it say this 24V is mains? Where will these large transients come from?

BB's idea of smoothing cap on output is slickest solution, however did you want a superfast response time?
 

Dippy

Moderator
Hang on.
Image 1 shows via optocoupler.
Image 2 shows directly into PICAXE with neutral from Mains? Yuk. Pop probably.

What optocoupler are you using?
What is the max LED If for that optocoupler?
Have you read the Data Sheet?
You will get zero to PICAXE as the voltage approaches zero 'give or take'.
The value of 'give or take' depends on the opto and limiting resistor chosen.
For DC the res would be (Vsupply - Vf)/ Imax for min res.
For AC it would be prudent/safer to use Vpeak-Vf/Imax - is the '24V AC' the RMS figure?
personally I would run it well below Imax.

You need to read the Data Sheet for the opto and give us some figures.
 

pilko

Senior Member
Forgeting the opto option for the moment. The 24V AC is RMS. What is Imax and Imin to maintain an input of 1 ?
 

Dippy

Moderator
Pilko,

without care (and someone doing the design for you) a 'direct' connection could end in an 'early bath'.

Forget all this Imin an Imax for a moment, you have to consider voltages first.

Assuming you are connecting Neutral to the PICAXE GND/0V , the AC voltage will go pos and neg wrt to GND/0V.

Your average Input Pin can only withstand -0.3V to (VDD + 0.3V).
(This is where you have to look at PIC Data Sheets (Electrical Specifications) rather than the Rev-Ed general summaries.)

Your circuit as posted will be applying +/- 34V ish peak to PIC I/O pin. Result: (probably) Goodbye PICAXE.

If you are OK with sensing every other cycle then a diode plus pot/divider could be a solution.
Or use a bridge with the -ve out connected to PICAXE GND/0V instead of Neutral.
Then after either of the above add your 'smoothing' capacitor - the latter being just like a simple AC/DC unreg power supply circuit with a potential divider to get (peak) volts down below your PICAXE +Vsupply Vdd).

Note: if you want a real fast response then this isn't the best way to do it. But that would require extra work. If you wish to sense pos & neg phase separately this is not the way to do it, though it isn't difficult.

Your best bet to start with is to produce a rectifier circuit (full or halfwave) with pot/div and smoothing cap, but NOT connected to PICAXE. The measure the output with a DMM to see if you have got it about right. A 'scope would be better.

What is your level of experience with PICAXE/electronics/coding?
 

stocky6409

Senior Member
I regularly use a HCPL0370 series opto for intefacing 24vac output from irrigation systems into multi channel radio systems for "cable replacement" application in vineyards - also work nicely with PICAXE :)

ONE resistor sets switching threshold and can be used for mains WITH ALL CARE AND SAFETY CONSIDERATIONS - ie we use then to detect 240vac output from gensets or to tell if a contactor has switched.

FYI - these are a LOGIC OUTPUT type opto
 
Last edited:

BCJKiwi

Senior Member
Dippy,
Have a read of this as referenced in post #10 above
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011013

In the Microchip Appnote 110V AC is applied via a current limit R directly to the PIC input.

Pilko,
Microchip give the detail of how they calculated the R value. In the case of the Appnote's 110VAC and the related peak they came up with 5Megohm and 32uA. Obviously less is required for 24V.
This is a sensing port right - you're not trying to power the chip from this are you?
 
Last edited:

Dippy

Moderator
Thanks BCJ.

I had seen that one before. I only said 'probably' because experienced users could do it and newbies could make a mistake and pop it. I was just playing safe as I never know what experience people have.

Anyway, that Data Sheet plus a calculator should providethe answer. I'll leave you to it.
 

hippy

Ex-Staff (retired)
The opto is the safest way, it doesn't matter what the two AC lines connect to as the two systems are completely isolated.

When using a direct connection one has to know what the AC lines actually connect to and what else is connected to the PICAXE and circuit. Not knowing that can lead to loud bangs, smoke, and far worse.

The Microchip App Note primarily, IMO, shows that current limiting is possible and only that is required to interface a high voltage to a PICmicro / PICAXE. Beyond that, actual use with mains or mains derived signals is a different matter. It requires other factors ( as mentioned ) to be taken into account and I'd only recommend using that aspect of the App Note with full knowledge of what is being done and under caution.

The App Note assumes you know what you are doing and isn't guidance for people who do not.
 

pilko

Senior Member
Thanks everyone. I am an oldbie at electronics,but a newbie at PIC's. To play safe i'll go with the photocoupler. I will be using PS2505-4's (quad photocouplers) I'll select R1 and C1 to give a min of 2 Volts input at zero cross of the AC
 

Attachments

lbenson

Senior Member
As it happens, I'm also in Nova Scotia at present (where are you, pilko--I'm in Milton, outside of Liverpool), and am also looking to determine when a 24V AC line is carrying current (because the thermostat zone relay for the furnace is on and calling for heat).

To be specific, would the LTV-814 optocoupler be suitable (datasheet here: http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=160-1344-5-ND and $.25US at Jameco)?

The "Test circuit for response time" from the datasheet is here:


Assuming that the switch shown in pilko's diagram is the thermostat relay and BB's 100nf cap is on the output (to picaxe 0V), should this show a high signal when the 24V AC is present (or is the output inverted)?

To try to be more complete, would this circuit be right, with the value of R(D) to be determined?

 

pilko

Senior Member
Hi Ibenson I live in New Germany.

In my circuit, when the stat closes, the transistor turns on and the input goes high.

In your circuit, when the stat is closed, the transistor turns on and the input goes low.
 

jglenn

Senior Member
benson, you have an error on the left. The opto input is shorted by a line,
it will get no voltage.

Sensing current is different than voltage. You need a shunt, or series resistor.
Imagine a 1 ohm in series with the xfmr and switch and load. You need to know the current the load draws, and figure out the voltage drop across the
1 ohm.

If this is not enough voltage to turn on a LED (2V), then make the one ohm
bigger. Watch the power rating (derate 50%). It is always a good idea to
use a current limit R in series with the LED, at least 10 ohm.
 

pilko

Senior Member
I assumed (may be I shouldn't),that when benson mentioned "sensing current" when thermostat closed , really only meant "detect when the cold side of the stat becomes hot" ie voltage on the cold side.
 

lbenson

Senior Member
jglenn--I admit I have trouble understanding how the connection to the optocoupler should work to sense the presence of current on an AC line (24 volt).

The left part of the circuit represents the current circuit--two wires connected to the thermostat (if they are shorted, then the furnace comes on--as it does if the called-for temperature is pushed up above ambient).
Code:
   | (thermostat relay)
  ---
--o o--.A
       |
       |
-------'B
I had thought that the optocoupler, with R, could be connected in parallel at A and B--is this incorrect? I'm not trying to measure the amount of current--just whether it is present (which means that the thermostat relay is closed).
 

jglenn

Senior Member
Between A and B you need a shunt resistor that develops a voltage across
it from the current flowing thru it, which is driving your valve solenoid. You need
to get a value for that current. This voltage has to be more than 2V to turn on
the opto.

Pilko: voltage sensing of the thermostat is another way, a bit simpler, if you
can get a wire on it.
 

jglenn

Senior Member
Here are some free calc. Assuming your valve is 7.5W, which may be close.

P=IE

I=P/E=7.5W/24V=.31A valve current

With my dumb suggested 1 ohm shunt:

E=IR=.31A x 1 ohm=.31V, not even close to turning on the opto.

SO......:cool:

R=E/I=3V/.31A=10 ohms, your shunt value, gives a healthy 3V when valve is on.

Now calculate a series R for your led that will take up 1V at 15mA.

Of course I used average ac voltage levels. U mite want to look at
the peak voltage for extra credit. :confused:
 

jglenn

Senior Member
OOPs, nasa we have a problem.

P=IsquaredR in the shunt=.31 x .31 x 10 = .96W, so U

better make the shunt a 2W resistor.

This is how you do it.
 

pilko

Senior Member
jglen--you don't need to monitor current, just monitor for 24V ac on the cold side of the thermostat contact (the side that only becomes hot when the stat closes). That is industrial control protocol.
 

Dippy

Moderator
I think IB and JG were just giving you an option , but yes you are right if you just want to check the stat has statted. I'd go for the non-current sensing approach personally.

"In my circuit, when the stat closes, the transistor turns on and the input goes high.

In your circuit, when the stat is closed, the transistor turns on and the input goes low."


- does this matter?

Either contingency can be coded for and the emitter to ground is the usual (best) way of connection.

Have you worked out your R value yet?
 

pilko

Senior Member
I agree,the choice of circuit doesn't matter,I was just stating the difference.
I have not done any calculations yet, I just needed to know if the type of interface is OK
I am working on a control system to improve the efficiency of my Heat Pump using a 28X. I have written the code (not very elegant) but simulates OK on the programming editor I will be monitoring 6- 24V inputs and 4- analog inputs. I will be outputting to 6-Control relays
 

lbenson

Senior Member
pilko--thanks for the circuit diagram. I don't have easy access to the 24V neutral on the return side of the equipment (pump, burner on, zone valve)--just the terminals at the thermostat (is "neutral" proper terminology for one pole of an AC transformer?).

I put the DVM across those terminals, and I get 25V AC. If I short those terminals, the voltage measured drops below .1V (and boiler fires up). So it would appear that an option would be to put the R with optocoupler between those terminals, essentially parallel to the thermostat relay. Then using the inverting circuit above, the picaxe signal would be low when the thermostat was not on and high when it was on.

Regarding the R, is the calculation for AC as for DC: I=V/R or .005391 = 25V/4.7K giving about 5 milliamps with a 4K7 resistor?
 

Dippy

Moderator
Obv the amount of current depends on transistor section load requirements and device CTR.
But with this simple logic switching that 4K7 looks fine.

Generally for AC I would have thought that basing the calc on Vpeak (and Imax of the opto) would be safer - best to err on the side of caution (like I said before).
However, I would have thought that the current you choose will affect the 'smoothing' Cap you use as well.

But I would have thought for best performance have the emitter down to ground as in post 24. That's the 'proper' way.

Time to stop debating, spend the 50p and have a play :)
 

pilko

Senior Member
By connecting the opto transmitter accross the stat contacts,you are effectively connecting the opto transmitter in series with the control valve solenoid coil.When the stat closes it will short (jumper the opto transmitter) This may work,but is very unorthodox.
If you cannot access the 24V AC neutral, it's probably grounded anyway.See if you get 24V AC between 24V Hot and Ground.
 

lbenson

Senior Member
>See if you get 24V AC between 24V Hot and Ground.

I have only two wires coming through the plaster and lath wall to the thermostat--no ground available.

>By connecting the opto transmitter accross the stat contacts, you are effectively connecting the opto transmitter in series with the control valve solenoid coil. When the stat closes it will short (jumper the opto transmitter)

Yes. I tried a 4K7 resistor between the thermostat terminals. This did not turn the boiler on. The same down to 1K. So it looks like this might work (using the circuit in post 24 and adjusting the cap as needed).

But I have three zones in all, so it may make more sense to work in the basement. It's an unholy mess of unlabelled wires down there, from 2 owners and 20+ years ago.

Thanks, all--hope I haven't hyjacked the thread too much. If I have further questions, I'll start another thread. This project was meant for the Fall, but the posting raised some of the same questions I had.
 

pilko

Senior Member
Thanks everyone for the great help and advice .I have not given up on the direct input with limiting resistor etc I’ll be testing that method (safely)
I have been playing with the programming editor for a few months with help from you guys . I am getting to be a slow learner and fast forgetter at my age.
I received my first hardware a few days ago—a 28 pin project board, 28X chips and a USB download cable. I am as nervous as a dad with a new baby so I am being very careful.
 
Top