Yes. Since simple transistors do not come in an IC package (Actually they do from a couple of manufacturers but are very expensive) you could get a 8 channel darlington pair IC, like a ULN2803, which would make wiring a little simpler, but you will be wasting unnecessary power. The other option is to buy one of the add-on boards that do the work for you.mayburyds wrote: You need a transistor/resistor for each relay switch, in this case 8?
Yes. It keeps the 3.3 CMOS output of the GPIO digital lines isolated from the 5V line of the pi. Also, keep in mind that the GPIO 5V line of the pi is not protected by a fuse, so check and then recheck your wiring before turning everything on. I am actually ordering a couple of small fuses to put on my 5v line when I place my next order.mayburyds wrote: Apart from the advantages of not having to power the relays all the time and setting them high instead of low to switch them on, which makes a lot of sense, do you need the transistors/resistor if you use two power supplies?
Correct.chisleu wrote: The collector on the transistor goes directly to the pin and merely switches the ground on to drop that pin so the relay switches on!!
Are you connecting the cable to a solderless breadboard or a soldered circuit card? I have ordered parts to build both and could supply you with parts numbers if you wish. If it is a solderless breadboard, Adafruit makes a connector for that purpose if you don't want to make your own.chisleu wrote: Hopefully I can find some sort of connector to I don't have to solder to this hacked up floppy drive cable.
If someone has a free method to repost the drawings, without needing for me to login, and without a timeout, I will repost them.chisleu wrote:Since the drawings from the previous posts are down, I wanted to be sure I have this right.
Sure, they are both basic NPN style transistors. You are pretty much just using them as a switch. The 2N2222 can handle a lot more collector current and costs more, but if you already got 'em use 'em.ryanjennings wrote:Would a 2N2222 instead of the bc547b work for this setup?
pjc123 wrote:OK, here we go.................
I have attached links to the schematics and spec sheets which I found after a long Google session when I first bought the relay card. Follow along, looking at the schematic as you read the rest of this, so you understand the various designations on the relay board that I am talking about. I must say that I was also very confused as well at first, reading that some people just hooked it up and it worked while others just couldn't get it to work. I think some of the confusion may be that there are a couple of these relay boards around from different manufacturers, and they don't all work the same, and people are using it with many different products, like Arduino for example, and each has different voltage levels on their GPIO output lines (CMOS vs TTL).
I was hoping when I bought the relay board that I could just hook it up to the GPIO ports and it would just work. So, the first thing I tried was to connect the 3.3v GPIO pin of the pi to Vcc of the relay (Pin 10 of the 10 pin header), then removed the jumper from pins 2 and 3 of the 3 pin relay header, connected the 5v GPIO pin of the pi to JD-Vcc of the relay (Pin 3 of the 3 pin header) so it operates the coil, and hooked the ground to pin 1 of the 10 pin relay header. Unfortunately, because there is a 1k ohm resistor in series with an indicator led and the opto's led, there is just not enough voltage at 3.3v to turn on the led in the optos (I measure only .49 ma flowing through the opto). So some relays worked, some didn't, some barely turned on.
Since that didn't work I connected the 5v GPIO pin of the pi to Vcc of the relay (Pin 10 of the 10 pin header), put the jumper back on pins 2 and 3 of the 3 pin relay header so that it would operate both the opto as well as the coil of the relay, and hooked the ground to pin 1 of the 10 pin relay header. I then attached the output of the GPIO to the base of an npn transistor using a 2.2 k resistor. I see others have used values as high as 10k or more (Since there is only 1.17ma flowing through the base, I really don't care about the value). The collector goes to output of the opto (IN1, IN2, etc). The emitter goes to ground. Now, it is active high instead of low, which makes a lot more sense; I don't want to have to continuously apply power to the GPIO data ports to keep the relays off. So, when I send a 1 or high to the GPIO port, this causes current to flow through the base of the transistor, 1.88 ma to flow through the opto, the opto lights up, and the relay turns on with a very solid loud click every time with every relay.
If you decide to use a different power supply to power the coils, it is as simple as removing the jumper from pins 2 and 3 of the 3 pin relay header, connecting the GPIO 5v line to to pin 2 of the header to operate the optos, and connecting the external 5v power supply to pin 3 of the header to operate the coils.
As a side note, the ground pins on both headers are connected together on the circuit board, so you do not need to attach to both of them.
You might come up with a better way to get it working, but that is what worked for me.
Relay Card Schematic
Relay Card Specifications
Man, I have to take a pee after all of that !
your description of how to operate the sainsmart relay board worked perfectly .. I have a 2 relay board. my only question is why use the resistor? I used a 10k resistor just because that is what I saw others doing .. you indicate that you don't care about the value .. so do you really need the resistor? (obviously I know nothing about electronics so take that into account) .
Although I never measured it, I suspect that all those GPIO grounds are just connected together on the circuit board. I just connected all the grounds of my circuit and the relay card to pin 6 Ground of the GPIO header, choosing that ground pin for no particular reason. Since you are probably using relays for isolation, you don't want to connect the relay output grounds to that ground, but I imagine you know that already.glukoz wrote:I want to set the same connection between Rpi and relay and I have one doubt regarding ground wires. Can ground wires in circuit be connected to multiple ground pins in Rpi or should they all be connected to one ground pin? If multiple, does it really matter which ground pins I will choose? If only one, which pin should I choose for that purpose?