1. What is a relay?
A relay is a electromechanical device. In simple words it's a combination of electromagnet and a mechanical switch. The electromagnets magnetic field operates the switch. When the internal electromagnet gets supply it turns on the switch and when the supply is cut, it turns off the switch. The switch in relay is a toggle switch also known as single pole double through (SPDT). The advantage of SPDT is that, we get COM(common), NO (normally open) and NC (normally close) contacts which are very usefull in circuit design. The below given image shows the bottom view of a relay along with the pin function.
The below given circuit images show how to connect the load to relay and how to turn it on and off.
![]() |
Coil is not provided 5V , relay is off, load is not getting supply. |
![]() |
Coil is provided 5V, relay is on, load is getting supply. |
Once we know how to operate a relay the next thing is to turn on a relay by microcontroller but that's not as easy as directly connecting the 5V ouput pin to relay because the pin can supply only limited current.
2. How to operate relay on digital signal from a microcontroller or IC?
Relay requires current greater than 40mA to operate. The maximum current that can be drawn from microcontroller's pin is limited to 40mA. That means if we connect a output device that draws current above 40mA then it's for sure that the microcontroller is going to get damaged. To increase the current we need to amplify the current and that can be done using NPN type transistor. The role of a transistor in this case is not only to amplify the current but also switch ground to relay, as the transistor is switching only ground the VCC (DC power supply voltage) for relay can be set depending on DC operating voltage of a relay. I am using a 5V relay in my circuit. The transistor also provides isolation between the relay circuit and microcontroller circuit. If you need more isolation then you can use opto-isolators, but a single transistor just works fine and gets the job done. Refer the below given circuit diagram.
![]() |
5V Relay module using BJT BC547 (NPN type) |
The diode is connected in reverse bias accross the relay coil , that is to provide path for the reverse high voltage spike. To know more about reverse high voltage spike click here
You can even connect a led in series with a resistor to the output of transistor to indicate that relay is on.
3. Drawback of using BJT transistor BC547 as switching device. Why to replace it with MOSFET?
In BJT transistor there is current flow from base of transistor to emitter. So the pin on which the transistor is connected will read LOW (0V) this can cause false triggering of some functions if the pin has multiple functions in some microcontrollers (for eg- esp8266). To avoid that you can replace the transistor BC547 with 2N7000 N-channel mosfet. There will be only few changes in circuit like:-
1. emitter replaced by source.
2. base replaced by gate.
3. collector replaced by drain.
4. Pull down resistor of 100K from gate to source.
Refer the circuit given below:-
![]() |
Circuit diagram of relay module with MOSFET |
4. YouTube video
- Now you know how to make a relay module and get a relay wired quickly with a microcontroller or any IC.
- If you find this blog usefull. Subscribe to my YouTube channel , Twitter.
- If you have any doubts regarding this blog you can contact me through my email Id - prachethire@gmail.com
If you found this blog useful and want to support me, then you can donate me. The money you give will be used to make more advance electronics projects and setting up better lab.

No comments:
Post a Comment