walterwoj
Posts: 28
Joined: Fri Mar 15, 2019 10:46 pm

Input Relay Board

Sun Mar 31, 2019 8:09 pm

So... previous I posted looking for an input relay. I have found this one and after asking the seller they replied that it would work for 110 volts as well as 220 volts. (yet to be conclusively tested). Anyway... I want to use it as an put to detect 110 volts. I am comfortable with the 110 side wiring but I'm not sure about the PI side. I'm hoping you can give me some guidance.

From the markings on the board and a note in the description ('Output High/Low level can be connected to SCM IO interface for testing'), I believe you connect either VCC or Ground to the pi and when there is 110 volts on the input the out(1,2,3) will be the the same?

Do you think this needs a resistor? If I put the resistor on the VCC that would cover all 3 outs right? Or do they each need a resistor?

PhatFil
Posts: 1406
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Input Relay Board

Sun Mar 31, 2019 8:31 pm

what exactly is the situation you want to monitor, there could be cheaper safer alternative solutions, for example if there is a led anywhere 'south' of what you want to detect a light sensitive resistor glued in place over the led could be all you need.. if a motor is involved a tilt switch could supply your input. Or look at using a smart relay controller to turn on/off the power and let it update you as to both power status and usage over wifi? . it its a whole or partial ring main plug in a phone charger linked to a cheap wifi enabled dev board like a wemos d1 or nodemcu and when it appears on your network you know it has power..

walterwoj
Posts: 28
Joined: Fri Mar 15, 2019 10:46 pm

Re: Input Relay Board

Sun Mar 31, 2019 8:38 pm

PhatFil: Thank you for the alternate ideas but they have already been considered and discarded. I have the board in question in my possession already and I believe it will be perfectly safe on the 110v side for what I am doing (checking the power state of 2 x 3-way switches to tell me if the light is on or off) So at this point lets work under the assumption that this is the method I will use. The question I am trying to answer is how do i connect this board to the pi safely (for the pi that is) so I can read the input it is providing?

User avatar
ptimlin
Posts: 88
Joined: Tue Jan 08, 2019 7:44 pm

Re: Input Relay Board

Sun Mar 31, 2019 8:57 pm

There was no schematic or data sheet supplied with the board?

If I had to guess I would assume that the output on the Pi side will be whatever voltage you use to supply the board's VCC & GND. Since the description indicates 3-5V use I would think if you supply 3.3V to the Vcc pin then you will get 3.3V on the OUTx pins. If you supply +5V to Vcc then you will get OUTx = 5V. Easiest way to check is hook up 3.3V to VCC+GND, then put a meter on OUTx and measure what you get when the switch it turned on or off for the AC. No Pi required to test.

walterwoj
Posts: 28
Joined: Fri Mar 15, 2019 10:46 pm

Re: Input Relay Board

Sun Mar 31, 2019 10:03 pm

Interestingly I was just testing that the way you suggested. It would appear that:

1.) if I connect vcc and ground to a 5v power supply and put a led from out3 to gnd (-) I get 2.63v on the LED (no 110v), once I apply 110v to the input I get 0v and the LED goes out.

1a.) If I omit the LED and only run my meter on the circuit I get 3.77v on high and 0 on low.

2.) If I connect VCC only and omit the GND I get 2.63 at rest and 3.3v with 110v input.

3.) if I only connect GND and out3 then I get nothing either way (0 or 110vac)

I'm guessing that #1 is the proper way it needs to be connected but I'm not sure why the high is only 2.63/3.77v when I put 5v in. (5.19v to be exact) I am sure it's not a amperage issue b/c my PS is good for 10 amps

walterwoj
Posts: 28
Joined: Fri Mar 15, 2019 10:46 pm

Re: Input Relay Board

Sun Mar 31, 2019 10:23 pm

ok, i'm clearly out of my depth!

#4.) VCC to 5.19v, GND to GND and LED from out3 to VCC. 0v dc at rest, 0v dc when in3 has 110v. BUT!!!! The LED lights brightly, like 5 volts bright even though my meter says 0 volts. WTF is going on here? I don't understand how this circuit works but it does. Can anyone explain this to me?

