knute
Posts: 692
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Relay board appears to pull inputs high?

Thu May 06, 2021 10:26 pm

I've got a Waveshare relay board. When I look at the voltage on the GPIO pins for the relays, they have about 2.0 volts on them when the Pi starts up. The relays are not energized. To energize the relays you have to apply a low output on the GPIO. I've checked the voltage on the GPIO without the relay board and it is 0 when the Pi starts and when it shuts down.

Not being an engineer, is there some reason that Waveshare would make the relay board work this way? Do you think they have a pull-up resister somewhere causing this? Is there some electrical safety reason this makes sense?

Thanks!

gordon77
Posts: 5685
Joined: Sun Aug 05, 2012 3:12 pm

Re: Relay board appears to pull inputs high?

Fri May 07, 2021 6:20 am

Can you provide details or photo of the board ?

This could be the schematic ?

https://www.waveshare.com/rpi-relay-board.htm
Attachments
IMG_20210507_072922.jpg
IMG_20210507_072922.jpg (9.41 KiB) Viewed 863 times

knute
Posts: 692
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Relay board appears to pull inputs high?

Fri May 07, 2021 2:53 pm

That looks like my relay board. From the schematic I can see why I see the voltage on the wire. Is this a typical wiring for a relay and opto-isolator? Is there a reason it couldn't be wired up so the output of the GPIO pin turns on the opto-isolator? Can the GPIO sink more current than source?

Thanks for looking!

gordon77
Posts: 5685
Joined: Sun Aug 05, 2012 3:12 pm

Re: Relay board appears to pull inputs high?

Fri May 07, 2021 3:10 pm

I guess they are ensuring the input is not floating, which may bring on the led which could be confusing.

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

Re: Relay board appears to pull inputs high?

Fri May 07, 2021 5:26 pm

knute wrote:
Fri May 07, 2021 2:53 pm
That looks like my relay board. From the schematic I can see why I see the voltage on the wire. Is this a typical wiring for a relay and opto-isolator? Is there a reason it couldn't be wired up so the output of the GPIO pin turns on the opto-isolator? Can the GPIO sink more current than source?

Thanks for looking!
Well the problem with this schematic is that it has two LED's in series, and as (Red) LEDs have a forward voltage (as a diode) of around 2.0 Volt, it would mean that the total forward voltage would be 4.0Volt, so technically the LEDs cannot be driven with just 3,3Volt. But if the forward voltage curve (the volt versus current curve) isn't too sharp, its perhaps possible, but with very little voltage remaining over the series resistor.

But my advise is to take out (short) the indicator LED, so that 3.3 - 2 = 1.3 Volt is left for the resistor, and choose a resistor so that about 5mA flows through the LED, meaning that with r=U (or V, depends where you are from whether you use U or V for voltage in ohms law) R = U/I = 1.5 / 0.005 = 260 Ohm you will have your 5mA .

I have no idea what the use of the 10K resistor is, seems superfluous to me, unless its used as a pullup to ensure the GPIO as an input sees a reliable high, but I don't have a clue why that would be important.

A GPIO can drive the same current as sink it, no difference there.

The rule of thumb is that a GPIO can source (or sink) maximum 15mA, before bad things could happen (internal copper traces in the chip that will burn through), and a sum total of 50mA for all GPIO's together. I wrote about using relays in my pitfall sticky, you may want to read that.

drgeoff
Posts: 11942
Joined: Wed Jan 25, 2012 6:39 pm

Re: Relay board appears to pull inputs high?

Fri May 07, 2021 5:42 pm

Sharp's datasheet for the PC817 states that for a forward current of 20 mA the typical voltage drop is 1.2 Volts and the maximum is 1.4. Also the current transfer ratio depends on the part binning category but the minimum with 5 mA through the diode and 5 Volts across the transistor is 50. So the relay probably can operate even with quite low current though the optocoupler's diode.
Quis custodiet ipsos custodes?

