Connect a Relay to a Digital Output
This How-to is intended for:
OSC Users, Electronics Hackers
Purpose
Connect a relay to the MC, this will allow you to switch higher voltages on and off discretely.
Prerequisities
You will need the controller with the digitalout subsystem activated.
Also you will need 4 or 5 pin relays
What is a Relay?
A relay is an electromechanical device that connects to a low voltage and controls a higher voltage discretely. A relay has two low voltage connections. One that is ground, and the other is the signal that you send from the MC. This voltage activates a small electromagnet inside the relay that moves a magnetized "heavy duty" switch inside the relay. The advantage here is that there is no direct electrical connection to your MC. so it is very difficult to fry your board.
Relays come in several flavors, but the most common and basic are 4 and 5 pin relays.
When pin 2 has sufficient voltage applied to it, the internal switch will flip up to contact from pin 3 to pin 4. Otherwise it will either be floating (as in the 4 pin relay) or it will be connected to pin 5 (as in the 5 pin relay). These pins are known as the always connected(3) normally connected(5) and normally open(4). Typically you will attach your positive higher voltage to pin 3 and select where it is directed to (pin 4 or 5) depending on whether you send a high signal from your MC or not.
Step by step
Choosing an adequate relay is the most important part of the setup. When you are looking at relays, the most important concerns are:
1. Can the MC output enough current/voltage to turn it on
2. Is the relay robust enough to handle the load I'll be attaching.
Usually the MC will have no problem turning the relay on and off, particularly if you buy one from a hobby shop or Radio Shack. The second concern is more important. It would not be wise to connect a tiny relay up to a high voltage line, for example. So use caution and be sure to read the specifications of the relay.
Also take care when using high-inductive loads such as heavy-duty motors. Inductive loads like to keep sucking current even after contact has been broken. This may result in sparks, which could cause problems.
Connect the relay as shown above, and you should be able to turn things on and off quite easily. You should hear a click whenever the switch moves back and forth insid the relay. If you don't get the response you want, the relay may be polarized, in which case you should switch the + and - connections you have made from the MC to the relay.
Relays are basically inductors, and as such they do use a fair amount of current, if you'd like to keep things low power, consider attaching a resistor between the MC and the relay as shown below:
This will reduce the flow of current through your relay, but is not necessary. Experiment with larger resistances until you find one that is large, but still allows you to activate your relay.
Further information
wikipedia.org: relay
Shopping Cart