User avatar
davidcoton
Posts: 4182
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Input Relay Board

Sun Mar 31, 2019 11:13 pm

walterwoj wrote:
Sun Mar 31, 2019 10:23 pm
ok, i'm clearly out of my depth!
...
Can anyone explain this to me?
Not without more information about the relay board and the circuit on it. But DO NOT use a Vcc greater than 3V3 for connection to a Pi. 5V in the wrong place (GPIO input) can destroy a Pi very quickly

But I would respectfully suggest that if you are out of your depth with sorting that out, you really should not be connecting to 110V.
Apart from more issues than you realise in avoiding 110V on the Pi and in preventing your connections affecting the operation of the mains circuit, you need to confirm that:
  1. the relay board conforms with your local safety standards for use at 110V. (A quick look suggests that it may not.)
  2. your wiring conforms with your local safety standards for use at 110V.
  3. all mains tracks and wires are enclosed to conform with your local safety standards for use at 110V.
  4. where appropriate, all external metal parts of mains enclosures are grounded to conform with your local safety standards for use at 110V.
This requires you to be trained and experienced to the standards of a qualified electrician. If you are not, please desist.
If you get it wrong, you could destroy you Pi, your house (fire), or kill someone.
And then you may find your have invalidated your house insurance.
Signature retired

JohnsUPS
Posts: 122
Joined: Fri Jul 06, 2018 2:13 am
Location: USA

Re: Input Relay Board

Sun Mar 31, 2019 11:37 pm

To test this board, don't put a LED across OUT1 (or 2 or 3) to ground. What you were measuring (if I read your post right) was the voltage drop across the LED. The LED was bright probably because there is no series resistance between it and the output of the board, and the output appears to be switched by a transistor, which has a negligible forward voltage drop when fully on.

Try these two tests:
1)
Power supply: VCC = 5VDC, GND to GND.
Mains: Line side to L1, neutral side to N.
Measure the voltage on the output side of the board with nothing attached to any of the output terminals. What do you get? I'm suspecting you'll get something just under 5VDC (or just under the supply voltage). Meter should be on VCC and OUT1.
{I read your post again - you got 3.77 VDC like this}

2)
Same test as above, but with VCC = 3.3VDC. If the output is above 3VDC or so, it should have no problem being recognized by the Pi (forget what the exact input voltage low threshold is at the moment).
The move your high side input to L2, and measure OUT2, then L3 & OUT3 just to be sure all of the channels are working.

Because the advertisement for the board states that that it should be able to run between 3 - 5 Vdc, it should work on 3.3VDC.

Please exercise extreme caution when working with mains voltages. The board is isolated (at least it appears to be with optoisolators), so under no circumstances should there be any connections made from one side of the board to the other.
Also, notice that none of these tests involved connecting the board to your Pi. Do so at your own risk......

Apparently davidcoton and I were responding to your post at the same time - please heed his advice. Thank you...

walterwoj
Posts: 28
Joined: Fri Mar 15, 2019 10:46 pm

Re: Input Relay Board

Mon Apr 01, 2019 12:20 am

davidcoton: Ironically I have a far better understanding of mains electric than this other stuff that you guys claim is electric! :ugeek:

<good humored rant> For example: if I put a wall switch in my house and turn it off, if I test for voltage at the light, guess what voltage I will get? 0 volts! Every time! On every switch in the house! If you get 0.05 VAC on the output of a house switch you have a defective switch!

I read that (and have observed on my PI ) 'floating' can occur on the pi (and other electronics apparently) where the switch is 'off' yet there is voltage up to half of the active voltage. WTF kind of design is that? :x A switch that is maybe, probably, MOSTLY OFF?!?!?!?! SINCE WHEN WAS THAT OK?!?! No electrician in the world would allow that to happen and no electrical code I've ever heard of allows that either!

And another thing: Active LOW?! That is the house hold equivalent of putting the switch on the ground wire which is a complete no-no. Again no electrician would do that and no code would allow it either as it is VERY DANGEROUS if someone ever tried to work on the system later.
</good humored rant>

