Menu Close

NodeMCU Controlling motor through on Arduino IDE

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.ItemQuantity
1NodeMCU 1
2Breadboard 1
3LED 1
4Resistor 1k 2
5Jumper Male to male 12
6nPn Transistor 1
75V Dual Pole Relay 1
85V DC motor 1
9Diode 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


1 Comment

Leave a Reply