When developing a robotics project, motors are one of the most important parts of the overall project, and more than one motor is always required. But the GPIO pins of the microcontroller board don’t allow you to draw the amount of current the motor needs. This is why motor driver ICs are used. You can build a motor driver circuit by using some electronic components, or you can build an almost ready solution, a motor driver shield.

In this DIY tutorial, we will build a NodeMCU Motor Driver Shield to drive a DC motor. This motor driver shield includes an L293D motor driver IC, a 6-pin switch for power on/off, an LM7805 regulator for regulating 5V, and some extra pins for sensors, relays, etc.

Components required for NodeMCU Motor Shield:

Node MCU

L293D motor driver IC

7805 voltage regulator

Capacitors (1×0.1µf, 1×0.33µf, 1×10µf)

1× 220Ω resistor

16-pin IC base

2 x screw terminals

1× LED

1× DC power jack female

NodeMCU motor driver shield circuit diagram

The complete schematic of the L293D Motor Driver Shield is shown below. The schematic diagram is drawn using EasyEDA.

This motor driver shield consists of a L293D motor driver IC, a 6-pin switch for power on/off and an LM7805 regulator for regulating 5V. It can control two DC motors. NodeMCU digital pins D3 and D4 are connected to the left motor and digital pins D5 and D6 are connected to the right motor. Additionally, this shield has additional header pins for sensors, relays, or other devices.

Fabricate PCB for NodeMCU Motor Driver Shield

After the schematic is complete, we can move on to laying out the PCB. You can use any PCB software of your choice to design the PCB. We have used EasyEDA to fabricate the PCB for this project. You can view any layer of the PCB (Top, Bottom, Topsilk, bottomsilk, etc.) by selecting the layer from the Layers window. In addition to this, you can also get a 3D model view of the PCB to see how it will look after fabrication. Below is a 3D model view of the top and bottom layers of the Pi Motor Driver HAT PCB.

Assembling the NodeMCU Motor Driver Shield PCB

The top and bottom layers of the board are shown in the figure below:

After making sure the tracks and footprints are correct. I proceeded to assemble the PCB. The fully soldered board looks like this:

NodeMCU motor driver code description

In this project, we are programming NodeMCU to simultaneously drive two DC motors in forward, reverse, left and right directions at two second intervals. The full code is given at the end of the document. Here we will explain some important parts of the code.

Start the code by defining the pins that connect to the motor pins. Here I have connected input 1 of motor A to D3, input 2 to D4, input 1 of motor B to D5 and input 2 to D6.

const int inputPin1 = D3; const int inputPin2 = D4; const int inputPin3 = D5; const int inputPin4 = D6;

In the setup() function, define all four pins of Motor A and Motor B as outputs.

void setup(){ pinMode(inputPin1, OUTPUT); pinMode(inputPin2, output); pinMode(inputPin3, OUTPUT); pinMode(inputPin4, OUTPUT);}

Next, inside the loop() function, simultaneously drive the two DC motors in forward, reverse, left and right directions at two second intervals. The following table shows the input pin state combinations for the motor direction:

void loop()

{ //forward digital write(input pin 1, high); digital write(input pin 2, low); digital write(input pin 3, high); digital write(input pin 4, low); delay(2000); //remaining digitalWrite(input pin 1, low); digitalWrite(input pin 2, low); digitalWrite(input pin 3, high); digitalWrite in(input pin 4, low); delay(2000); //correct digitalWrite(inputPin1, high); digitalWrite(inputPin2, low); digitalWrite(inputPin3, low ); digitalWrite(input pin 4, low); delay(2000); // undo digitalWrite(input pin 1, low); digitalWrite(input pin 2, high); digitalWrite( inputPin3, low); digitalWrite(inputPin4, HIGH); delay(2000); //stop digitalWrite(inputPin1, low); digitalWrite(inputPin2, low); digitalWrite(inputPin3, low); digitalWrite(input pin 4, low); delay(2000); }

Testing the NodeMCU Motor Driver Shield

After completing the PCB assembly, upload the code to NodeMCU, then mount the L293D IC and NodeMCU on the driver shield. If all goes well, the DC motor connected to the NodeMCU will move left, forward, right and reverse simultaneously every two seconds.

//Motor A
const int inputPin1 = D3;
const int inputPin2 = D4;
//Motor B
const int inputPin3 = D5;
const int inputPin4 = D6;
void set()
{
pinMode(inputPin1, OUTPUT);
pinMode(input Pin2, output);
pinMode(inputPin3, OUTPUT);
pinMode(inputPin4, OUTPUT);
}
void loop()
{
//forward
digitalWrite(input pin 1, high);
DIGITALWRITE(INPIN 2, LOW);
DIGITALWRITE(INPIN 3, HIGH);
DIGITALWRITE (INPIN 4, LOW);
delay(2000);
//remain
digitalWrite(input pin 1, low);
DIGITALWRITE(INPIN 2, LOW);
DIGITALWRITE(INPIN 3, HIGH);
DIGITALWRITE (INPIN 4, LOW);
delay(2000);
//correct
digitalWrite(input pin 1, high);
DIGITALWRITE(INPIN 2, LOW);
digitalWrite(inputPin3, LOW);
DIGITALWRITE (INPIN 4, LOW);
delay(2000);
// undo
digitalWrite(input pin 1, low);
DIGITALWRITE(INPIN 2, HIGH);
digitalWrite(inputPin3, LOW);
digitalWrite(inputPin4, HIGH);
delay(2000);
//stop
digitalWrite(input pin 1, low);
DIGITALWRITE(INPIN 2, LOW);
digitalWrite(inputPin3, LOW);
DIGITALWRITE (INPIN 4, LOW);
delay(2000);
}

Leave a Reply

Your email address will not be published.