Seriously though: I've worked on mains electric all my life. :mrgreen: I could wire any house in the US to code with no problem. :geek: The concepts like floating, active low and pull up/down resistors simply don't exist in any household mains application or are illegal. So I am having some trouble accepting the concepts and applying them here. :shock: Please forgive me if I sound like any idiot when it comes to this low voltage stuff, it's actually very new to me.

walterwoj
Posts: 28
Joined: Fri Mar 15, 2019 10:46 pm

Re: Input Relay Board

Mon Apr 01, 2019 1:06 am

JohnsUPS wrote:
Sun Mar 31, 2019 11:37 pm
Same test as above, but with VCC = 3.3VDC. If the output is above 3VDC or so, it should have no problem being recognized by the Pi (forget what the exact input voltage low threshold is at the moment).
The move your high side input to L2, and measure OUT2, then L3 & OUT3 just to be sure all of the channels are working.

Because the advertisement for the board states that that it should be able to run between 3 - 5 Vdc, it should work on 3.3VDC.
I will have too see if I can scare up a 3.3v dc source. I only have the 5v power supply I bought for the PI. I will test the other input and outputs too, I just used #3 because it was easy to access.

I'm guessing that since it goes to 0 volts when activated that is an example of ACTIVE LOW (see above for my opinion of that, LOL) I think that the reason the relay puts out less DC voltage than expected is that they were originally designed for 220vac input. I'm putting 120vac into the input side (the seller said it would work) which is 54% and I'm getting 3.77vdc which is 72% of 5.19vdc (not quite the same, I get it.) but if it scales then 3.3vdc will be knocked down to 2.37vdc, So is 2.37vdc enough to register on the PI?

User avatar
ptimlin
Posts: 88
Joined: Tue Jan 08, 2019 7:44 pm

Re: Input Relay Board

Mon Apr 01, 2019 2:59 am

I will repeat my original question since it was not answered. Did this device/board come with any sort of schematic, data sheet, or other documentation? That would be very helpful.

As to the "active low", I explained it here somewhere a little while ago, but too lazy to look for it. Answer is that in the early days of semiconductor ICs, chips could not source much current (when the output is high) but they could usually sink much more current when those outputs would go low. And even LEDs required a bit more current to light properly back then where you would want to drive an LED with a good 10mA min, 20mA perhaps. So since your output couldn't drive 10ma, you would instead tie your voltage directly to the LED and then the "bottom" of the circuit would either go high to turn it off or go low (ON) to sink the current.

So it became the defacto standard that ON was "active low" and is still more or less the norm in electronics still. Keeping in mind that electronics are a lot different than electricity in a house. You won't kill yourself with 5V, so it doesn't really matter on a safety standpoint which side you switch.

User avatar
Burngate
Posts: 6046
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Input Relay Board

Mon Apr 01, 2019 11:01 am

walterwoj wrote:
Mon Apr 01, 2019 12:20 am
For example: if I put a wall switch in my house and turn it off, if I test for voltage at the light, guess what voltage I will get? 0 volts! Every time! On every switch in the house! If you get 0.05 VAC on the output of a house switch you have a defective switch!
...
And another thing: Active LOW?! That is the house hold equivalent of putting the switch on the ground wire which is a complete no-no. Again no electrician would do that and no code would allow it either as it is VERY DANGEROUS if someone ever tried to work on the system later.
Makes sense.
That's because the light is low-impedance compared to the switch when it's off.

And when the light-bulb goes pop, I'd very much like to be able to change it without touching live mains.
I read that (and have observed on my PI ) 'floating' can occur on the pi (and other electronics apparently) where the switch is 'off' yet there is voltage up to half of the active voltage.
Whatever is being fed by electronics such as a Pi's GPIO can itself be more-or-less an open-circuit - the gate of a FET for example takes no current.
So just disconnecting what's feeding it won't change anything - you have to provide a path for the charge to leak away. It's called pull-up or pull-down.

Inside the Pi SoC is a set of 50k resistances that can be used for that.
Whatever's driving the input - your optoisolator - doesn't have to be zero resistance when it's on - it just has to be very much lower than the pull resistance.
When it's off, it doesn't have to be infinite resistance, just very much higher than the pull.

