User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 05, 2012 6:17 pm

TarjeiB wrote:
fruitloaf wrote:That's the board I have but I used a transistor to drive it as from my reading of the circuit it puts 5V into the GPIO line via the status LED. If you look VCC goes to R1 which goes via a diode and LED to the GPIO.

My reading of that (and I'm far from an electronics expert) is that when your GPIO is high the LED will be lit as you are still getting 5V - 3.3V into it and LEDs will show a usable amount of light down into low volt levels. When low you are sinking the 5V into GPIO. I think that the R1 resistor is what is limiting the current and stopping you from blowing up your Pi. I may of course be completely wrong about the above :)

I'm using a transistor and a couple of resistors to drive the input successfully.
Yes! That sounds similar to what I've seen some times - I was thinking I just didn't understand it.

However the GPIO is just GPIO -> R 1k -> Gate on the transistor and no other tracks on either side as far as I can see, does power really flow back through the gate of a transistor?
No, it shouldn't, and if that's the way it is, you ought to be fine - however...

If you have wiringPi, then try this at the command-line:

gpio -g mode 23 in
gpio -g mode 23 up
gpio -g mode 23 down

assuming you're using GPIO pin 23.. (change for whatever)

See if it toggles the relay, alternating between up & down... that's enbling the internal pull-up, pull-down resistors...

Then try this:

gpio -g mode 23 out
gpio -g write 23 1 # Turn on
gpio -g write 23 0 # turn off

then try connecting a 330 ohm resistor from the gpio pin to 0v, however a "low" gpio pin really ought to turn off a transistor!

-Gordon
--
Gordons projects: https://projects.drogon.net/

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 05, 2012 6:51 pm

This is really doing my head in :/

Firstly, nice program with the wiringPi! I did, however, get the error

Code: Select all

[email protected]:~# gpio -g mode 23 in
wiringPiSetup: Unable to determine board revision: 1000002
gpio: Unable to initialise GPIO mode.
trying to use it, so I had to stick with the echo 1 > /sys/class/gpio/gpio23/value and so on.

I'm using the pin 23.

I added the 330ohm resistor between GND and GPIO, and end up with 3.0V with GPIO23 high and 118mV with GPIO23 low, and guess what... Relay stays on. :evil:

I'm thinking it's the wrong transistor (if there is such a thing), my RPi is leaking power (118mV?) or something I don't understand. Evidently it works at 0.0V (disconnected GPIO turns off relay), but it doesn't work at 118mV (GPIO low turns on relay).
Last edited by TarjeiB on Wed Sep 05, 2012 6:59 pm, edited 2 times in total.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 05, 2012 6:57 pm

TarjeiB wrote:This is really doing my head in :/

Firstly, nice program with the wiringPi! I did, however, get the error

Code: Select all

[email protected]:~# gpio -g mode 23 in
wiringPiSetup: Unable to determine board revision: 1000002
gpio: Unable to initialise GPIO mode.
Sorry - you've caught me updating the code for the new Raspberry Pi board revisions and obviously there is a bug there...

Can you email me the output of your /proc/cpuinfo please?

Your revision number is somewhat unnexpected...

-Gordon
--
Gordons projects: https://projects.drogon.net/

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 05, 2012 7:01 pm

Code: Select all

[email protected]:~# cat /proc/cpuinfo
Processor       : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS        : 795.44
Features        : swp half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xb76
CPU revision    : 7

Hardware        : BCM2708
Revision        : 1000002
Serial          : 000000001d438275
Another fun observation! The transistor turns on with only GND connected to the "in1" pin! A whooping 3mV is measured between TP2 and the "in1" pin. The LED runs bright and the relay is switched. As soon as I pull it off it switches back. Something is completely out of whack.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 05, 2012 7:06 pm

TarjeiB wrote:

Code: Select all

[email protected]:~# cat /proc/cpuinfo
Processor       : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS        : 795.44
Features        : swp half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xb76
CPU revision    : 7

Hardware        : BCM2708
Revision        : 1000002
Serial          : 000000001d438275
Well that's very unnexpected. I expected it to be 0002 not 1000002 )-:

See here for the Revision codes according to Eben: http://www.raspberrypi.org/archives/1929

So I wonder what's going on here )-:

-Gordon
--
Gordons projects: https://projects.drogon.net/

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 05, 2012 7:24 pm

[email protected] wrote:Well that's very unnexpected. I expected it to be 0002 not 1000002 )-:

See here for the Revision codes according to Eben: http://www.raspberrypi.org/archives/1929

So I wonder what's going on here )-:
-Gordon
Must be the 1M ohm I misplaced somewhere during my random testing :lol:

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 05, 2012 7:26 pm

[email protected] wrote:
TarjeiB wrote:

Code: Select all

[email protected]:~# cat /proc/cpuinfo
Processor       : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS        : 795.44
Features        : swp half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xb76
CPU revision    : 7

Hardware        : BCM2708
Revision        : 1000002
Serial          : 000000001d438275
Well that's very unnexpected. I expected it to be 0002 not 1000002 )-:

See here for the Revision codes according to Eben: http://www.raspberrypi.org/archives/1929

So I wonder what's going on here )-:
I've worked it out - You have overvolted your Pi!

that's how the foundation (or anyone!) can tell...

Now to adjust wiringPi accordingly.

Cheers,

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 05, 2012 8:03 pm

[email protected] wrote:
[email protected] wrote:
TarjeiB wrote:

Code: Select all

[email protected]:~# cat /proc/cpuinfo
Processor       : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS        : 795.44
Features        : swp half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xb76
CPU revision    : 7

Hardware        : BCM2708
Revision        : 1000002
Serial          : 000000001d438275
Well that's very unnexpected. I expected it to be 0002 not 1000002 )-:

See here for the Revision codes according to Eben: http://www.raspberrypi.org/archives/1929

So I wonder what's going on here )-:
I've worked it out - You have overvolted your Pi!

that's how the foundation (or anyone!) can tell...

Now to adjust wiringPi accordingly.

Cheers,

-Gordon
I've pushed a new version, and deliberately overvolted one of my Pi's to test it with - if you want to do a git pull origin and re-built it, then you might be able to run the gpio commands now!

-Gordon
--
Gordons projects: https://projects.drogon.net/

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 05, 2012 8:23 pm

[email protected] wrote:If you have wiringPi, then try this at the command-line:

gpio -g mode 23 in
Result: LED turns off, relay stays on (what?)
gpio -g mode 23 up
Result: Relay turns off
gpio -g mode 23 down
Result: Nothing happens, LED is off, relay is off
See if it toggles the relay, alternating between up & down... that's enbling the internal pull-up, pull-down resistors...
It does not - only thing that toggles the relay is

Code: Select all

gpio -g mode 23 out
gpio -g mode 23 in (LED turns off)
gpio -g mode 23 up (relay turns off)
Down/up does nothing untill I do OUT again.
Then try this:

gpio -g mode 23 out
gpio -g write 23 1 # Turn on
gpio -g write 23 0 # turn off
OUT switches on relay and LED. 1 and 0 does nothing, relay stays on.

How on earth did the relay stay on but the LED turn off? They are in the same circuit I thought...
I will do all the tests again tomorrow with the 330ohm resistor in place.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 05, 2012 9:19 pm

TarjeiB wrote: How on earth did the relay stay on but the LED turn off? They are in the same circuit I thought...
I will do all the tests again tomorrow with the 330ohm resistor in place.
I think at this point, it might be worthwhile trying to reverse engineer an accutate citcuit diagram by tracing the PBC tracks and seeing how it's really wired up...

-Gordon
--
Gordons projects: https://projects.drogon.net/

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Will An Ebay Relay Board work with the pi?

Thu Sep 06, 2012 11:16 am

[email protected] wrote: I think at this point, it might be worthwhile trying to reverse engineer an accutate citcuit diagram by tracing the PBC tracks and seeing how it's really wired up...
-Gordon
I think this is how it's wired from what I can tell - I've traced everything I can see and put it down as I went.
From my very limited experience it seems OK - maybe I should just try to remove all the LEDs?

*EDIT* Corrected the transistor direction in the drawing... Maybe.
Attachments
switch.png
switch.png (14.76 KiB) Viewed 3642 times
Last edited by TarjeiB on Thu Sep 06, 2012 11:35 am, edited 1 time in total.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Thu Sep 06, 2012 11:35 am

TarjeiB wrote:
[email protected] wrote: I think at this point, it might be worthwhile trying to reverse engineer an accutate citcuit diagram by tracing the PBC tracks and seeing how it's really wired up...
-Gordon
I think this is how it's wired from what I can tell - I've traced everything I can see and put it down as I went.
From my very limited experience it seems OK - maybe I should just try to remove all the LEDs?

Oh, the transistors may be backwards in this drawing... No idea if they are on the board, I don't know how to tell.
Yes, I suspect the transitors have been drawn upside down (collectors & emitters swapped) and I also think some of the resistors have an extra zero (e.g. 4700 ought to be 470)

However, thats fairly standard - nothing really odd about it - the relays are on the emitter side of the transistor in common collector mode, so taking the input to +3.3v ought to turn the relay on, and taking it to ground ought to turn it off.

I am somewhat surprised that setting a GPIO pin to output and writing 0 to it does not turn the relay off. At that point the GPIO pin is more or less connected to 0v and it really should turn the relay off!

I'd be tempted to wire up an LED in parallel with the GPIO output connected to ground via a 330 ohm resistor just to make sure you're actually switching the output on and off..

-Gordon
--
Gordons projects: https://projects.drogon.net/

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Will An Ebay Relay Board work with the pi?

Thu Sep 06, 2012 11:42 am

[email protected] wrote: I am somewhat surprised that setting a GPIO pin to output and writing 0 to it does not turn the relay off. At that point the GPIO pin is more or less connected to 0v and it really should turn the relay off!
Funny thing that - I actually tried to have only VCC and GND connected (Relay is then off), then connect GND to IN1, and it turns on! No GPIO involved at all.
Are my transistors broken? Seems like no matter where the wire comes from, as long as something is connected to IN1 or IN2 it turns on. Setting direction IN seems to "disconnect" the pin.
[email protected] wrote: I'd be tempted to wire up an LED in parallel with the GPIO output connected to ground via a 330 ohm resistor just to make sure you're actually switching the output on and off..
I can do that, but connecting GND directly to IN1 pretty much tells me this won't make a difference? I just bought a bunch of LEDs though so I'll probably try it :)

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Will An Ebay Relay Board work with the pi?

