Using the module

This is page 10 of 10 of a how-to on how to build an outlet/relay module. The main project page is here.

Conceptually, using the module is straight-forward. Plug the thing to be turned on into an outlet. Connect a microcontroller output pin to one of the signal pins. Connect the other signal pin to ground. Plug the module's power cord into a wall. When the output pin turns on, the device turns on.

For some microcontrollers, it may be as simple as that. According to the spec sheet, the relay I used has a coil resistance of 100 ohms +/- 10%. At 5 volts, the amount of current required is 5V divided by 100 ohms, which equals 0.05 amps, or 50mA. Some microcontrollers are capable of providing this much current. I believe the Prop-1 and Guilderfluke devices are examples of these, and they have the necessary diode protection built in, too. Other microcontrollers, such as PICs, will need some help to trigger the relay. That help will be in the form of a transistor, plus a diode across the emitter and collector pins of the transistor to protect the transistor from the voltage spike generated when the coil of the relay is de-energized. The schematic below worked for me when I tried it.

relay control schematic

The relay that we are trying to control is at the top of the diagram. One of the signal pins gets voltage directly from the power source. In my case, that is 5V, so that is what I showed in the diagram. The other signal pin of the relay is connected to the collector of the transmitter. On the 2N2222 transistor I used, this was the left-most pin, where I consider the flat side of the transistor package to be the back, and the round side is the front. The emitter of the transistor (the right-most pin) is connected to ground. A 1N4001 diode is placed across the collector and emitter to deal with the voltage spike. Be sure that the stripe on the diode is connected to the collector. Resistor R1 is a 10K resistor between the base (middle pin) of the transistor and ground. This is a pull-down resistor. This makes sure that when the output pin from the microcontroller is off, the base of the transistor is definitely at ground, which means that the relay is off. Resistor R2 is a current-limiting resistor between the microcontroller output pin and the base of the transistor. A value of 1K worked for me, but I would recommend testing it with your components yourself. I am no expert at circuit design. You may find that you need a lower value for R2. When I measured the current going from the micro output pin to resistor R2, my meter read 4.7mA, so just about any micro should be able to handle that.

Back to the previous step - Final Testing
Back to my how-to index
Back to my Halloween index

Page last modified 05/18/2011