Back to your light switch - when it's on, it doesn't have to be perfect, just good enough that the heat generated doesn't set fire to anything.
When it's off, it has to be nigh-on perfect, to avoid killing you.

User avatar
Burngate
Posts: 6046
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Input Relay Board

Mon Apr 01, 2019 5:06 pm

One of the things that initially bemused me was that "3 Channel AC 220V Optocoupler Isolation Board AC Detection Testing Module" being referred to as a relay - it isn't.

Without having one in my hands, I can't be sure, but it appears to take in three phases and neutral, rectify them, and pass the resultant DC through 150k to optoisolators.
Their outputs seem to be presented to some sort of transistor which could possibly be wired as open-collector. Or maybe not.

walterwoj
Posts: 28
Joined: Fri Mar 15, 2019 10:46 pm

Re: Input Relay Board

Mon Apr 01, 2019 6:01 pm

ptimlin: Sorry but the seller (and google) have not provided any schematics or instructions for this board. I did request them but did not get a response so I'll have to figure this out the hard way.

also, THANK YOU for that explanation of active low, It still drives me nuts but at least I understand why it's bass ackwards and it does make sense why it's that way now.

walterwoj
Posts: 28
Joined: Fri Mar 15, 2019 10:46 pm

Re: Input Relay Board

Mon Apr 01, 2019 6:07 pm

Burngate wrote:
Mon Apr 01, 2019 5:06 pm
One of the things that initially bemused me was that "3 Channel AC 220V Optocoupler Isolation Board AC Detection Testing Module" being referred to as a relay - it isn't.

Without having one in my hands, I can't be sure, but it appears to take in three phases and neutral, rectify them, and pass the resultant DC through 150k to optoisolators.
Their outputs seem to be presented to some sort of transistor which could possibly be wired as open-collector. Or maybe not.
You are right it is not a relay, I am used to relays of the mains voltage and above type so that's how I think of it, but your right it it is really opto-isolators with what appears to be Active low output (is that an oxymoron? active low and output since it is really taking voltage in?)

Now that we understand how it works (i think :mrgreen: ) do you believe it needs a resistor or anything between it and the PI or can I just wire it in direct?

User avatar
ptimlin
Posts: 88
Joined: Tue Jan 08, 2019 7:44 pm

Re: Input Relay Board

Mon Apr 01, 2019 7:33 pm

