Pages: [1]   Go Down
Author Topic: Arduino controlling relay question  (Read 981 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I've done a bunch of research on how to control a relay with the Arduino.  My relay draws about 60 mA and needs 5v.  According to the arduino uno page, there is 40 mA at each digital output pin.  So I rigged up a couple circuits on a breadboard following these:
http://www.rason.org/Projects/bipolamp/bipolamp.htm
http://www.rason.org/Projects/transwit/transwit.htm
I used 2n3904, 2n3906 and 2n5088 transistors and no matter what I do, the arduino is still drawing about 60 mA of current.  I simply do not understand this.  The only thing I have been doing that I feel is questionable is using only the 5 volts from one arduino pin to power the whole transistor circuit.  Is it necessary to use two separate power supply's?  Or if anybody could guide me to maybe a few pages that helped them understand these concepts, I would appreciate it so much.  As usual, thanks in advance.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the arduino is still drawing about 60 mA of


Drawing 60ma, measuring where? If the relay requires 60 ma it will draw that no matter what. If you mean the output pin is sourcing 60 ma, then you don't have the proper size base resistor wired to the transistor.

Perhaps a simple drawing showing your specific circuit and where you are measuring the current would be helpful to see if you have a problem or not.

Lefty

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8975
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This article from Make Magazine shows how it is done:

http://blog.makezine.com/archive/2009/02/connecting-a-relay-to-arduino.html

It's OK for the relay to draw 60 milliamps from the 5V supply.  You just don't want to draw 60 milliamps from a digital output pin.  The transistor draws a little current from the digital output pin to switch a larger current through the relay coil.

The diode across the coil protects the transistor and Arduino from the high reverse voltage spike induced in the coil when the magnetic field collapses.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 42
Posts: 5612
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This article from Make Magazine shows how it is done:

http://blog.makezine.com/archive/2009/02/connecting-a-relay-to-arduino.html

It's OK for the relay to draw 60 milliamps from the 5V supply.  You just don't want to draw 60 milliamps from a digital output pin.  The transistor draws a little current from the digital output pin to switch a larger current through the relay coil.

The diode across the coil protects the transistor and Arduino from the high reverse voltage spike induced in the coil when the magnetic field collapses.

Regarding that: Power your relay off an external voltage supply (make sure to hook up the supply's ground to the Arduino's ground, though); an extra 60 mA from the on-board voltage regulator isn't much, but that regulator is mainly meant to power the Arduino only, and not a whole mess of external components (one relay and the interface circuitry probably isn't going to kill it, but if you start adding more, sooner or later you're going to start reseting the Arduino from voltage/current sags - best to avoid it altogether).

smiley
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, this is making some sense now that I'm not all tired and frustrated.  To lefty, I did mean the output was sourcing 60 mA.  Also I wasn't using the 5v pin on the Arduino so I don't know why I expected it not to draw 60 mA.  I need to provide constant power to a few relays, actually eight, with the 5v pin and then turn them on individually with the digital output pin.  That will work.  Thanks John for that article.  Thanks guys!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34726
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
According to the arduino uno page, there is 40 mA at each digital output pin.
Many people think the output is limited to this, it is not. The limit means that you must arrange things so that you don't exceed this, if you do draw 40mA or more from a pin then you damage the arduino. Even 40mA if sustained will damage things. The best bet is if you limit things to 30mA per pin, but you have to do this by arranging the load. You can if you want get a lot more than 40mA from an arduino pin but you do cause permanent damage to the chip doing so.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If one reads the ATMega datasheet, one can see that Hi/Lo levels are only certain to be met at 20mA.
Para 29.2, Table 29.1
Voh @ Vcc = 5V, 20mA load = 4.2V
Vol @ Vcc = 5V, 20mA load = 0.9V

At higher currents, the output voltage are likely to degrade as well:

"If IOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current
greater than the listed test condition."
"If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater
than the listed test condition."

Keep those current limiting resistors handy!

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: