samedi 24 août 2013

Control a 12v relay with Arduino & Raspberry Outputs

To control a 12v relay from an output of a microcontroller, you just need a resistor, a NPN transistor and a diode ... and a relay of course !

Here's a sample :


The R1 value is generally 1K but it should be adapted to the microcontroller (output current/voltage) and the transistor.
The 2N2222 is a general purpose transistor and a lot of NPN transistor can be used.
The D1 diode is very important : it avoid current feedback on switching, don't forget it or you can damage the microcontroller !
The relay (K1) should be a 12V coil, but the switching load should be adapted to your need ! if you need to switch a 1A lamp, it is not the same as a 20A heater !

The 12v can be different depending on your need, it can vary from 5V to 24V,  but i don't recommand to go over 24V with this schematic (and especially with the 2N2222 which as a Vce max of 30V)... at higher voltage a optocoupler is prefered ... but it depends on the switching speed you need !