Tutorial 3: DC motor Speed Control through LabVIEW and Arduino: In our previous article we have seen how to program Arduino with LabVIEW. We write our first program in which we controlled LED connected on pin 13 of Arduino UNO board with a push button created in LabView. In today’s tutorial we will go a step ahead and see how to control speed of DC motor through LabView and Arduino. We will start building VI from scratch and then control the speed as well as direction of DC motor from LabVIEW graphical user interface. If you do not know about labview, I suggest you check this post on Getting started with labview and arduino with labview
Hardware and software required for this project are as follows.
Components for dc motor speed control with labview
5V rating is necessary so that we can directly power it from power supply available at Arduino board. If you use a motor with high current and voltage rating you will have to modify the motor driving circuitry a little bit.
This motor driver is a specially designed chip for direction control of motor. You can you Arduino Shield for this purpose which already has such integrated chips. But you will have to modify the code in case you use the shield instead of chip.
- Jumper Wires
- Arduino interacing for LabVIEW
If you have not installed these softwares, you can refer to previous tutorial.
In this section we will show step by step process to wire the circuit.
- Put motor driver L293D chip in the bread board. It should be placed in middle. So that both sides of pins are not shorted.
Here is the pin configuration of motor driver L293D.
- Connect pin number 8 and pin number 16 with 5V supply.
- Connect pin number 4 or 5 with ground of 5V.
- Connect Arduino pin number 4 with pin number 7 of L293D.
- Connect Arduino pin number 5 with pin number 2 of L293D.
- Connect Arduino pin number 6 with pin number 1 of L293D.
- Connect pin 3 of L293D with motor one terminal.
- Connect pin 6 of L293D with motor other terminal.
After this we are done with circuit of this project, now we can move to next step that is software par in LabVIEW.
LabVIEW Program to Control the Speed and Direction of DC Motor:
In this section we will write LabVIEW Program to control the speed and direction of DC motor.
- Start the LabVIEW.
- Creat Blank VI as in Tutorial 1.
- Go to LabVIEW “Block Diagram” Panel
- Right Click on white space. Go to “Arduino” and select “init”. This will add Initializations of Arduino board.
- First input is “VISA resource”. It is the serial port you are using for interfacing of Adruino. You can find it in “device manager” of your computer under “ports (COM & LPT)….” Make sure Arduino board is connected with computer otherwise it won’t be shown. In my case it is COM4.
- Bring cursor on first input of “Init” until it shows “VISA resource”. Right click on it. Go to “create” and select “constant”. As it will be a constant value of Port which will be always used for serial communication.
- Click on arrow it will show available option. In my case its “COM4”. Select appropriate one after checking from device manger as mentioned above otherwise it won’t work.
- Second input is “Baud Rate”. Create it as constant as done for “VISA resource”. Right click on “Baud Rate” then “create” and then “constant”.
- Third input is “Board Type”, fourth is “Bytes per packet” and fifth is “Connection type” make them also constant.
- Draw a rectangle on LabVIEW “Block Diagram” and click on red color round icon “loop condition” Create a constant by right clicking on it. I will show a “STOP” icon on diagram.
- Place 2 “Digital Write Pin” and 1 “PWM Write Pin” Block as follows.We need 2 digital write pins to control direction of motor in 2 different directions (left and right). PWM pin will be used to control the speed of Motor.
- This process results in following LabVIEW Block Diagram.
- Click on white space on “Block Diagram” and follow “Arduino → Low Level → and select Set Digital Pin”
- Place “Set Digital Pin” on “Block Diagram”. Place such 3“ Set Digital Pin” block on “Block Diagram”. This results
- Join the above diagram as shown below. You can take help from previous tutorial.
- Further, join the blocks as shown in diagram. We also need two more “close” block. You also need to place them. For PWM input we create control as done previously and for all other inputs we create constants.
- Now Start Ardunio IDE.
- Click “File” then “Open” and Follow as shown. Go through all these folders from “Computer” onward and open LIFA_BASE Arduino file.
- Upload the program opened in Arduino IDE using Arrow button on top of Arduino IDE.
- Once uploading done close the Arduino IDE. It’s very important to close Arduino IDE because both LabVIEW and Arduino are using COM4. If not closed LabVIEW will not be able to communicate and LabVIEW will crash.
- Now go to Front Panel in LabVIEW and run the program in toolbar menu of LabVIEW.
- When we right 1 at the place of “direction1”. Motor rotates in one direction. When we right 1 at the place of “direction2”, motor rotates in other direction. Be careful, when dong this, do not make “direction1” and “direction2” 1 simultaneously. Both should direction controls should not be 1 at once. If one direction control is 1 other should be 0. Otherwise, L293D will get damage permanently. One more thing to note is that speed should be somewhere between 0 to 255, otherwise motor will not rotate.
- By varying speed between 0 to 255 we can see motor speed varies. At 0, motor is stop and at 255 it rotates at maximum speed.