walterwoj wrote:
Mon Apr 01, 2019 6:01 pm
ptimlin: Sorry but the seller (and google) have not provided any schematics or instructions for this board. I did request them but did not get a response so I'll have to figure this out the hard way.
Since you have it in your hands, you can tell us what ICs are on it and how the components are hooked up and we can figure it out. As @burngate already mentioned, the high voltage side is pretty easy to figure out. Each phase goes through a diode bridge via the big ass resistor to rectify it, the cap provides smoothing, then it goes to the optoisolators. Knowing the numbers on those ICs will tell us what kind of output is on the low voltage side (so the three black ICs next to the Q's. Then if possible if you can read the flat face of the Qs we can see what kind of transistor is being used. The two resistors, one is for current limiting of the LED, but interested on where the other one is hooked up to Q and how both are interfaced to Vcc and GND.

Basically a number of ways these can be configured (transistor switched the output to GND or switches it to VCC, etc.) so rather than guess if you can follow the traces on one of the three channels to how everything is laid out, we can figure out the circuit.

Or even a couple of close up photos of that section of the board, both sides.

LTolledo
Posts: 2009
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Input Relay Board

Mon Apr 01, 2019 9:53 pm

This to detect the presence or absence of 220v?

If it were me I'd probably use a normal (industrial grade) relay with a coil rated 200 ~ 240v (like the Omron G2R-1-S, in socket P2RF)
to provide additional isolation a 3v optocoupler unit to be connected to the relay output contacts.
the optocoupler 3v outputs to RPi GPIO.
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

User avatar
davidcoton
Posts: 4182
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Input Relay Board

Mon Apr 01, 2019 10:08 pm

LTolledo wrote:
Mon Apr 01, 2019 9:53 pm
This to detect the presence or absence of 220v?
It's for detecting 110V, which the OP believes he is competent to handle (but see my earlier post). So it needs a relay with a 110V coil.
LTolledo wrote:
Mon Apr 01, 2019 9:53 pm
If it were me I'd probably use a normal (industrial grade) relay with a coil rated 200 ~ 240v (like the Omron G2R-1-S, in socket P2RF)
to provide additional isolation a 3v optocoupler unit to be connected to the relay output contacts.
the optocoupler 3v outputs to RPi GPIO.
And what powers the relay contacts and opto input? Another isolated supply? Or a Pi-derived supply? If the former, good, but do you really need two lots of isolation? If the latter, the opto achieves nothing.
Signature retired

boyoh
Posts: 1341
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Input Relay Board

Mon Apr 01, 2019 10:34 pm

If your input is 220vac or 110vac should make no difference
As the opto isolator gives total isolation between the opto
Transmitter and opto receiver. There should be no different
In the low voltage side whether you use 3.3 or 5v dc
If you use 5v to interface with the Pi you will have to use
Voltage levelling
Do NOT do any common connecting between INPUT & OUTPUT

220 vac / 110vac-----------( Circuit )----------( opto IR ) (opto receiver)

(Isolated Side) 3.3v+Rail----------( Circuit )-------GPIO I/P------(10k)---0vPi

Example showing One input
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

User avatar
ptimlin
Posts: 88
Joined: Tue Jan 08, 2019 7:44 pm

Re: Input Relay Board

Tue Apr 02, 2019 12:38 am

And what powers the relay contacts and opto input?
Ya if I were to use a 120Vac activated relay to sense is the 120V is on or not, then stupid easy way to do it is have the contacts simply connect the Pi's 3.3V to a GPIO input pin. No optoisolator or other components requires. The contacts are already isolated from the high voltage side with the coupling being magnetic now rather than optical.

boyoh
Posts: 1341
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Input Relay Board

Tue Apr 02, 2019 9:40 am

Working with mains voltages is not for the inexperienced
So take great care

I assume the low voltage side works like this
The signal switching is don using a on board transistor not a relay
The opto isolator receiver transistor will switch the 3.3 or 5v
The opto isolator receiver transistor collector will all be commoned
To the 3.3 or 5vdc witch ever voltage you are using.
The opto isolator transistor emitter will switch the on board transistor
On or Off when the mains input is active.

Might be right or wrong Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

boyoh
Posts: 1341
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Input Relay Board

Tue Apr 02, 2019 1:15 pm

ptimlin wrote:
Tue Apr 02, 2019 12:38 am
And what powers the relay contacts and opto input?
Ya if I were to use a 120Vac activated relay to sense is the 120V is on or not, then stupid easy way to do it is have the contacts simply connect the Pi's 3.3V to a GPIO input pin. No optoisolator or other components requires. The contacts are already isolated from the high voltage side with the coupling being magnetic now rather than optical.
1 Three way 220/120 ac voltage monitoring unit £ 12.00

1 220 / 110 vac Relay £10.00 x 3 = £ 30.00

No cost of relays mounting box
No AC relay buzz or noise

Not so stupid now is it

Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

User avatar
ptimlin
Posts: 88
Joined: Tue Jan 08, 2019 7:44 pm

Re: Input Relay Board

Tue Apr 02, 2019 4:53 pm

boyoh wrote:
Tue Apr 02, 2019 1:15 pm
1 Three way 220/120 ac voltage monitoring unit £ 12.00
1 220 / 110 vac Relay £10.00 x 3 = £ 30.00
Sounds like he only needs two. So £ 20 for the relays ;)
boyoh wrote:
Tue Apr 02, 2019 1:15 pm
No cost of relays mounting box
No AC relay buzz or noise
How is it that you require a box for the relays but not one for this exposed circuit board? So be sure to add in the costs associated with mounting that ac voltage monitoring board.

And unless you are buying crap relays, relays typically do not "buzz".

At any rate, my response was simply to note that *if* you used a relay to sense a voltage (it wasn't my suggestion) then you don't need the addition of optoisolaters and such as was being suggested, just wire the contacts across the required Pi pins.

Return to “Beginners”