User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4257
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: how to sense 220v input -solved- I hope

Wed Jul 19, 2017 8:17 am

I'm stupid with electronics too. Generally, if I build anything with mains, I hide behind the chair the first time I switch it on.

The obvious thing to test is the voltage across the LEDs. You'll probably want to attach (and double-check) the probes before turning it on. If the LEDs have failed you may get mains voltage across them, so start out with the meter on a high setting. If everything is working well then you'll get 1-2V AC.
The next worry I would have is the capacitor. Try disconnecting it. The GPIO should then see a 50 or 60Hz square wave when power is on.

Also be aware of the comments further up the page that the 100K resistor looks rather large for the application. If you do have 1-2V across them and no signal with the capacitor out of circuit, I would try reducing it to 2W 50K.

conciseusa
Posts: 2
Joined: Wed Mar 28, 2018 5:40 am

Re: how to sense 220v input -solved- I hope

Mon Apr 23, 2018 6:04 am

One tip, using a cap on the input to lower the voltage with much less heat is great if you are connected to the grid where you have a nice clean sine wave.

I sometimes need to monitor the output of a 240VAC modified sine wave inverter in an off grid system. I find that using a cap in this situation lets the smoke out of my interface. So I go with a resistor or two at 2 - 3 Watts.

I also wanted an indicator lite and some input protection against spikes.

I did a write up on the design I have been using for a few years if you want to look over what worked for me.

http://conciseusa.com/wordpress/versati ... pberry-pi/

huey-driver
Posts: 5
Joined: Mon Dec 23, 2019 10:35 pm

Re: how to sense 220v input -solved- I hope

Mon Dec 23, 2019 11:01 pm

Anyone mind if I resurrect this thread (he says as he posts on a 7 year old thread).
Hopefully, someone can help. I post here rather than starting a new one because there is a lot of good historical discussion.

I am looking to sense 24VAC, a US thermostat call. I can use any optoisolator, but the LTV-844 stands out. (forward voltage=1.8V, forward current=50mA)
Just to make sure, I calculate about a 500Ω resistor on the AC line at about 1.5W power dissipation.
Am I in the ballpark?

Just for comparison, the power supply is HT01BC115C, rated 40VA, but I assume that means consumption on the 120V side. The whole board is protected by a 3A fuse.
Please disregard the DC motor, its the easiest thing I found in fritzing....
Attachments
Untitled Sketch 2_schem1.jpg
Untitled Sketch 2_schem1.jpg (78.88 KiB) Viewed 691 times
Last edited by huey-driver on Mon Dec 30, 2019 2:53 pm, edited 1 time in total.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13285
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: how to sense 220v input -solved- I hope

Tue Dec 24, 2019 1:01 am

Well, hardware doesn't "age"as quickly as software, otherwise I wouldn't have let this post through. :mrgreen:

If you build this circuit the result would have been smoke pouring out of the opto-isolator, as the LED in it probably can't withstand the 34 or so volt (square root of 2 times 24V, is 1.41 x 24 = 33.94) it would try to block 50% of the time.

What you would need is a diode in anti-parallel with the LED in the opto-coupler so that in both directions there is a conducting diode in series with the resistor.

I = V/R = 22/500 = 33mA, which is a bit much, so I should triple the resistor to 1500 Ohm.

plugwash
Forum Moderator
Forum Moderator
Posts: 3664
Joined: Wed Dec 28, 2011 11:45 pm

Re: how to sense 220v input -solved- I hope

Tue Dec 24, 2019 1:13 am

huey-driver wrote:
Mon Dec 23, 2019 11:01 pm
I am looking to sense 24VAC, a US thermostat call. I can use any optoisolator, but the LTV-844 stands out. (forward voltage=1.8V, forward current=50mA)
50mA is the absolute maximum rating. I doubt you will need to go anywhere near that high. 5mA is probablly far more reasonable.

Normally you would need to add an anti-paralell diode as majongg suggests, but it seems that these particular optocouplers have anti-paralell LED inputs, so you don't need to deal with that externally.

huey-driver
Posts: 5
Joined: Mon Dec 23, 2019 10:35 pm

Re: how to sense 220v input -solved- I hope

Tue Dec 24, 2019 3:17 am

