Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help with arduino controlled relay

Status
Not open for further replies.

theigmo87

New Member
I'm pretty new to this, but I recently purchased an arduino, hoping to connect it to my garage door and open it when i signal it to. I have found many diagrams online, but one that I decided on is this:

View attachment 64436

the arduino outputs 5v and a 40 mA current from the digital pin, and I will connect the relay to the 5v power source from the board as well. I found a relay I want to get, here:

https://www.radioshack.com/product/index.jsp?productId=2062480

As you can see, its a 5v relay. the contact capacity is 24 vdc which is what i need, coil current is 90mA, and the coil resistance is 55 ohm. I think this should be fine to open the garage door.

I bought a 1n4148 diode whose datasheet can be found here:

https://www.electro-tech-online.com/custompdfs/2012/05/1N4148_1N4448.pdf

and a 2n3904 transistor whose datasheet can be found here:

https://www.electro-tech-online.com/custompdfs/2012/05/2N3904.pdf

I bought these as this is what the writer of the first blog with the diagram suggested.

Instead of just hooking it up as his diagram says, I want to know why he picked each part, and I am a beginner at this. Can someone help me out?
 
The diode is there to clamp the inductive "kick" from the relay when you turn it off. Without it the voltage at the collector of the transistor might be to high. You can google clamp diode or flyback diode for more info.

The transistor is one that can switch up to 200 ma. So it is large enough for your realy at 90 ma.

The 1K resistor limits the base current to a little less than 5 ma. It could be a little smaller - like 470 ohms as the transistor only has a gain of 10 when it is turned on as hard as possible. So 470 ohms would give about 9 ma of base current which will make sure the transistor is turned on hard.

The 10K resistor is really not needed but will make sure the transistor is turned off when the micro is not connected or if it's output is floating..
 
Last edited:
The 10K resistor is really not needed but will make sure the transistor is turned off when the micro is not connected or if it's output is floating..

I've switched relays in this manner with arduino before. I had lots of relay chatter (especially when AC got near it) until I put the pulldown resistor in. However, I was using a TIP120 Darlington.
 
The 1K resistor limits the base current to a little less than 5 ma. It could be a little smaller - like 470 ohms as the transistor only has a gain of 10 when it is turned on as hard as possible. So 470 ohms would give about 9 ma of base current which will make sure the transistor is turned on hard.

how did you get the base current to be a little less than 5ma? and the gain is abbreviated as hfe correct? reading the datasheet under the hfe section, did you take the ratio of Ic and the min value to get the value of 10?

The 10K resistor is really not needed but will make sure the transistor is turned off when the micro is not connected or if it's output is floating..

Again, I'm just trying to understand this completely so I can do it myself later, but I still don't see how that 10k resistor will make sure its off. could you explain a little more? Thanks for the help.
 
how did you get the base current to be a little less than 5ma?
The output of the micro will be a bit less than 5 volts and the Vbe drop of the transistor is about .7 volts so 4.3/1000 = 4.3 ma.

the gain is abbreviated as hfe correct? reading the datasheet under the hfe section, did you take the ratio of Ic and the min value to get the value of 10?

hfe is specifies with 1 volt from collector to emitter, so you might only have 4 volts for your relay. Saturation is usually when base current is 1/10 of collector current and then the Vce drop is about .3 volts. (Page 2 of the datasheet)



I still don't see how that 10k resistor will make sure its off.

The transistor will start to turn on when the voltage on the base is .6 or .7 volts. The output from the micro in the low state is probably around .2 volts so the 10k probably serves no purpose. But should the micro be disconnected the base will be what I call floating. In this case a small bit of noise could turn on the transistor. The resistor to ground helps prevent this.
 
when arduino output is high, you get some 5V. 5V/1kOhm=5mA
Actually Vbe=0.7V or similar so the better approximation is Ib=(5V-0.7V)/1k=4.3mA

hfe or beta is ratio of Ic/Ib and for many small signal (general purpose) transistors it is in the range of 100.
but we are not looking for analog operation of transistor, we need this to work as a switch so Vce is small and relay gets most power.
this means driving transistor into saturation and there it is usually assumed (just rule of thumb) that gain is ~10.
so 4.5mA*10=45mA. but if the relay current is 90mA, then we need to either make sure that transistor has sufficient gain or we need to increase base current to something closer to 9mA.
9mA*10=90mA. to get higher base current, we cannot increase output voltage of the arduino GPIO but we can reduce 1k resistor to 470 Ohm for example.
(5-0.7)/470 = 9.15mA
 
Status
Not open for further replies.

Latest threads

Back
Top