The Relay requires a few other components to provide enough power to trip the relay coil (transistor) and a diode across the relay coil to protect the transistor from any back EMF that could be caused by the relay coil.
The relay will be controlled by a pin on the microcontroller. Since the microcontroller will not allow a draw of current that the relay coil will need, a transistor will be needed to switch on a higher current supply. The higher current supply is just the 5v that is powering the circuit. On of the pins of the transistor is connected to the pin of the microcontroller. This pin will have a resistor between the pin and the transistor (base). When the pin is high, the transistor will allow current to pass through the other two pins (collector and emitter).
The relay coil is connected to this part of the transistor so when the pin is high, the relay coil will fire. Since the coil can create back EMF, the coil will have a signal diode across the coil to keep any current from hitting the transistor.
First, we need to determine the current the relay will draw (ohm's law) to determine the minimum current rating of the transistor we wish to use:
We know that the resistance of the relay coil is 25 ohms from the relay datasheet.
I = V/R
= 5v/(25 ohms)
= .2 Amps or 200 mA (milliamp)
Next, the current gain rating (Hfe) for the transistor needs to be determined:
Hfe must be 5 times the load current divided by the current from the microcontroller pin. The microcontroller can output 40 mA from the port pin (found in the microcontroller datasheet).
Hfe = 5 x (loadCurrent/PinCurrent)
= 5 x (.2 amps / .04 amps)
= 5 x (5)
= 25
So, the transistor must have a rating above 25.
The final consideration is to determine the resistance value that must be added between the pin and the base pin of the transistor. We can use a special formula since the voltage from the pin will be the same as the voltage going through the collector and emitter.
Resistance = CurrentOfCircuit x ResistanceOfRelayCoil x HfeOfTransistor
= .2 amps x 25 ohms x 200
= 1000
So a 1k resistor will work.
The diode that will be placed across the coil of the relay will be a diode rated at 1 amp since there is only .2 amps on that part of the circuit. The diode will be a 1N4001 signal diode.
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.