gordon77
Posts: 5685
Joined: Sun Aug 05, 2012 3:12 pm

Re: Relay board appears to pull inputs high?

Fri May 07, 2021 6:31 pm

mahjongg wrote:
Fri May 07, 2021 5:26 pm
knute wrote:
Fri May 07, 2021 2:53 pm
That looks like my relay board. From the schematic I can see why I see the voltage on the wire. Is this a typical wiring for a relay and opto-isolator? Is there a reason it couldn't be wired up so the output of the GPIO pin turns on the opto-isolator? Can the GPIO sink more current than source?

Thanks for looking!
Well the problem with this schematic ...
This relay is sold specifically for the pi, see link, so maybe the schematic is wrong or the components have been specially chosen ?

The OP didn't say it doesn't work just wondering about a pull up.

emma1997
Posts: 1525
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Relay board appears to pull inputs high?

Fri May 21, 2021 5:25 pm

With that universal but incompetent circuit, simply shorting the LED is easiest and most economical fix for reliable operation. Otherwise you may find it fails when temps drop. If you share common ground or supply then bypassing the opto entirely makes more sense. Added advantage becomes active high which makes far better for most applications anyway.

Surprised that the usual advice to add darlingtons or other Rube Goldberg mods have not been posted.

gordon77
Posts: 5685
Joined: Sun Aug 05, 2012 3:12 pm

Re: Relay board appears to pull inputs high?

Fri May 21, 2021 7:47 pm

If this is the relay board l linked to then l would expect it to work as its sold as a pi specific item.
The OP never said it didn't work, just surprised it's active low.

pidd
Posts: 2076
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: Relay board appears to pull inputs high?

Fri May 21, 2021 7:54 pm

I'd expect an active low input to have some pull-up to switch it off in its default state. Generally devices should default to off if they have an open circuit input.

gordon77
Posts: 5685
Joined: Sun Aug 05, 2012 3:12 pm

Re: Relay board appears to pull inputs high?

Fri May 21, 2021 8:51 pm

pidd wrote:
Fri May 21, 2021 7:54 pm
I'd expect an active low input to have some pull-up to switch it off in its default state. Generally devices should default to off if they have an open circuit input.
It has.

emma1997
Posts: 1525
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Relay board appears to pull inputs high?

Fri May 21, 2021 10:28 pm

gordon77 wrote:
Fri May 21, 2021 7:47 pm
If this is the relay board l linked to then l would expect it to work as its sold as a pi specific item.
The OP never said it didn't work, just surprised it's active low.
Maybe it 'sort of works' but shouldn't with two diode drops inline as mentioned earlier in this thread. Assuming couple volts offset each, it's surprising 3.3v signal works. In fact more than a few that have gone through my hands did not. At least not reliably, specially at temps too far below freezing.

Also surprising a lower value series resistor is not required considering the poor transfer characteristics of cheapo optos.

"You have to ask yourself one question, do I feel lucky? Well... do ya punk?"

https://www.youtube.com/watch?v=38mE6ba3qj8

lol

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

Re: Relay board appears to pull inputs high?

Mon May 24, 2021 1:47 pm

One reason why two diodes (LED's) in series might just work would be if the LED in the onto isolator is an infra-red LED, (there is no reason why the LED light has to be visible, and these LED's have somewhat lower forward voltages. Just an idea, look it up in the onto-isolators datasheet. :mrgreen:

gordon77
Posts: 5685
Joined: Sun Aug 05, 2012 3:12 pm

Re: Relay board appears to pull inputs high?

Mon May 24, 2021 2:50 pm

mahjongg wrote:
Mon May 24, 2021 1:47 pm
One reason why two diodes (LED's) in series might just work would be if the LED in the onto isolator is an infra-red LED, (there is no reason why the LED light has to be visible, and these LED's have somewhat lower forward voltages. Just an idea, look it up in the onto-isolators datasheet. :mrgreen:
1.2v @20mA, less with lower current
Attachments
IMG_20210524_183043.jpg
IMG_20210524_183043.jpg (82.99 KiB) Viewed 437 times
IMG_20210524_154936.jpg
IMG_20210524_154936.jpg (25.57 KiB) Viewed 456 times

drtechno
Posts: 245
Joined: Fri Apr 09, 2021 6:33 pm

Re: Relay board appears to pull inputs high?

Mon May 24, 2021 8:33 pm

knute wrote:
Thu May 06, 2021 10:26 pm
I've got a Waveshare relay board. When I look at the voltage on the GPIO pins for the relays, they have about 2.0 volts on them when the Pi starts up. The relays are not energized. To energize the relays you have to apply a low output on the GPIO. I've checked the voltage on the GPIO without the relay board and it is 0 when the Pi starts and when it shuts down.

Not being an engineer, is there some reason that Waveshare would make the relay board work this way? Do you think they have a pull-up resister somewhere causing this? Is there some electrical safety reason this makes sense?

Thanks!
Well, so far I see none of the relay boards actually are designed for the PI. Because they don't make provisions in the design for the GPIO when the PI is turned on and the IO is at an unknown state. Beyond other small things like the max current is 50mA total for all the busses.

That is why the best setup for these Pis are MOSFET drivers so the gpio doesn't use any current and cause extra heat in the processor.

Beyond that, I see a lot of these relay boards made just to market with the PI. Which a lot of them will have mistakes because someone copied a DIY design and massed produced it without proper engineering. Beyond the practice of using the gpio in a convoluted way to power the unit off, which it really doesn't. Because other are trying to sell junk because they want to try to avoid selling you the solution because the end customer has to solder the header pins for global_en.

pidd
Posts: 2076
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: Relay board appears to pull inputs high?

Mon May 24, 2021 9:17 pm

drtechno wrote:
Mon May 24, 2021 8:33 pm
Well, so far I see none of the relay boards actually are designed for the PI. Because they don't make provisions in the design for the GPIO when the PI is turned on and the IO is at an unknown state.
I don't understand what you expect.

For the Waveshare board above if the IO is low or high it will obey the status, if the IO is an input or tri-state then relay will be de-energised.

The Pi GPIO outputs are in a known state on boot, its up to the user to choose a suitable pin and interface that matches their requirements. The defaults are that all are inputs GPIO 0 thru 8 have pull-ups, GPIO 9 thru 27 have pull-downs but as these are weak pull-downs they will not be sufficient to energise that relay board.

So when the Pi is turned on, the Waveshare board will have all the relays de-energised until the Pi software says otherwise.

BTW, full marks to Waveshare for giving full documentation and are gradually putting their software on Github (even if it is a little buggy sometimes).

qiangyou_peng
Posts: 38
Joined: Wed Nov 04, 2020 2:56 am

Re: Relay board appears to pull inputs high?

Fri Jun 11, 2021 9:49 am

pidd wrote:
Mon May 24, 2021 9:17 pm
drtechno wrote:
Mon May 24, 2021 8:33 pm
Well, so far I see none of the relay boards actually are designed for the PI. Because they don't make provisions in the design for the GPIO when the PI is turned on and the IO is at an unknown state.
I don't understand what you expect.

For the Waveshare board above if the IO is low or high it will obey the status, if the IO is an input or tri-state then relay will be de-energised.

The Pi GPIO outputs are in a known state on boot, its up to the user to choose a suitable pin and interface that matches their requirements. The defaults are that all are inputs GPIO 0 thru 8 have pull-ups, GPIO 9 thru 27 have pull-downs but as these are weak pull-downs they will not be sufficient to energise that relay board.

So when the Pi is turned on, the Waveshare board will have all the relays de-energised until the Pi software says otherwise.

BTW, full marks to Waveshare for giving full documentation and are gradually putting their software on Github (even if it is a little buggy sometimes).

When the waveshare engineer saw this, the expression was dumbfounding

Return to “HATs and other add-ons”