View Single Post
Old 05-26-2018, 12:07 PM   #4
dmjlambert
Senior Member
 
dmjlambert's Avatar
 
Join Date: Apr 2016
Location: Cypress, TX
Posts: 3,584
Re: Any electronics nerds interested in Arduino/Atmel?

It looks like the guy in that video is driving the relay directly. I think that is using the Arduino's processor beyond the specs and may damage it. So you have the right thinking about using a transistor to drive the relay.

2N3904 is a common transistor and good to use in that situation. I like this web page for explanation of using a transistor for this.

http://www.ermicro.com/blog/?p=423

It also has the wiring for connecting a relay, and talks about a clamp diode (aka flyback diode) when driving an inductive load.

Getting into this, although it is not really possible to grasp everything that is in a datasheet unless you're an engineer, it is good to read them anyway. I had a manager a while back who encouraged me to read technical stuff, and he said you won't get it all at first, and you may never get it all, but each time you expose yourself to it you will gain a little more. Now a few years later, I agree. Google "datasheet 2n3904" or "datasheet atmega328p" to find and download the PDF manuals for the various components you will be working with. The atmega328p is the controller chip in an Arduino. At the very least those data sheets will show you what pins are what on the component. After you buy a 2N3904 transistor, you are going to need to know which pin is the base, which is the emitter, and which is the collector.

So, to just get down to the nuts and bolts of it, here is a doctored diagram from that ermicro blog I gave the link to above.
Name:  dr.png
Views: 574
Size:  47.0 KB

You don't need a resistor in line with the relay, because the coil of the relay provides the correct resistance if you are connecting a 12V relay to your truck. 1N4001 is a common diode you can use as a clamp diode. And a 220 ohm 1/4 watt resistor is a common value to use to limit the current going from an Arduino pin to the base of the transistor.

You can get this stuff on aliexpress.com if you are patient about delivery from China. bags of 50 transistors, a few hundred assorted values of resistors, bag of diodes, breadboard, etc. each for a couple bucks with free shipping.

Last edited by dmjlambert; 05-26-2018 at 12:09 PM. Reason: spelling
dmjlambert is offline   Reply With Quote