Arduino relay control - Why the resistor and transistor?

I am a complete beginner to electronics and microprocessors and am designing a project that uses an Arduino to switch a kitchen appliance on/off and also to control a linear actuator.

I've got a big SSR to switch the appliance and a small one for the actuator which operates on 12 VDC at 50mA.

I've been looking at some schematics for circuits that feature Arduinos controlling things like solenoids and have notices that the circuits always seem to include a resistor and a transistor.

I thought the whole point of using a relay was that it allowed you to switch relatively large currents using small control voltages so I'm surprised that a transistor would be necessary. So why can't you just control the relay directly with the Arduino?

Also, in the attached schematic there is also a resistor - what is its purpose?

Will I need to design separate circuits like this to control both of my relays?

Thanks.

Some relays can be controlled with 5V and <35mA of current so the arduino pin can drive them directly.

Other relays need more current, or a higher voltage, so a transistor is needed to switch that higher current.

The base of an NPN transistor looks like a diode to ground. The resistor limits the current to keep the arduino pin from being damaged.

(5V - 0.7V)/35mA = 123 ohm, so use something like a standard 150 ohm resistor to turn the transistor on full, and protect the arduino output pin.

Thanks Crossroads.

So the Arduino is limited to an output of 5V @ 35mA?

vanchopski:
Thanks Crossroads.

So the Arduino is limited to an output of 5V @ 35mA?

Technically, individual pins of the ATMega328 are limited to 40mA @ 5V (HIGH), but you never want to hit this "absolute maximum" amount; so you should limit to something lower than this. 35mA to me seems like cutting it close; I would actually limit things to something even lower in a design (especially if you are using more than one pin; more on this in a moment) - maybe 20-25mA. If you are using more than one pin, though, the ATMega328 (IIRC) is limited to a total output of 200mA @ 5V (thus, if you limited your current draw on all pins to 20mA each, you could "turn on"/"set HIGH" up to 10 of them at one time).

Well a lot my Seniors CrossRoads and Crosh have defined already.
but on following:

So the Arduino is limited to an output of 5V @ 35mA?

I want to say that it's a lot(the current), always the Micro-ontrollers which ever you take up whether they are picaxe(another nice forum backed microcontroller) also the many others like PIC, Parallel Propeller etc all supply current nearby this level only, The thing they are there to process the code made by you and then achieve the final result via. supporting circuitry the same you are doing now giving resistance and diode and a relay to handle high current stuff.
Not only Microcontroller/Microprocessor's work like this other sort of IC's also call for supporting circuitry to achieve a goal.

So the Arduino is limited to an output of 5V @ 35mA?

I think one reason begineers have difficulty understanding about output pin current 'limits' is the very use of the word limit. I think many think the output pin can (or should) self 'limit' itself to it's 40ma max value, which of course it can't. The word limit as used by the specification, is a value the user must insure that their external circuitry does not attempt to draw more then that specified current 'limit' as doing so will cause higher then rated current to flow and thus subject the pin and chip to damage.

Lefty

That's a good point - often bad names persist for historical reasons, abs. max limits are really "thresholds of permanent damage", and are the counterpart of parameters like "breaking strain" in physical components (and not "safe working loads").

The recommended/safe current draw for each Arduino pin is rated at 20 mA IIRC.

I typically use a 220 Ohm resistor driving the gate of a BS170 MOSFET as a low end switch for switching purposes. It works great when the load is <= 500 mA. I love the BS170 -- I bought a hundred for a pittance at Digi-Key and it's almost time to re-order :slight_smile:

Once turned on (or off,) there will be almost no current draw out of the BS170, so you never have to worry about pin limits or trying to saturate a device, like you would for a bipolar transistor.

No, 20mA is the max a pin can sink or source and still meet it rated output voltage levels.
Above that current, the voltage may start to rise (sinking current) or droop (sourcing current).
And above 40, good chance the output pin will fail.

Most of my design, I prefer using a transistor switch circuit to control multitud of led's, relays, etc. My raison is this question :

Which parts you prefer to fail ?

A ... Microcontroller
B... transistor

If you choose A. You have money & time to burn. ]:slight_smile: If you choose B. You are wise. :grin:

That is my raisoning.

Please note also that (notes on the datasheet's table 30-1):

1] The sum of all IoH , for ports C0 - C5, D0- D4, ADC7, RESET should not exceed 150mA.
2] The sum of all IoH , for ports B0 - B5, D5 - D7, ADC6, XTAL1, XTAL2 should not exceed 150mA.

1] The sum of all IoL , for ports C0 - C5, ADC7, ADC6 should not exceed 100mA.
2] The sum of all IoL , for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 100mA.
3] The sum of all IoL , for ports D0 - D4, RESET should not exceed 100mA.

Just an observation. You say in your post:

I've got a big SSR to switch the appliance and a small one for the actuator which operates on 12 VDC at 50mA.

I hope you have an SSR for the appliance and a relay for the actuator, as SSRs are for AC only. You cannot control DC with a SSR.

A few more observations is that this is a very old thread and a search at DigiKey results in 3,256 hits for controlling DC or both AC & DC with SSRs.

@dlloyd

You're right. Didn't notice that it was a Lazarus thread.

Yes, there are 'SSRs' that will control DC but I have always known and spoke of them as optoisolators. Technically these are SSRs but in my experience SSR is reserved for AC. Different parts of the world often have terminology differences.