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


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

Re: control a relay from the pi via GPIO

From rickman <gnuarm@gmail.com>
Newsgroups comp.sys.raspberry-pi
Subject Re: control a relay from the pi via GPIO
Date 2016-07-08 00:29 -0400
Organization A noiseless patient Spider
Message-ID <nlna7g$em8$1@dont-email.me> (permalink)
References (1 earlier) <nljqk9$p7j$1@dont-email.me> <nljrnb$udt$1@dont-email.me> <nlm31a$nj7$1@dont-email.me> <nlm7b7$7vo$1@dont-email.me> <nlmjvp$pq8$1@dont-email.me>

Show all headers | View raw


On 7/7/2016 6:10 PM, Dennis wrote:
> On 07/07/2016 01:34 PM, rickman wrote:
>> On 7/7/2016 1:21 PM, Björn Lundin wrote:
>>> On 2016-07-06 23:03, rickman wrote:
>>>
>>> Thanks rickman, for your replies
>>>
>>>>
>>>> So you have two problems.  One is that the relay coil is rated for 5
>>>> volts which means it should have 3.75 volts on the coil to work
>>>> properly.  The rPi I/Os won't survive with this much voltage across
>>>> them
>>>> when the output is not driven low.
>>>
>>> Hmm, yes, but I did try feeding it 5 V as well. no go
>>>
>>>
>>>> The other is the rated current, 71.4 mA.  This is far higher than what
>>>> the rPi I/Os can drive.
>>>
>>> That might be the problem.
>>> Still, if I grounded the signal pin, the relay came to life,
>>> so the coil was fed enough to click/switch the relay
>>>
>>>
>>>
>>>> To solve both problems you simply need to add a transistor to your
>>>> circuit.  In reality your relay module should have the transistor on
>>>> it,
>>>> but it doesn't look like it does.
>>>
>>> Yes, I realize that now. Either I do that or try it with an arduino.
>>> I could communicate with the arduino via the serial port
>>>
>>>
>>>> There seem to be tons of available references on how to interface this
>>>> type of relay to your rPi.  If you provide better info on what you have
>>>> I can give you more info on what you can do to use it.
>>>
>>> Yes and I read a good part. Some info indicates it is ok to use directly
>>> with the pi, while other indicates that a transistor is needed. I just
>>> thought it was very strange that I got movement when I grounded the
>>> middle pin. As you can tell, electronics is not my strongest subject.
>>>
>>> <https://www.youtube.com/watch?v=OvWOcNiQe1c>
>>> indicates 3 min into the movie that no transistor i needed.
>>>
>>> I try the arduino , and it it works, I'll use that instead
>>>
>>> I got a big server in the garage that gathers data at night.
>>> I don't want to run it during the day, so I'm thinking of
>>> automatically ssh in to it and issue a sudo halt using expect from the
>>> pi. This still leaves the fans on, so I'd like to kill the power to it
>>> via the relay. and when power is restored, it boots automatically.
>>
>> As Dennis pointed out there is a fuzzy blob on the photo that looks like
>> it is three terminal and likely a transistor.  So you would need to
>> trace out the circuit to see what they have designed.  The circuit on
>> the module Dennis has turned out to be a high side switch which means it
>> is handling the higher current for you, but is referenced to 5 volts and
>> so will over stress your rPi I/O pin.  If this is what is on your module
>> it is not a good idea to drive this relay directly from your rPi I/O. It
>> will need another transistor to handle the voltage translation.  Just
>> one transistor and two resistors.  I would use a common base arrangement
>> with the base biased to about 1 volt.  Or you can use a common emitter
>> arrangement which will invert the sense of the signal which you can
>> compensate for in the software.
>>
>> Some Arduinos are 5 volt devices which will drive this I/O directly. But
>> first you need to trace out the circuit to see just what you have.
>>
> I am pretty sure mine has the same circuit as his but with 2 relays. It
> looks similar and has "2 Relay Module" and "HL-52" on the board. I think
> they make 1, 2, 4 and 8 relay versions that are just multiple copies of
> the same circuit.

I have seen Chinese boards made to do the same job but by different 
companies.  They can vary widely while appearing very similar.  So I 
don't share your confidence of the two circuits being the same, but I 
certainly can't rule it out.


> The question is why high switching (PNP) rather than low side (NPN)
> which would work fine with either 3.3 or 5 volts. My guess is for
> safety. The processors I know of come up with the I/O in input mode
> which would look like a high signal (tri-state or pull-up) which would
> leave the relay unenergized. You can then do your set up before changing
> to output mode and selecting the relay. Using an NPN could energize the
> relay immediately on power up which you may not want.

It would not be an issue if the output comes up high impedance (which is 
not a pull-up).  Either a high side or low side switch could default to 
off.  A pull up or a pull down as appropriate should be on the relay 
module.  I agree that there seems to be little difference between the 
high side and the low side switch.  So I can't say why they would use 
the high side switch.

-- 

Rick C

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