Help with circuit - Page 1
Forum section: electronics / beginners

author: SEnergy
author_rank: Contributor
timestamp: June 29, 2015, 05:41:30 pm
content: Hello,I'm SEnergy and I'm pretty new to this forum AND electronics (second week), I've been programming for 8+ years and decided to upgrade my software skills by adding a little bit of hardwareI'm trying to use Relay with my raspberry pi, following tutorial I found on the internet (except I do not have transistor, gonna get that tomorrow) but I am not quite sure I connected this correctly (schemes are still kinda new to me)scheme (only relay <-> raspberry part, not actual output of relay, and yes, I realize I've bought incorrect relay for this and that I'm using 330R instead of 1KR, this is just a "prototype" circuit till I get transistor):EDIT: After looking at it for another half an hour I decided to rebuild it from scratch, the result:

author: PICmonster
author_rank: Regular Contributor
timestamp: June 30, 2015, 02:16:56 pm
content: You have a 6V relay on the breadboard that will be powered from 5V supply from the Pi, ideally this should be a 5V relay, however should work as there will be a voltage tolerance, the circuit diagram looks to be fine but I can not see enough detail of the breadboard to advise.Also some relays are polarized so it is very important to make sure that the + &- connection are correct on polarized relays, you can test this by listening if the coil engages when you apply 5V to the relay coil, try +&- and then -&+ on the relay coil, if you can here it energizing each time it is non-polarized relay and you can connect it either wayaround.Sounds like your new to electronics and I would suspect electrical aspects also, I can not comment about the mains side of your application and advise not to do any work with mains voltages if you are inexperienced as it is very dangerous.

author: picandmix
author_rank: Frequent Contributor
timestamp: June 30, 2015, 04:17:01 pm
content: The diagram should work, but there are two things to be aware of.Your relay, be it the 6v one or even a 5v type, have a minimum voltage needed to turn on.Your 6v relay is being powered from 5v plus there is a 0.7 volt drop across the BC337 so the relay will only see 4.3v which might be too low to allow it to turn on.Depending on the quality of the relay, its datasheet may specify that minimum turn on voltage.Also assumning that 5v is whats powering your micro, though possible / ok for your learning exercise, its not the best thing to have an electrical noisy device like a relay on the same power line as the micro; many circuits you will see drive relays from a separate / eg. 12v line to avoid such problems.For outputs controlling main AC devices its often much better to use a Solid Sate Relay.

author: Tandy
author_rank: Frequent Contributor
timestamp: June 30, 2015, 05:57:06 pm
content: The Raspberry Pi GPIO pin can not drive a relay directly as there is insufficient current, that is why you need the transistor.See the Magpi Magazine issue 3https://www.raspberrypi.org/magpi-issues/MagPi04.pdfIt is a little out of date but explains why you need a transistor.

author: IanB
author_rank: Super Contributor
timestamp: June 30, 2015, 06:11:36 pm
content: Quote from: picandmix on June 30, 2015, 04:17:01 pmIf the transistor is turned on fully there should be much less than a 0.7 V drop across it. Maybe 0.1 V or so.