Thu Sep 06, 2012 12:06 pm

Just checked the transistors (bent it forwards) and they are marked "S8550 SDA08". I guess this means it's a PNP transistor. Is that correct?

*EDIT* Ok seems that would more or less explain everything! Since the base voltage is ALWAYS lower than the 5V I've connected, the transistor is always closed. It's just the wrong damn transistor.

I need to just exchange it for a NPN and it should work, in my head at least. :)

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

Re: Will An Ebay Relay Board work with the pi?

Thu Sep 06, 2012 12:20 pm

That looks likely, at least "S8550" is the part number of a PNP transistor. So the switching voltage will be relative to Vcc, and not to GND. I think that might be your problem; the relay will switch on between GND and Vcc-0.6V, and switch off at Vcc. It's probable that the RaspPi is not supplying a high enough voltage.

You've gone beyond my programmer's-level knowledge of transistors if you use an NPN with the same circuit. It might work, but the LED in the emitter circuit will affect the behaviour. I think that's the sort of thing used to add negative feedback, and therefore you might find it difficult to switch on. Then again, I might be totally wrong. You need an EE.

I think you could swap all the transistors to NPN, reverse the diodes and swap the polarity of the power supply, but that might be more work than you want.

Saulverde
Posts: 15
Joined: Fri Aug 17, 2012 12:18 am

