This tutorial of Robo India explains how to control speed of DC motor with PWM Signals using L293D IC Motor Driver. (By Robo India)
1. Introduction
The Motor Driver is a module for motors that allows you to control the working speed and direction of two motors simultaneously .This Motor Driver is designed and developed based on L293D IC.
L293D is a 16 Pin Motor Driver IC. This is designed to provide bidirectional drive currents at voltages from 5 V to 36 V.
1.1 PWM Signals
The DC motor speed in general is directly proportional to the supply voltage, so if reduce the voltage from 9 volts to 4.5 volts then our speed become half of what it originally had. But in practice, for changing the speed of a dc motor we cannot go on changing the supply voltage all the time. The speed controller PWM for a DC motor works by varying the average voltage supplied to the motor
The input signals we given to PWM controller might be an analog or digital signal according to the design of the PWM controller. The PWM controller accepts the control signal and adjusts the duty cycle of the PWM signal according to the requirements. These diagram below shows the waveforms obtained as output at different voltage requirements
In these waves frequency is same but the ON and OFF times are different.
2. Hardware required
S.No. | Item | Quantity |
1 | NodeMCU | 1 |
2 | Motor Driver | 1 |
3 | DC Motor | 2 |
4 | Female to Male Jumper wire | 10 |
5 | 6 x AA Battery | 1 |
3. L293D IC Pin Out
The L293D is a 16 pin IC, with eight pins, on each side, to controlling of two DC motor simultaneously. There are 4 INPUT pins, 4 OUTPUT pins and 2 ENABLE pin for each motor.
Pin 1: When Enable1/2 is HIGH, Left part of IC will work, i.e motor connected with pin 3 and pin 6 will rotate.
Pin 2: Input 1, when this pin is HIGH the current will flow though output 1.
Pin 3: Output 1, this pin is connected with one terminal of motor.
Pin 4/5: GND pins
Pin 6: Output 2, this pin is connected with one terminal of motor.
Pin 7: Input 2, when this pin is HIGH the current will flow though output 2.
Pin 8: VSS, this pin is used to give power supply to connected motors from 5V to 36V maximum depends on Motor connected.
Pin 9: When Enable 3/4 is HIGH, Right part of IC will work, i.e motor connected with pin 11 and pin 14 will rotate.
Pin 10: Input 4, when this pin is HIGH the current will flow though output 4.
Pin 11: Output 4, this pin is connected with one terminal of motor.
Pin 12/13: GND pins
Pin 14: Output 3, this pin is connected with one terminal of motor.
Pin 15: Input 3, when this pin is HIGH the current will flow though output 3.
Pin 16: VCC, for supply power to IC i.e 5V.
4. Connections with NodeMCU
1. Module 5V (VCC) – NodeMCU Vin.
2. Module GND – NodeMCU GND.
3. Module 1 – NodeMCU D3.
4. Module 2 – NodeMCU D2.
5. Module 3 – NodeMCU D1.
6. Module 4 – NodeMCU D0.
7. Module EN12 – NodeMCU D6.
8. Module EN34 – NodeMCU D5.
9. Module Motor terminals – DC motors.
10. Module VSS power terminal- External power source of 9V.
Connection with NodeMCU
Make sure that the Jumpers are preset on the Enable 1-2 and Enable 3-4 pins of module, so that motor will be enabled and work at maximum speed.
Connection with NodeMCU using PWM Signals
Make sure to remove the Jumper preset on Enable pins of module, so that we can connect PWM input to this pin and control the speed of motors. If we connect these pins to ground , then the motor will get disabled.
Make the connection as shown above.
5. Programming1:
Here is the code to run this circuit.
You may download this code (Arduino Sketch) from here.
// Robo India //Tutorial on L293D IC Motor Driver with NodeMCU // http://roboindia.com/tutorials/ //Motor A const int inputPin1 = 5; // Pin 15 of L293D IC const int inputPin2 = 16; // Pin 10 of L293D IC //Motor B const int inputPin3 = 4; // Pin 7 of L293D IC const int inputPin4 = 0; // Pin 2 of L293D IC void setup() { pinMode(inputPin1, OUTPUT); pinMode(inputPin2, OUTPUT); pinMode(inputPin3, OUTPUT); pinMode(inputPin4, OUTPUT); } void loop() { digitalWrite(inputPin1, HIGH); digitalWrite(inputPin2, LOW); digitalWrite(inputPin3, HIGH); digitalWrite(inputPin4, LOW); }
6. Output-1
After uploading the first code you can see both motors get start rotating with maximum speed.
7. Programming2:
Here is the code to control the motors with PWM signals..
You may download this code (Arduino Sketch) from here.
// Robo India //Tutorial on L293D IC Motor Driver using PWM Signals // http://roboindia.com/tutorials/ //Motor A const int inputPin1 = 5; // Pin 15 of L293D IC, D1 Pin of NodeMCU const int inputPin2 = 16; // Pin 10 of L293D IC, D0 Pin of NodeMCU //Motor B const int inputPin3 = 4; // Pin 7 of L293D IC, D2 Pin of NodeMCU const int inputPin4 = 0; // Pin 2 of L293D IC, D3 Pin of NodeMCU int EN1 = 12; // Pin 1 of L293D IC, D6 Pin of NodeMCU int EN2 = 14; // Pin 9 of L293D IC, D5 Pin of NodeMCU void setup() { pinMode(EN1, OUTPUT); // where the motor is connected to pinMode(EN2, OUTPUT); // where the motor is connected to pinMode(inputPin1, OUTPUT); pinMode(inputPin2, OUTPUT); pinMode(inputPin3, OUTPUT); pinMode(inputPin4, OUTPUT); Serial.begin(9600); Serial.println("Enter values between 0 - 255"); } void loop() { if(Serial.available()) { int speed = Serial.parseInt(); Serial.println(speed) analogWrite(EN1, speed);//sets the motors speed analogWrite(EN2, speed);//sets the motors speed digitalWrite(inputPin1, HIGH); digitalWrite(inputPin2, LOW); digitalWrite(inputPin3, HIGH); digitalWrite(inputPin4, LOW); } }
8. Output-2
After uploading the program 2, open the Serial Monitor and send the input values to Arduino. You can control the speed of the DC motor by sending different values between 0 -255.
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team
Robo India
https://roboindia.com