Updated 24 September 2020
Kits and Gadgets Electronics Inc.
Farwaniya, Kuwait 80003
Kuwait
ph: +965 99571844
kits
The schematic diagram below is the simplest way of connecting a DC motor to NodeMCU. It is not possible to connect or drive directly the motor using the NodeMCU due to several reasons. Although some DC motors work even below 3.3 Volts, the variable current and the noise involve when driving a motor may damage the NodeMCU.
Also, since we want to operate the motor with reverse and forward motion or CW / CCW, it is not possible using only the ULN2803 driver IC. Thus, we need to use two relays or a motor driver IC to enable such functionality.
In the diagram, the motor supply terminals are either connected to POSITIVE or GROUND polarity of the supply line depending on whether the relays are active or not. Two signals from NodeMCU are needed to achieve the needed function of the motor.
The program below can easily be modified to change the direction and the speed of the motor by just changing the state of GPIO and the delay value.
DIAGRAM
PHOTO-SHOT
VIDEOS
PROGRAM
/* Experiment No.10
By: Rolando Estomaguio
Radar Specialist - Electronics Engineer
http://www.kits-gadgets.com
Objective: To learn the operation of NodeMCU and utilize its full functionality.
Title: Motor Drive Interface
Description: Drives the motor forward and reverse using two GPIOs.
*/
// Using GPIO5 and GPIO4 to drive the motor through ULN2803
void setup() {
// initialize digital pin 5 and 4 as an output.
pinMode(05, OUTPUT);
pinMode(04, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(05,HIGH); // connect the motor positive terminal to B+
digitalWrite(04,LOW); // connect the motor negative teminal to GROUND
delay(2000); // wait for two seconds
digitalWrite(05,LOW); // connect the motor positive terminal to GROUND
digitalWrite(04,HIGH); // connect the motor negative terminal to B+
delay(2000); // wait for two seconds
}
Copyright 2013 Kits and Gadgets Electronics Inc. All rights reserved.
Kits and Gadgets Electronics Inc.
Farwaniya, Kuwait 80003
Kuwait
ph: +965 99571844
kits