Re: Will An Ebay Relay Board work with the pi?

Thu Sep 06, 2012 4:18 pm

These are the relay boards I use. I can power the two relay board from the pi without any problem. I just used my led blink program to test the relays and they worked. I would think the 4 relay board will require its own supply.

http://www.dealextreme.com/p/arduino-co ... ule-144762
http://www.dealextreme.com/p/arduino-2- ... red-144140

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Will An Ebay Relay Board work with the pi?

Thu Sep 06, 2012 4:30 pm

Yea, it seems it's just the wrong transistors on mine for what I wanted it to do. I'm going to order a couple new ones to solder on, and see if I can't make it work. Meanwhile I've got some MOSFETS which will do the trick (but no diode for protection).

Thanks a bunch for helping me through this, especially Gordon with your nice little program and invaluable advice :)

At least I now understand a bit more, and had the right idea from the start... Just the wrong components.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Thu Sep 06, 2012 4:35 pm

TarjeiB wrote:Just checked the transistors (bent it forwards) and they are marked "S8550 SDA08". I guess this means it's a PNP transistor. Is that correct?

*EDIT* Ok seems that would more or less explain everything! Since the base voltage is ALWAYS lower than the 5V I've connected, the transistor is always closed. It's just the wrong damn transistor.

I need to just exchange it for a NPN and it should work, in my head at least. :)
I thought the circuit looked 'wrong' and should have been a PNP transistor.

