Handy Tips - Relays

 

    Why use another chip to control outputs? Well the answer to that is that the PIC can only supply up to  25mA. This is fine for logic levels, and even small devices like LED's, but you can't drive a relay, motor, piezo siren etc with a PIC..

    The ULN2003 is a very cost effective chip that acts like a switch. It simply switches an earth to/from an external circuit, and can withstand a continual 500mA current drain and a maximum 50V. All this for $0.47 AUD.

    Internally the ULN2003looks like this;

    The relays +Ve voltage must be connected to Pin 9 to protect Back EMF, and the common ground is connected to Pin 8. This is the ground supplied to the external circuits when switched on. As you can see there are 7 channels per chip, to control a relay, hook up a circuit like this, and be sure to connect Pin 8 of the ULN2003 to ground);

ULN2003 and Relay

    You don't need the ULN2003 to control a relay/load that the PIC can't drive on its own. You can use a transistor like the following example (note that there are now 3 external components instead of 1);

Note the PIC's power supply/oscillator are not shown

Click here too see this circuit in action!

    Now whenever the output of the PIC goes high, an earth is instantly supplied to the relay, the coil will energize. Note the diode, this is to negate back EMF (Built-in on the ULN2003), and is vital in inductive circuits like these.

    The benefit of the diode is that it provides a low voltage-drop path for the current induced by the collapsing magnetic field to follow, thereby preventing the build-up of a destructively high voltage on the coil winding and/or the switch contacts. With the absence of the diode, the voltage will rapidly build up on the coil until something brakes down, allowing the energy to dissipate. That breakdown could be by damaging arcing across the switch contacts or by punching through the insulation on the coil wires, leading to eventual failure.

 

Where you can get the components;

 Skip Navigation Links.

Collapse Site Tutorial IndexSite Tutorial Index
Expand 16F PIC Examples16F PIC Examples
Expand 18F PIC Examples18F PIC Examples
Collapse Handy TipsHandy Tips
Collapse High Power SwitchingHigh Power Switching
FET's (N-Channel)
FET's (P-Channel)
ULN2003
Relays
Transistors
Zener Diodes
Photocoupler
OpAmps
Expand Serial CommsSerial Comms