Go Down

### Topic: Arduino controlling relay question (Read 1 time)previous topic - next topic

#### goPlayYourGuitar

##### Jun 21, 2011, 04:01 am
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.

#### retrolefty

#1
##### Jun 21, 2011, 05:14 am
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

#### johnwasser

#2
##### Jun 21, 2011, 05:24 am

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.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

#### cr0sh

#3
##### Jun 21, 2011, 06:17 am

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).

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

#### goPlayYourGuitar

#4
##### Jun 21, 2011, 02:04 pm
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!

#### Grumpy_Mike

#5
##### Jun 21, 2011, 02:21 pm
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.

#6
##### Jun 21, 2011, 03:23 pm
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!

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up