Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.raspberry-pi > #12626

Re: control a relay from the pi via GPIO

From Gordon Henderson <gordon+usenet@drogon.net>
Newsgroups comp.sys.raspberry-pi
Subject Re: control a relay from the pi via GPIO
Date 2016-07-07 10:44 +0000
Organization Drogon Towers
Message-ID <nllbra$3ga$1@dont-email.me> (permalink)
References <nljpg6$me8$1@dont-email.me>

Show all headers | View raw


In article <nljpg6$me8$1@dont-email.me>,
Björn Lundin  <b.f.lundin@gmail.com> wrote:
>Hi!
>I got a pi model B that I want to control a relay.
>
>I've got one just like the ome on the picture in the link here
>
><https://halckemy.s3.amazonaws.com/uploads/image_file/file/76359/PoolSchematicDC.jpg>
>
>
>I connect just as the picture, +5v to vcc and ground to ground.
>The green diod then ligths up.
>
>So I connect a gpio to the middle pin marked Inl.
>GPIO low = nothing happens
>GPIO high = nothing happens.
>
>I grab a voltmeter and measure between the GPIO and ground,
>and I get ca 0 V resp 3.3 V. So - correct pin, but no action in the relay.
>
>Ok, thinking 3.3 might be to small to drive the relay, testing +5 V on
>the middle pin. Still nothing.
>Frustrated - testing ground to middle pin - and then the relay clicks,
>and the red diod lights up, somewhat brighter than the green one.
>
>Surley - this is not supposed to happen - or ?
>
>I got 3 of those relays, and all three behave the same - ground the
>middle pin and then action.
>
>
>What am I doing wrong here?

Several things.

Firstly you've bought a cheap relay board which may have said "Raspberry
Pi" on it website, but it really is not Pi compatible. This happens a lot,
especially with sellers in far-off land you have no way to get in-touch
with. They lie and use the Raspberry Pi name to lure unsuspecting buyers.

So the relay board - the real issue is that it's designed for 5v
operation. It's really for an Arduino or similar running at 5v. The Pi's
3.3v combined with the resistor into the opto coupler does not provide
enough "oomph" to light the internal LED and activate the relay. Thats
the case with most of these cheap boards...

... however - another issue is that sometimes these relay boards (and I've
seen dozens of different ones )-: effectively connect the LED + resistor
to the 5v line - expecting the driving computer to short it to 0v.

Try this:

Leave it wired as it is, but then remove the wire from the Pi'2 GPIO
pin 22 and connect it to 0v/Gnd.

If the relay fires then you have one of these.

And by reading the above, this is most likely.

So do this:

  Re-connect it to the Pi on that pin (bcm_gpio 22)

and run these commands:

  gpio -g mode 22 in

Realy ought to be off and stay off.

  gpio -g write 22 0

Nothing should happen at this point.

  gpio -g mode 22 out

Relay should click ON. The pin is in output mode and is sinking
the current from the 5v, via the resistor + LED to 0v.

  gpio -g mode 22 in

Relay should click off.

I've seen this make similar relay boards work. It works, BUT ... when
in the off state (ie. gpio pin is in input mode), you are presenting 5v
to the GPIO pin. fortunately via a resistor and diode and the input
protection diodes on the GPIO pin will limit the damage, but it's very
not recommended. It'll work, but for how long...

Really, you need to throw this relay board away and get something designed
for the Pi. Use something like a PiFace board.

Gordon
(Author of wiringPi)

Back to comp.sys.raspberry-pi | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

control a relay from the pi via GPIO Björn Lundin <b.f.lundin@gmail.com> - 2016-07-06 22:24 +0200
  Re: control a relay from the pi via GPIO rickman <gnuarm@gmail.com> - 2016-07-06 16:45 -0400
    Re: control a relay from the pi via GPIO rickman <gnuarm@gmail.com> - 2016-07-06 17:03 -0400
      Re: control a relay from the pi via GPIO Dennis <dennis@none.none> - 2016-07-06 18:00 -0500
        Re: control a relay from the pi via GPIO Dennis <dennis@none.none> - 2016-07-06 21:10 -0500
          Re: control a relay from the pi via GPIO rickman <gnuarm@gmail.com> - 2016-07-06 23:55 -0400
            Re: control a relay from the pi via GPIO Dennis <dennis@none.none> - 2016-07-07 12:30 -0500
      Re: control a relay from the pi via GPIO Björn Lundin <b.f.lundin@gmail.com> - 2016-07-07 19:21 +0200
        Re: control a relay from the pi via GPIO rickman <gnuarm@gmail.com> - 2016-07-07 14:34 -0400
          Re: control a relay from the pi via GPIO Dennis <dennis@none.none> - 2016-07-07 17:10 -0500
            Re: control a relay from the pi via GPIO rickman <gnuarm@gmail.com> - 2016-07-08 00:29 -0400
        Re: control a relay from the pi via GPIO Björn Lundin <b.f.lundin@gmail.com> - 2016-07-12 10:18 +0200
          Re: control a relay from the pi via GPIO Rob Morley <nospam@ntlworld.com> - 2016-07-12 12:49 +0100
  Re: control a relay from the pi via GPIO Gordon Henderson <gordon+usenet@drogon.net> - 2016-07-07 10:44 +0000
    Re: control a relay from the pi via GPIO Björn Lundin <b.f.lundin@gmail.com> - 2016-07-10 17:40 +0200
      Re: control a relay from the pi via GPIO rickman <gnuarm@gmail.com> - 2016-07-10 12:43 -0400
        Re: control a relay from the pi via GPIO Björn Lundin <b.f.lundin@gmail.com> - 2016-07-12 10:06 +0200
          Re: control a relay from the pi via GPIO The Natural Philosopher <tnp@invalid.invalid> - 2016-07-12 09:20 +0100
          Re: control a relay from the pi via GPIO rickman <gnuarm@gmail.com> - 2016-07-12 04:23 -0400
            Re: control a relay from the pi via GPIO The Natural Philosopher <tnp@invalid.invalid> - 2016-07-12 09:58 +0100
    Re: control a relay from the pi via GPIO Graham. <graham-usenet@mail.com> - 2016-07-11 23:10 +0100
  Re: control a relay from the pi via GPIO Graham. <graham-usenet@mail.com> - 2016-07-08 21:45 +0100
    Re: control a relay from the pi via GPIO Björn Lundin <b.f.lundin@gmail.com> - 2016-07-10 17:26 +0200
      Re: control a relay from the pi via GPIO Graham. <graham-usenet@mail.com> - 2016-07-11 22:13 +0100
        Re: control a relay from the pi via GPIO Björn Lundin <b.f.lundin@gmail.com> - 2016-07-12 10:00 +0200
  Re: control a relay from the pi via GPIO Big Bad Bob <BigBadBob-at-mrp3-dot-com@testing.local> - 2016-08-18 10:08 -0700
    Re: control a relay from the pi via GPIO rickman <gnuarm@gmail.com> - 2016-08-18 16:40 -0400

csiph-web