This tutorial of Robo India explains how to control motor using relay on NodeMCU.
1. Introduction:
A relay is an electro mechanical switch. It is used for switching high current devices that cannot be switched by transistor. Relay consists one electromagnetic coil and three terminals for switching. One among these three terminals is a common terminal that floats between other two terminals. These two terminals are Normally Close (NC) and Normally Open (NO) terminal.
In normal condition (power is not supplied to relay’s coil) the Common terminal remains connected to the NC terminal. When a power is supplied to the relay’s magnetic coil, it generates magnetic force. This force detaches common terminal from the NC terminal and connects the common terminal to the NO terminal. The relay returns to its original condition as soon voltage supply stops.
The common terminal switches between the NO & the NC terminals.
1.2 Hardware required
S.No. | Item | Quantity |
1 | NodeMCU | 1 |
2 | Breadboard | 1 |
3 | LED | 1 |
4 | Resistor 1k | 2 |
5 | Jumper Male to male | 12 |
6 | nPn Transistor | 1 |
7 | 5V Dual Pole Relay | 1 |
8 | 5V DC motor | 1 |
9 | Diode | 1 |
2. Building Circuit
Schematic of circuit
Layout of circuit
3. Programming:
Once the circuit part is done, NodeMCU is needed to be programmed. Here is the code to run this circuit on NodeMCU.
You may download this code (Arduino Sketch) from here.
// Robo India Tutorials //Simple code for control Motor //Hardware: NodeMCU const int motor = 4; //Motor connected with D2(GPI04) of NodeMCU void setup() { pinMode (motor, OUTPUT); } void loop() { digitalWrite (motor, HIGH); delay(1000); digitalWrite (motor, LOW); delay(1000); }
4. Output
The code is same as earlier chapter Switching Using Transistor. The Motor rotates for 1 second and then stops, remains stopped for 1 second. This loop continues .
5. Troubleshooting
LED is glowing but motor is not spinning: Check polarity of Relay. If this did not work, try to listen click sound when LED glows. This click sound means the relay is perfectly working. A computer’s USB power supply may not supply adequate current, it is recommended to use external power supply.
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team
Robo India
https://roboindia.com
How to interface two dc motors controlled seperately without repeating the whole circuit?