dc motor control with labview and Arduino



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



dc motor speed control with Labview and Arduino

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.

  • Breadboard
  • Jumper Wires

Software Requirements:

  • LabVIEW
  • Arduino interacing for LabVIEW

If you have not installed these softwares, you can refer to previous tutorial.

Wiring Diagram:

In this section we will show step by step process to wire the circuit.

  1. 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.

  1. Connect pin number 8 and pin number 16 with 5V supply.
  2. Connect pin number 4 or 5 with ground of 5V.
  3. Connect Arduino pin number 4 with pin number 7 of L293D.
  4. Connect Arduino pin number 5 with pin number 2 of L293D.
  5. Connect Arduino pin number 6 with pin number 1 of L293D.
  6. Connect pin 3 of L293D with motor one terminal.
  7. 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.

  1. Start the LabVIEW.
  2. Creat Blank VI as in Tutorial 1.
  3. Go to LabVIEW “Block Diagram” Panel
  4. Right Click on white space. Go to “Arduino” and select “init”. This will add Initializations of Arduino board.

  1. Bring Cursor to anywhere in LabVIEW “Block Diagram” panel and place the “Init”.
  1. 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.
  2. 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.
  1. 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.
  2. Second input is “Baud Rate”. Create it as constant as done for “VISA resource”. Right click on “Baud Rate” then “create” and then “constant”.
  3. Third input is “Board Type”, fourth is “Bytes per packet” and fifth is “Connection type” make them also constant.
  1. Click on white space on LabVIEW “Block Diagram” and follow “Structure → select While loop”.
  1. 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.
  2. 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.

Similarly place second “Digital Write” and For “PWM Block” follow. Place “PWM write pin” Block on LabVIEW “Block diagram” panel.

  1. Place “Close Block” as follows.
  1. This process results in following LabVIEW Block Diagram.
  2. Click on white space on “Block Diagram” and follow “Arduino → Low Level → and select Set Digital Pin”
  1. Place “Set Digital Pin” on “Block Diagram”. Place such 3“ Set Digital Pin” block on “Block Diagram”. This results
  2. Join the above diagram as shown below. You can take help from previous tutorial.
  3. 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.
  4. Now Start Ardunio IDE.
  5. Click “File” then “Open” and Follow as shown. Go through all these folders from “Computer” onward and open LIFA_BASE Arduino file.
  1. Upload the program opened in Arduino IDE using Arrow button on top of Arduino IDE.
  2. 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.
  3. Now go to Front Panel in LabVIEW and run the program in toolbar menu of LabVIEW.
  4. 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.
  5. 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.



Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,395 other subscribers