author: SEnergy
author_rank: Contributor
timestamp: June 30, 2015, 07:45:59 pm
content: Quote from: PICmonster on June 30, 2015, 02:16:56 pmI've tried it with different voltages and 5V works fine, also looks like it's non polarizedI am not really gonna use electrical aspects (my father is electrician so if I'd go for that I have someone to help me, but he has little to none experience with electronics)I just need this so I can control electronics via GPIO output on raspberry, something to send a "signal" to turn on a part of the circuit that is powered by other source (e.g. DC Motor that's powered by a battery, which I want to control using software and GPIO pin on raspberry) - or should I use something else than a relay for this?Quote from: picandmix on June 30, 2015, 04:17:01 pmas stated above, I tried to connect it directly to the 5V pin on raspberry and it worked just fine, I also tried to use it without transistor (so I connected it straight to the ground instead of transistor) as soon as I got a reply that the circuit is correct and it powered just fine, also I haven't found minimum voltage to power the relay in datasheetI don't know what you mean by "micro", but the relay is not noisy at all (if you don't mean the clicking), also I don't really understand what would it cause if I'd power the relay from the raspberryalso why would there be voltage drop across the transistor? it's being powered from different GPIO pin (3V3), so it shouldn't affect the relay, or?Quote from: Tandy on June 30, 2015, 05:57:06 pmnot sure about other versions, but from what I know on raspberry pi 2 B it is safe to draw ~20mA from 3V3 GPIO pins, up to 50mA combined and as much as the raspberry pi source can provide from 5V pin minus what pi draws (e.g. if I have 5V@2A source that powers raspberry, which draws ~700mA I can draw up to 1300mA from 5V pin)Quote from: IanB on June 30, 2015, 06:11:36 pmwhy would transistor reduce the voltage drop? (I really have no idea what transistor does, I still kinda have bad understanding of those electronic devices from all the tutorials as they don't explain it on a newbie level - I need to see it in action to truly understand it, as all that info I've found makes kinda zero sense to me)thanks all for your answers, just to make sure you understood (I kinda have other feeling) the scheme is from the internet and I just wanted to know if my breadboard circuit is connected correctly according to the scheme, also could someone explain to me why is there diode connected like that? I really don't understand it's purpose in this circuit

author: picandmix
author_rank: Frequent Contributor
timestamp: June 30, 2015, 07:56:09 pm
content: Put simply, the diode is just there to stop the interference caused by the relay voltage turning on and off .Not sure how much you want to get into the detail of such circuits, but if you would rather have something working without all the experimentation you can buy boards like this for cheaper than the price of most single relays.http://www.ebay.co.uk/itm/Dual-Relay-board-cables-for-use-with-UNO-MEGA-Rasberry-pi-etc-UK-stock-/191493523446?pt=LH_DefaultDomain_3&hash=item2c95e747f6Expect you will have some similar on your local ebay, though you do not show your country flag.Edit - This pdf shows how such a circuit is put togther.http://www1.electusdistribution.com.au/images_uploaded/relaydrv.pdf

author: Tandy
author_rank: Frequent Contributor
timestamp: June 30, 2015, 08:06:50 pm
content: Because the relay has a coil in it that is energised to switch it on, when you stop powering the coil the energy stored in it is released back in the opposite direction. The diode diverts this excess energy away from the sensitive components like the transistor and the raspberry pi.

author: IanB
author_rank: Super Contributor
timestamp: June 30, 2015, 08:20:31 pm
content: Quote from: picandmix on June 30, 2015, 07:56:09 pmExcept in extreme cases that "interference" may be enough to destroy the thing powering the relay. The diode is for protection against that.

author: SEnergy
author_rank: Contributor
timestamp: June 30, 2015, 09:22:48 pm
content: Quote from: Tandy on June 30, 2015, 08:06:50 pmlooking at my breadboard, the leftover energy will go to orange wire, therefore to diode, which won't let it go thru BUT at the same time back to the yellow wire, therefore voltage source, right? same with scheme, it will go "up" from the relay, pass near the diode and will go to 5V source, or how does it work exactly?

author: Tandy
author_rank: Frequent Contributor
timestamp: June 30, 2015, 10:19:30 pm
content: Using conventional flow the current is going from the +5V through the relay coil and then through the transistor to ground to magnetise the relay coil. On your Breadboard that would be the orange wire at +5v and the red at near enough ground (0v ignoring voltage drop over the transistor).When you switch off the power to the relay by sending a zero the magnetic energy is converted back to electrical energy where it will be released in the reverse direction. I.e the green wire will have a positive voltage on it and the orange will have 0v. SO now as you can see from the schematic the current can flow that way through the diode, the diode therefore will absorb the energy, converting it to heat.

author: SEnergy
author_rank: Contributor
timestamp: June 30, 2015, 11:19:56 pm
content: Quote from: Tandy on June 30, 2015, 10:19:30 pmthanks!but now I've got few questions:1, if I get this right, the transistor and diode (red & green wire) are in parallel, right? so shouldn't the current go from the coil to the transistor AND the diode?if NOT1a, why is the current going only to transistor (not to diode) when the transistor is powered?1b, why is the current going only to diode (not to transistor) when the transistor is not powered?2, when I switch off the power of the relay - you said that the green wire will have positive voltage and orange will have 0V - doesn't that mean the current will go FROM the green wire, thru the coil TO the orange wire?if NOT2a, it means that the current goes from the coil TO the green wire from the orange wire, therefore it is NOT in the reverse direction, right?if YES2b, if it goes to the orange wire from the coil, the diode then shouldn't let the current flow thru it (based on how it is currently used), therefore the current would end up back in the 5V source, right? wouldn't that damage the source?

author: Tandy
author_rank: Frequent Contributor
timestamp: June 30, 2015, 11:34:47 pm
content: The Diode D1 is in parallel with the relay REL1. The Transistor is in series with them.Starting at the top of the schematic you can see that the +5v from the raspberry Pi (your red wire) is fed to the relay and the cathode of the diode (your orange and yellow wires).The other side of the relay is connected to the collector of the transistor (second red wire).When you set the GPIO high on the Raspberry Pi, a small current flows into the base of the transistor (via resistor) to switch it on. This completes the circuit by connecting the relay to the 0v ground.Now when you set the GPIO to low on the raspberry Pi the current stops flowing to the transistor and the relay switches off.When it switches off, for a brief moment a back EMF is generated. This means that current is flowing the opposite way, this would be trying to push backwards through the transistor potentially damaging it. But because the diode offers a lower resistance path for the current to flow it is dumped into the diode.Electric current always takes the path of least resistance.

author: SEnergy
author_rank: Contributor
timestamp: July 01, 2015, 08:49:17 am
content: Quote from: Tandy on June 30, 2015, 11:34:47 pmbased on the schematics I see why is the transistor in series, but the diode confuses me - how is it in parallel? why?also looking at my breadboard to me it looks like both are in parallel - how should I connect the wires to make both, transistor and diode in parallel after the relay? (just so I understand series/parallel configuration better, as it still kinda confuses me)----------------------------------------------------so when the transistor is not powered, the current goes all the time to to the diode, where it gets lost as a heat - now there's a question -1, is the current going straight to the cathode, OR is it going THROUGH the relay and to the anode of the diode?1a, if it is going straight to the cathode, why is not the current going to the relay as well (as they are in parallel), and then to the anode, thus powering the relay?1b, if it is going thru relay to the anode, why isn't it powering the relay?----------------------------------------------------Quotehow? you said the coil will release magnetic energy, converting it to the electrical energy and pushing it in the opposite direction - therefore it should go from coil to the orange wire - what happens next is not known to meI appreciate your effort, but as I mentioned above - most of the tutorials (and your lessons) are NOT easy to understand by someone who has basically no knowledge about electronics (I'm not even sure I know how diode works...) - I'd need you to tell me exactly how is the current flowing like I'm 10y old and using few words to explain what and why is going on in the electronic component, e.g."when you power the 5V source, the current goes thru yellow wire to orange wire (and diode???), to the coil, then it goes to transistor, but it doesn't go to diode, BECAUSE ..." et cetera

author: Tandy
author_rank: Frequent Contributor
timestamp: July 01, 2015, 10:06:37 am
content: It is not easy to explain things in text in a forum. But I think the issue is that you are trying to learn everything all at once.I would suggest perhaps pick up a book for beginners or use some of the on-line videos and tutorials as it is a lot easier with illustrations. It can be quite daunting at first but don't give up.

author: Zero999
author_rank: Super Contributor
timestamp: July 01, 2015, 10:11:22 am
content: Don't worry about the rest of the circuit for now. Focus on the rely and diode.The coil of a relay is an inductor. It resists changes in current flow. It behaves like a flywheel. It takes time to change the amount of current flowing through it.If the transistor is turned on so it appears to be a piece of wire, current will build in the inductor, until it reaches a value determined by its internal resistance.When the transistor is turned off, it appears to be an open circuit but because energy is stored in the inductor, the current continues flowing but there's no longer a path to the negative rail so it continues to flow through the diode, until the energy is dissipated.It's easier to understand if arrows are added to the schematic to represent the conventional current flow.

author: SEnergy
author_rank: Contributor
timestamp: July 04, 2015, 06:29:14 pm
content: Quote from: Hero999 on July 01, 2015, 10:11:22 amthanks!but I've still got few questions1, for some reason it still looks to me that the diode and transistor are in parallel with relay, there's that (idk how to call it) "point" where the diode and transistor are connected, just like the same point above, that connects diode relay - why is diode + relay in parallel, but transistor is in series? what's the logic behind it? at what should I look to distinguish between series and parallel connection in schemes?2, when the transistor is on, why isn't the current flowing to the diode? why is it completely ignoring that path? in what case would it go thru the diode AND transistor?3, when the transistor is off, why isn't the current flowing back to the source? I understand it would be kinda stupid for it to go there, as the electrons are coming out of there, so there most likely is not a physical possibility for electrons to go in the opposite direction as the current flow, but then again, that is a parallel connection, so it should go there, right?4, when the transistor is off, the current is flowing thru the coil anyway, so it should be magnetized, therefore turned on - so why is it off?

author: IanB
author_rank: Super Contributor
timestamp: July 04, 2015, 06:43:54 pm
content: Quote from: SEnergy on July 04, 2015, 06:29:14 pmParallel and series is a way of describing wiring. The diode is in parallel with the relay because both sides of the relay are connected to both sides of the diode. The transistor is in series with the relay because only one side of the transistor is connected to only one side of the relay.QuoteCurrent flows "downhill", following a voltage gradient. When the transistor is on the current can't flow through the diode because 5 V is "higher" than the bottom of the relay. The other side of the transistor is "lower" than the bottom of the relay at 0 V, so the current flows that way.QuoteSee 1.QuoteThe relay is indeed "on" in the second diagram when the transistor is off and the current is flowing through the diode. But notice this state only lasts for a tiny fraction of a second. After that the current decays and the relay opens.

author: Phoenix
author_rank: Frequent Contributor
timestamp: July 05, 2015, 01:03:15 am
content: Quote from: SEnergy on June 30, 2015, 07:45:59 pmThe brown wire from the NPN to ground connects to the blue strip on the bottom of the breadboard. You need to jumper that blue strip accross to the other part of the blue strip along the bottom.

author: SEnergy
author_rank: Contributor
timestamp: July 05, 2015, 11:42:49 am
content: Quotedoes it matter how many electronic components are in series, when the end and start of their "chain" is connected with end and start of another one? e.g. if I would add (just randomly throwing stuff) DC Motor and a capacitor before the diode, they'd all be in parallel with relay, right?QuoteI still am confused - I read this sentence like 10 times and I still can't understand what you meant by that (also what is gradient? translator translates it as "increase", which is weird), also you said it can't go thru the diode because 5V is "higher" than the bottom of the relay - but the diode doesn't need 5V to power on, the current needed for diode to work is lower, so it should go there, right? for some reason I think you mean the "point" right after the source, where cathode of diode is connected - I meant the point where relay is connected to the anode, as shown hereand I still can't (for any reason) understand why the current can't flow thru the diode AND transistorQuotethis case is after I turn off the transistor and the voltage it still in there, however when I don't even turn on the transistor, just connect everything as its supposed to be (with 3V3 source turned off) - it doesn't send any current to the relay as the circuit is not completed? (there's just a relay-diode loop, but there's no ground) ... do I get that right?QuoteI thought the whole red/blue strips are connected, didn't know they are separated in the middle

author: Hideki
author_rank: Frequent Contributor
timestamp: July 05, 2015, 01:42:58 pm
content: The diode looks a bit like an arrow, right? Current through the diode will only flow in the direction of the arrow, not in reverse. So in order for the diode to do anything at all, the voltage at the anode that you circled must be HIGHER than the voltage at the cathode. The cathode is fixed at 5V.When the transistor turns off, the current through the relay coil can not instantly fall to zero because it has set up a magnetic field that keeps "pushing" the electrons through the wire. With nowhere to go, the voltage across the coil will quickly rise as high as it needs to go in order to maintain the same current as before.Without the diode in place, how high the voltage goes depends on many factors, including how quickly the transistor turns off. 50-100V is quite possible, and over time that will easily damage small transistors that are not rated for such high voltages.With the diode in place, it does nothing at all in normal operation, but when turning off, the voltage at the anode only gets to about 5.7 volt (compared to ground), or 0.7 volt across the diode before the it starts conducting. Ground is not connected, so this loop is as you say only through the diode and coil. The energy is wasted as heat in the coil and diode, so even though there will be some milliseconds of delay, the relay will eventually turn off.

author: Zero999
author_rank: Super Contributor
timestamp: July 06, 2015, 11:40:06 am
content: Quote from: SEnergy on July 04, 2015, 06:29:14 pmThe transistor is in series with the relay.The diode is in parallel with the relay.QuoteBecause the diode only conducts is one direction.QuoteWhen the transistor is turned off, the current simply continues to flow through the relay coil, until the energy is dissipated.QuoteThe relay does turn off eventually as the energy is dissipated in the resistance and the diode but it doesn't happen immediately.

author: rs20
author_rank: Super Contributor
timestamp: July 06, 2015, 02:22:15 pm
content: For smaller loads up to 5A or so, the other classic solution is optotriac + triac, like the example circuits inthis datasheet.