Login

Interface a BO DC motor with NodeMCU using H-bridge

Objectives

  • Run a DC motor using NodeMCU and H-bridge
  • Control direction of motor.

Things

  1. NodeMCU board (quantity: 1 no.)
  2. Micro USB cable A to B (quantity: 1 no.)
  3. Breadboard (quantity: 1 no.)
  4. DC BO motor (quantity: 1 no.)
  5. DC barrel jack (quantity: 1 no.)
  6. 12V DC adaptor (quantity: 1 no.)
  7. Jumper wire – male to male (quantity: 2 no.)
  8. Jumper wire – male to female (quantity: 2 no.)
  9. Arduino IDE on your computer

Let’s begin!

A DC motor is an actuator that rotates when supplied with DC power. When a voltage is applied across its terminals, it rotates. Usually DC motors come in a compact geared set, called BO motors.

 

 

BO DC motor

 

Unlike sensors which can be powered by the NodeMCU itself, a DC motor requires additional circuitry to be powered simply because the NodeMCU on it’s own cannot provide adequate current to run the motor. To overcome this limitation, we use a ‘motor driver’. This device’s main function is to power the motor using an external high current source and to also provide a communication pathway to convey control signals from the NodeMCU to the motor. We use a H-bridge motor driver to perform these functions.

A H-bridge circuit is the name given to a set of electronic switches built into an IC. L293D is an example of such an IC. By controlling which switches are closed/open, we can control the polarity of voltage obtained at the output.

 

H-bridge

 

Usually two switches are controlled by one input pin. Since there are four switches, we have two input pins on the IC – IN pin1 and IN pin2.

  • When we give HIGH to IN pin1 and LOW to IN pin2, switches S1 and S4 close and switches S2 and S3 open. This completes the circuit and current flows in one direction, causing the motor to rotate in one direction.
  • When we give LOW to IN pin1 and HIGH to IN pin2, switches S1 and S4 open and switches S2 and S3 close. This completes the circuit and current flows in the opposite direction, causing the motor to rotate in the opposite direction.
  • When we give LOW to both IN pin1 and IN pin2, all switches are open and no current flows. If the motor is rotating, it slows to a stop.
  • When we give HIGH to both IN pin1 and IN pin2, all switches are closed and there is no voltage difference between motor terminals. Hence, no current flows. If the motor is rotating, it slows to a stop.

 

The H-bridge circuit comes as a well packaged module. It can control 2 motors at the same time. Each motor can be controlled by 2 inputs. The inputs are designed such that if Input 1 is given high voltage, S1 becomes closed and S2 becomes open; if Input 1 is given low voltage, S1 becomes open and S2 becomes closed. Similarly, Input 2 controls S3 and S4.

Interfacing a BO DC motor with NodeMCU using H-bridge

 

Interfacing a BO DC motor with NodeMCU using H-bridge

 

Final Code

To copy the code, right click on view raw at the bottom of the code, click on open link in new tab and then copy the code.

Takeaway

Loader Loading...
EAD Logo Taking too long?
Reload Reload document
| Open Open in new tab

We would love to see what you build out of these learnings!

Click here to submit your projects, share it with the world and stand a chance to be rewarded.

top

Knowledge and Content by Li2 Technologies | © 2021 NASSCOM Foundation | All rights reserved

X