Well, thanks for letting through!
Felt kinda bad with it being an old thread. But, i have read a LOT and this thread had the best info in it.
Actually, I got 1.5k on my first try, using a peak to peak of 34ish. I talked myself out of it tho, so thanks for the help.
Using that 34V value, and maybe a more reasonable 20mA forward current, i get a little under 1W. My big question is on the power. The duty cycle is way less than 25%, but it may have some continuous on time of 2 hours, possibly more, when a big temperature change is called for.
And i also looked at a few, and liked the bi-directional LEDs. Taking some of Gordon's advice above, i can fix the pulsing problem in software. The granularity of my samples will be over many seconds, rather than tight milliseconds.

huey-driver
Posts: 5
Joined: Mon Dec 23, 2019 10:35 pm

Re: how to sense 220v input -solved- I hope

Sat Dec 28, 2019 1:15 pm

One thing, maybe I can get help with....
I understand the math (Ohm's law) and I understand the how (a resistor works)...
Trying to understand the 'why' (with 35 years having passed since college physics)...
I ordered several different resistors, assuming that since I was paying shipping from digikey, might as well replenish the supply.
A lot (all) of my past 'projects' (more 'experiments') were trial and error. Calculating initial values (ie, for a voltage divider) then building and tweaking using what I had. But they were all DC, which seems easier for me to understand.
Now, working with AC, I may be making it harder than it really is. I got out my multimeter, and no matter which side of the resistor I measured on, I still got 24VAC when putting a 1.6k ohm resistor in series with the multimeter across the hot and common. I havent tried my higher quality (RMS) multimeter yet, but dont understand why I am not even seeing a slight drop in voltage. And I did test the resistor several times, and it is showing the right values...
Thanks!

User avatar
rpdom
Posts: 17569
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: how to sense 220v input -solved- I hope

Sat Dec 28, 2019 1:38 pm

huey-driver wrote:
Sat Dec 28, 2019 1:15 pm
Now, working with AC, I may be making it harder than it really is. I got out my multimeter, and no matter which side of the resistor I measured on, I still got 24VAC when putting a 1.6k ohm resistor in series with the multimeter across the hot and common. I havent tried my higher quality (RMS) multimeter yet, but dont understand why I am not even seeing a slight drop in voltage. And I did test the resistor several times, and it is showing the right values.
The resistor and your multimeter are forming a potential divider. The resistor is 1.6K and your meter will be something on the order of 10000K. It is that high (or probably higher) so that it doesn't drag the voltage it is measuring down.

So Ohms Law:

Total resistance, say 10001.6K at 24V (I'm going to ignore the fact it is AC at the moment, just to make things easier). That's about 2.4microAmps. The voltage at that current across the 1.6K resistor will be around 0.004V and the meter will still get most of the 24V.

Does that help?
Unreadable squiggle

huey-driver
Posts: 5
Joined: Mon Dec 23, 2019 10:35 pm

Re: how to sense 220v input -solved- I hope

Sat Dec 28, 2019 7:33 pm

Thanks. I think I was expecting to see 1.8v that I was trying to get down to for the LEDs.
But I see now that multimeter is taking up many times more, leaving the resistor very little to do. If thats right. And I also figured the bi-directional flow may be giving me something other than what I was expecting and would have seen with DC. This was further proven, when I was measuring values and even though I had a circuit, it wasnt enough to turn on the furnace....
Just wanted to verify my calculations before I put it to the LEDs in the opticoupler....
Like I said, I believe the math. Just trying to learn the 'why'.... And also, I always check before putting wires to the little black plastic things with the magic smoke inside... Kind of a "measure twice, cut once" thing...
I guess next step is to hook it up and see... But, that is one of the reasons why I bought extra parts....

huey-driver
Posts: 5
Joined: Mon Dec 23, 2019 10:35 pm

Re: how to sense 220v input -solved- I hope

Tue Dec 31, 2019 12:49 am

Thanks for the help.
I put everything together yesterday using a 1.6k/1W resistor. So far, the MSL gauge (thats 'Magic Smoke Level') is still showing 'Full'.
I updated my fritzing diagram above with the new resistor value. Didnt want someone who didnt read the whole thread to just look at the pictures and burn anything up.
Initially, I wired up an LED to the optocoupler output. That 1.6k ohm resistor still delivered enough to have a steady bright LED. Later, wired it up to the digital input on my Arduino using the 5V source, a 1k current limiting resistor and 10k pull-downs. I'm using interrupts on the Arduino that just set a boolean value to 'True' if they detect a high pin. The loop runs every 5 secs and reads all the booleans, then resets them back to false. Thats my technique for overcoming any pulsing of the optocoupler (rather than a capacitor). Keeps things simple.
I'll clean it all up and put it on my github for others looking for the same...
Thanks again all!

Return to “HATs and other add-ons”