Better to use an NPN as a level changing inverter before the inputs to the relay board. Either that or level translating MOSFET.


Thinks must get these boards built damn paying work getting in the way :lol:
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Fri Sep 14, 2012 7:35 pm

At least I now understand a bit more, and had the right idea from the start... Just the wrong components.
No it is the wrong circuit as well.
If you just replace those transistors with NPN ones then the maximum voltage you can get across the relay is 2.6V which I suspect will not be enough to turn it on.
This is because the load is in the emitter and the emitter will not get higher that -0.7V of the base. As you are only driving the base with 3V3 that gives you 2V6 on your relay.

You need a different circuit where the relay goes from the collector to +5V, put the LED & resistor across the relay coil. Then you can switch it on with a 3V3 signal, 1K between the base and GPIO pin.
The emitter of the transistor goes straight to ground.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Fri Sep 14, 2012 8:43 pm

Better still use a digital FET like FDV303N to ground

NO resistors

CAN sink 2A continuous current

DIRECT drive from 3V3 GPIO signal

Low Rds (low power dissipation) diue to low ON impedance
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
Bencom
Posts: 56
Joined: Wed Mar 07, 2012 10:40 pm
Location: New Zealand
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Fri Sep 14, 2012 8:52 pm

I use a YwRobot 4 relay. These relays are positive logic. In other words +3.3v equals off and 0 volts equals on. I think it works this way. When the port is set as input the pin is high due to pull up enabled (Relay off). When the pin is output it is floating (Tri state) thereby 0v and the relay is on.

It is normal to boot a micro in the safest state and I think the outputs need to be driven low but are configured as open collector so can not be driven low. To use the ports as one may normally expect requires more set up but really is not necessary.

The reason for positive logic is simple. It stops the relays chattering on power up. Explaining electronic theory is not a strong point.

This has the circuit for the relay I use. Cheap from Ali Express in China, shipping being the killer.
http://arduino-direct.com/sunshop/index ... tail&p=181

The R value is such that the relay will activate with 3.3v or 5v logic. One may not have the same joy with opto isolated relays depending on how it is set up.

Image
View image and remove -320 for the full sized image.

Basically I use the wiringPi software gpio and the library. I have written a small C daemon which monitors the button and switches the relays as well as other things. I simply switch between input and output.

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Will An Ebay Relay Board work with the pi?

Sat Sep 15, 2012 5:57 pm

Thanks guys - I ended up ditching the whole relay and using a single MOSFET instead, as outlined in this post.

No diode though for protection, but don't think the 12V-48V will give "feedback" on shutdown, or am I wrong?

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Will An Ebay Relay Board work with the pi?

Sat Sep 15, 2012 7:25 pm

with 12 - 48V around I would put as much protection in as possible as 48V is like to fry/smoke your Pi if things go wrong.

How god the MOSFET is depends on the MOSFET in use as some are only 20 to 30V capable others have higher voltage working. We have no idea from that post how you are configuring it. Is it a P or N MOSFET?

Many other possible questions .
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: Will An Ebay Relay Board work with the pi?

Sun Sep 16, 2012 8:16 pm

It's a N MOSFET of type irli3705n and it's switching the ground wire of 12V. There's a 12V-56V converter in the chain which I'm worried the spools may give some return voltage when power is cut, like a motor may? It should be connected like the original drawing in the original project post.

rooster
Posts: 100
Joined: Thu Aug 02, 2012 8:09 pm

Re: Will An Ebay Relay Board work with the pi?

Wed Sep 19, 2012 1:30 pm

Hi TarjeiB

I think I'm having the same trouble as you. I have the YWRobot transistor and relay circuit that is supposed to connect to the gnd, 5V and GPIO0 from the PI and the GPIO is supposed to switch the relay - but doesn't. Not sure why - the gpio 3.3V is just supposed to be the signal which puts 5V across the coils to switch it. If anybody finds a solution please post it here. This is very frustrating!

R

Return to “Automation, sensing and robotics”