Making an h bridge circuit, makes a real messy circuit. Its also hard and time consuming to select the appropriate rated transistors or mosfets(h bridge can also be made with fet’s) for the circuit needs. Pre assembled and manufactured h bridge circuits are available in market and they also came in ic’s. L293d is popular half h bridge ic available in market.
L293d motor driver
L293d has two half h bridge channels. Each channel can control a single motor independently. We can control two motors with a single l293d motor driver. Each channel can control loads requiring 0 – 36 volts and 600 mA of current. Each channel has two input and two output pins. Our load(motor) is connected across output pins of channel. Controls are connected to input pins. Each channel is activated through an enable pin. To learn more about individual channel internal structure, each pin function and l293d operation requirements i recommend you take the below tutorial.
Dc motors speed can be control through various methods. The most popular is by varying the input voltage to the motor. I am also going to vary the input voltage to dc motor for speed control of dc motor. Input voltage can be varied using a variable resistor. Like in homes we rotate the knob at switch port to control the speed of roof fan. By rotating the knob we vary the input power(voltage,current) to fan.
In our case we want to control the speed digitally not physically(fan knob case discussed in above paragraph). Digitally controlling the dc motor speed is possible by switching on and off the motor control system. Since we are using a microcontroller nodemcu in our project so we must be switching on and off the system which is controlling the motor. We are using l293d motor driver in our project and our motors are connected across its channels output pins. If we switch on and off the individual channels of l293d we can vary the output voltage to motor and hence we can control the motor speed.
In a pulse width modulation signal output the duty cycle of the signal is controlled. Duty cycle is the amount of time the signal is high in a given one period of digital signal. On the right hand side duty cycles are shown diagrammatically. In the first wave duty cycle is 50 %. It means that the signal is high for 50 % of the period. For example period is 2 seconds. With 50 % duty cycle the output remains high for 1 second and low for 1 second. If duty cycle is 75 %. Output remains high for 1.5 seconds and low for 0.5 seconds. Hope it makes sense to you. When periods are combined it makes frequency. And usually its in kilo or mega Hz.
- GPIO-15 with Input-1 of l293d
- GPIO-13 with Input-2 of l293d
- GPIO-12 with Input-4 of l293d
- GPIO-14 with Input-3 of l293d
To control the speed of motors i am generating a pwm signal on GPIO-5 and GPIO-4 of nodemcu esp8266. Each l293d channel enable pin is supplied the generated pwm signal for controlling the motor rotation speed. Connect
- GPIO-5 with ENABLE-1 of l293d
- GPIO-4 with ENABLE-2 of l293d
Vss of l293d is supplied +5 volts. Vs of l293d is supplied the motor operating voltage +12 volts in our case. Both the l293d and nodemcu grounds must be common in order for circuit to work properly.
In the code first i included the library the ESP8288WiFi.h. This library contains the nodemcu core initialization functions. Then SSID and Password of the WiFi network is entered. You must enter your WiFi SSID and Password first before moving a head.
const char* ssid = “Your SSID”;
const char* password = “Your Wifi Password”;
When nodemcu started its server. It started serving the web page. Just make the circuit and upload the above code in your nodemcu.
After uploading the code in nodemcu open the arduino serial monitor from your arduino ide. In arduino serial monitor you will see the nodemcu requesting the WiFi router for IP allotment and then starts its server. When server is fully operational nodemcu will output the server address on arduino serial monitor. This address is the HTML address of the motor controls web page. One has to enter this address in browser of his device(mobile, desktop or laptop). You can see the serial monitor snap shot on the right hand side.
- Button Start Motor
Will start rotating the motor 1 and 2 in clock wise direction.
- Button Toggle Direction
Will toggle direction and starts rotating motors in anti clock wise direction. In order to bring back to clock wise press Start Motor again.
In loop function nodemcu is waiting for any request from client. If request is made nodemcu performs the desired function in client request and before closing the request nodemcu replies with the updated status of the dc motor.
I showed you how to control the dc motor speed with nodemcu WiFi module and l293d h bridge motor driver. In my project one can select only three duty cycles. For future you can insert a text field and submit button in web page and accept the custom duty cycle from user through key board. There are many more possibilities to enhance the project functionality by making RC car, robot etc.
Filed Under: Electronic Projects, ESP8266, Microcontroller Projects