Build a Relay-Driver Circuit or Uni-directional Motor Controller
Today we are building a relay-driver circuit to allow a Raspberry Pi or Arduino to activate the relay we built last week. You could also use this device to run a DC motor in one direction.
This relay-driver circuit uses the 3.3V from the Raspberry Pi's GPIO pins to activate 12V for the relay. The relay circuit then uses that 12V to switch the AC power on or off.
The driver circuit uses NPN power transistors salvaged from a CRT television. These transistors are actually quite similar to the mechanical relay we built last week: Once activated by a small voltage they allow a large voltage from another source to flow through your circuit.
The transistors I am using are actually overkill for this project. They are rated at about 160V at 3 Amp, which isn't much lower than the relay itself. I want the option of using this device as a motor controller and with heat-sinks it can definitely run most DC motors.
To keep things simple I am focusing on a single transistor circuit. To build a dual circuit simply duplicate the first circuit.
As usual I am using salvaged parts where possible. You will need the following components.
An NPN transistor
Most transistors will work fine for this project. The main consideration is the voltage and current required to activate the transistor. If you are using salvaged parts like me, you can sometimes find a data sheet on the Internet to determine the requirements.
I built my circuit on a breadboard first and tested the transistors thoroughly. It pays to test them actually powering the load you plan to use, in this case the relay. This way you know the transistor is opening fully.
If you wish to use this unit to drive large motors you may need to use a heat-sink to keep the transistor cool.
A PCB board
You can buy 10 of these boards from this Ebay seller for $1.40.
A resistor and a diode
I used a 1400 Ohm resistor for R1 between the 3.3V input and the base pin on the transistor.
The diode protects against spikes that occur when the relay switches. Most diodes will work, I just used what I had. I think it was an 1N4004. To drive large motors you may need something with a higher rating.
I used header pins for the input and output of my unit. I have plenty of double-ended cables from inside TVs that can use these pins to neatly connect the relay to the matching pins on the relay-driver board. Screw terminals may be better for the output.
Below is the breadboard diagram to test the transistor. Don't use your Raspberry Pi for the initial test. If you have made a mistake in your circuit you may fry your Pi. Use a 3.3V power supply instead of the Pi's GPIO and GND pins. Once you know the circuit works you can try it with the Pi.
You can see that the load sits between the 12V+ on the power supply and the collector pin(pin2) on the transistor. The emitter pin(pin3) connects to GND. The 3.3V input(from the Raspberry Pi) connects through R1 to the base pin(pin1).
When you send 3.3V to the base pin, the transistor connects the collector and the emitter, allowing the 12V power through the transistor via the relay.
Now to put it together
I generally bend the legs of these transistors to achieve a staggered stance. This gives you more space between the pins and makes soldering the connections a lot easier. The bent legs also help to hold the transistor in place while soldering.
Below is the PCB diagram for the circuit.
The 12V+ input goes to the first header pin at the top of the board. The adjacent header connects to the collector pin (pin2). These two header pins will connect to positive and GND on your relay or motor.
The lower-left header pin (The Raspberry Pi's GPIO) connects through R1 to the base pin (pin1). The lower-right header pin connects to the 12V GND. This is the main GND connection for the circuit. The Pi's GND pin also plugs into this header.
The emitter pin (pin3) connects to GND. D1 connects from GND to the collector (pin2). Note the orientation of the white ring on D1 in the diagram above. This is important.
Testing the unit
First plug your top headers on your relay-driver board to the headers on your relay board.
Plug the 12V wires from the relay-driver board to your 12V power supply. Connect the GND from a 3.3V power supply to the lower-right GND header pin. Connect the positive wire from the 3.3V power supply to the lower-left header pin.
Turn on your 12V power supply but leave the 3.3V supply off. Nothing should happen, the relay should not activate.
Now turn the 3.3V power supply on. You should hear the relay activate and the LED on the relay board should light.
You can now try it with your Pi or Arduino.
Where to next?
We have now built a relay board and a relay driver circuit to power it. In the next article I will share the code required to run them.
There are two more builds in the initial range of hardware. We now have movement-sensors, light-sensors, relays and relay/motor drivers. Next we'll build a temperature sensor. Then we need an enclosure to put all this stuff, and a power supply to run it.
There are currently no comments for this article.