Servo Motor Control using Arduino
Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to tell you about how to design an algorithm for
Servo Motor Control using Arduino. First of all I would like to tell you a bit about the servo motors. Servo motors are small devices having an output shaft. We can adjust this shaft in different angular positions by continuously sending the servo coded signal. Servo motor maintains the angular position of the shaft as long as the coded signal is present at the input. If the applied coded signal changes, angular position of the shaft of a servo motor also changes correspondingly. If you are working on Servo Motor then i would suggest you to must have look at this tutorial
Servo Motor control in Proteus, as its always a best practice to design simulation first.
In my previous tutorials I have controlled the direction and speed of the both DC as well as of the stepper motor. Ordinary DC motor has only two input terminals. When power is supplied it simply starts to rotate continuously. In comparison to the DC motor servo motor has three wires. Using servo coded signal we can send commands to the servo motor that in what direction and with what angle it has to rotate. If we want to add motion in our electrical projects, servo motor will be an easy way to do so. Servo motor has a wide range of applications in our daily life e.g elevator, cars, robotics, puppets, remote controlled airplanes and cars, conveyor belts, solar tracking system, antenna positioning, textiles etc.Moreover, I have also controlled the
Servo Motor with PIC Microcontroller, so if you are using PIC Microcontroller then have a look at that one.
Servo Motor Control using Arduino
In the tutorial
Servo Motor Control using Arduino, I will tell you step by step procedure for connecting the servo motor with Arduino and how to design a algorithm in Arduino software to control its angular position with the help of servo coded signal. First of all I would like to tell you about the hardware components necessary for Servo Motor Control using Arduino.
- You can download the complete Arduino source code here by clicking on the button below.
- Just download .rar file, extract it and enjoy the complete source code.
Hardware Required
A complete list of the hardware equipment necessary for this task is given below.
- Computer/Laptop
- Arduino UNO (Micro Controller)
- Appropriate USB Cable
- Servo Motor (4.8 to 6.0V with 2.5 kgf-cm torque)
- Jumper Wires (Cables)
Arduino UNO acts as the backbone of this task. It sends the servo encoded signal to the servo motor to control its angular movement. Arduino UNO board is shown in the figure below.
Servo Motor having torque of 2.5kgf-cm and 4.8-6.0v is used for this project. The selected servo motor is shown in the figure below. Power of 5V is supplied to the servo motor from the Arduino UNO board.
Jumper Wires are used to make the connections of the all the components in order to make the complete circuit with proper working. Jumper wires are shown in the figure below.
Circuit Diagram
- The circuit diagram for Servo Motor Control using Arduino is shown in the figure below.
- I have supplied 5V to red wire of the servo motor as shown in the above figure.
- The black wire is the attached to the GND pin of the Arduino UNO.
- Yellow wire is basically the wire used to control the angular motion as well as the angle of the servo motor.
Source Code Description
- The complete Arduino source code for Servo Motor Control using Arduino is given below.
- You have to just copy the code given below and to past it in your Arduino software.
- By uploading the source code to your Arduino board you will be able to control the servo motor using Arduino.
#include <Servo.h> //library for servo motor
Servo myservo; // servo motor object for its control
int ang = 0; // a variable to store the servo angle
void setup() {
Serial.begin(9600);
myservo.attach(8); // servo motor is attached to pin no 8 og Arduino
}
void loop() {
for (ang = 0; ang <= 180; ang += 5) // goes from 0 degrees to 180 degrees with a step og 5 degree
{
myservo.write(ang); // rotates the servo to rotate at specific angle
delay(50); // adding delay of 50 msec
Serial.println("Motor has started its rotation from 0 to 180 degress");
}
for (ang = 180; ang >= 0; ang -= 5) // goes from 180 degrees to 0 degrees with a step of 5 degree
{
myservo.write(ang); // rotates the servo to rotate at specific angle
delay(50); // adding delay of 50 msec
Serial.println("Motor has started its rotation from 180 to 0 degress");
}
}
- First of all I have inserted the library for servo motor.
- Then I have created a servo object and declared the initial angle of the servo motor.
- After that I have have adjust the baud rate, the rate at which Arduino communicates with the laptop/computer.
- Then I have defined the pin at which the servo motor is attached to the Arduino UNO's board.
- Inside the main loop, I have applied the condition that in between 0 and 180 degrees, the servo motor's angle will be increased with different steps and each step has 5 degrees of angular movement.
- When maximum limit is reached, the angle will be reduced from 180 to 0 degree with different steps, each step having 5 degrees of angular movement.
- That was the brief description of the Arduino complete source code designed for Servo Motor Control using Arduino.
That is all from the tutorial Servo Motor Control using Arduino. I hope you all have enjoyed this tutorial. If you face any sort of problem you can ask me freely in comments any time you want without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. I will explore Arduino by making different projects on it and will share all of them with all of you as well in my later tutorials. Till then, Take care :)
DC Current Sensor ACS712 Arduino Interfacing
Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge with all of you guys about
DC Current Sensor ACS712 Arduino Interfacing. First of all, I would like to tell you about importance of current sensing/measuring. Sensing the amount of current passing through any circuit can be useful in a lot of applications. For example, in low power consuming equipment, current sensing will be helpful to understand the system's impact on its battery life. The current sensing can also be used to make the decisions regarding safety in over current protection circuits.
Simply, we can say that sensing and controlling the flow of the current through the circuits is now a fundamental requirement e.g. over current protection circuits, battery chargers, watt meters, power supplies etc.
DC Current Sensor ACS712 Arduino Interfacing
Basically, there are two types of current senors
AC and DC. But, in the tutorial,I am going to do the
DC Current Sensor ACS712 Arduino Interfacing, and we will learn about the sensing of the DC current. I will use
ACS712 DC current sensor for sensing the DC current.
- You can download the complete Arduino source code there.
- Download .rar file, extract it and upload code in your Arduino board:
Components Required
Here I am going to tell you about the components necessary for this projects. The list of all the components is given below.
- Arduino UNO
- DC Current Sensor (ACS712)
- DC Load
- Wero Board
- Soldering Iron
- Soldering Gum
- Jumper wires
- Power Supply (12V)
- 20 x 4 LCD
Description of the Components used
[ultimate_spacer height"10"]
In this section of the tutorial Interfacing DC Current Sensor with Arduino, I will explain the reasons why I have used the specific components for this project.
- Arduino UNO acts as the back bone of the project. It manipulates the whole source code uploaded to the board, prints the desired data on the serial monitor and also prints the executed commands on the LCD. You can use the same code of other Arduino boards as well i.e. Arduino Nano, Arduino Pro Mini etc.
- Power Supply of 12V is used to turn the entire system ON. Because, we can not test and verify our system until we have not switched it ON. Power supply used for this project is shown in the figure. I have used this 9A Battery (I have this available) but you can use 1.5A small battery as well. Battery selection depends on your projects' power consumption.
- LCD is used to display the digital values of the data which has been printed on the serial monitor of the Arduino software i.e all the executed commands will be printed on the LCD as well. The LCD which I have used for this is shown in the figure.
- Jumper Wires are used to make the connections of the all the components, in order to make the complete circuit with proper working. Jumper wires are shown in the figure. There are 3 types of Jumper wires available: Male to Male, Male to Female & Female to Female.
- ACS712 is used to sense the Direct Current (DC) flowing through the any circuit. The DC current sensor used is shown in the figure.
Flow Chart
[ultimate_spacer height="5"]
- Here, I would like to explain the entire algorithm with the help of a flow chart for DC Current Sensor ACS712 Arduino Interfacing.
- The flow chart for this project DC Current Sensor ACS712 Arduino Interfacing is shown in the figure.
- First of all, I have initialized the Serial Port.
- After that we are reading the value from our current sensor ACS712.
- Then data will be displayed on the LCD and Serial Monitor.
Circuit Diagram
- The complete wiring diagram for this project is shown in the figure below.
- You can run this project properly, by making the circuit first, identical to the circuit diagram shown in the figure above.
- The digital pin 0 of the Arduino UNO will help us in reading the data from the sensor.
- The other two pins of the sensor are connected to the supply of 5V and ground respectively as you can see from the above figure.
Source Code Description
- The source code for this project DC Current Sensor ACS712 Arduino Interfacing is given below.
- You have to just copy and paste the code given below in your Arduino software after properly interfacing DHT11 with the Arduino.
- After uploading the code onto your Arduino board you will be able to observe the humidity and temperature and humidity level on serial monitor.
// include the library code:
#include <LiquidCrystal.h> //library for LCD
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
//Measuring Current Using ACS712
const int analogIn = 0; //Connect current sensor with A0 of Arduino
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0; //voltage measuring
double Amps = 0;// Current measuring
void setup() {
//baud rate
Serial.begin(9600);//baud rate at which arduino communicates with Laptop/PC
// set up the LCD's number of columns and rows:
lcd.begin(20, 4); //LCD order
// Print a message to the LCD.
lcd.setCursor(1,1);//Setting cursor on LCD
lcd.print("www.TheEngineering");//Prints on the LCD
lcd.setCursor(4,2);
lcd.print("Projects.com");
delay(3000);//time delay for 3 sec
lcd.clear();//clearing the LCD display
lcd.display();//Turning on the display again
lcd.setCursor(1,0);//setting LCD cursor
lcd.print("Reading Values from");//prints on LCD
lcd.setCursor(1,1);
lcd.print("DC Current Sensor");
lcd.setCursor(5,2);
lcd.print("ACS 712");
delay(2000);//delay for 2 sec
}
void loop() //method to run the source code repeatedly
{
RawValue = analogRead(analogIn);//reading the value from the analog pin
Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
Amps = ((Voltage - ACSoffset) / mVperAmp);
//Prints on the serial port
Serial.print("Raw Value = " ); // prints on the serial monitor
Serial.print(RawValue); //prints the results on the serial monitor
lcd.clear();//clears the display of LCD
delay(1000);//delay of 1 sec
lcd.display();
lcd.setCursor(1,0);
lcd.print("Raw Value = ");
lcd.setCursor(13,0);
lcd.print(RawValue);
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
lcd.setCursor(1,1);
lcd.print("Voltage = ");
lcd.setCursor(11,1);
lcd.print(Voltage,3);
lcd.setCursor(17,1);
lcd.print("mV");//Unit for the voltages to be measured
Serial.print("\t Amps = "); // shows the voltage measured
Serial.println(Amps,3);// the '3' after voltage allows you to display 3 digits after decimal point
lcd.setCursor(1,2);
lcd.print("Current = ");
lcd.setCursor(11,2);
lcd.print(Amps,3);
lcd.setCursor(16,2);
lcd.print("A"); //unit for the current to be measured
delay(2500); delay of 2.5 sec
}
- I am going to explain you that how this code is working!
- Then I have defined the library for LCD.
- I have defined the pin at which DC current sensor is attached with the Arduino board.
- Then I have defined the Arduino pins at which the LCD is interfaced.
- Then by opening the serial port I have started to print the level of temperature and humidity on the serial monitor as well as on the 20×4 LCD.
- At the end, I have added the delay of few seconds so that the speed of the data to be printed on the serial monitor can be reduced to some extent in order to observe properly.
- This was the brief description of the source code.
This is all from the tutorial DC Current Sensor ACS712 Arduino Interfacing. I hope you all enjoyed this tutorial. If you face any sort of problem you can ask me anytime in comments without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. I will explore Arduino further in my later tutorials. Till then, Take care :)
Scrolling Text on LCD with Arduino
Hello everyone! hope you all will be fine. In this article I am going to share the knowledge about displaying
Scrolling Text on LCD with Arduino. A Liquid Crystal Display is usually known as
LCD in the market. It is a display unit made up of liquid crystal. When we want to made electronics based projects, we need a device on which we can show the system’s output and the desired messages. There are a lot of such devices which are helpful to display the output messages and the most common is a seven segment display.
Alternate good option is LCD, which are now available in different size having different qualities. 16×2 LCD Module is a most frequently used device for the electronic projects out of all the other types of LCD’s available in the market. 32 ASCII characters can be displayed on it simultaneously in 2 rows i.e. it has a capacity to show 16 characters per row. 20×4 LCD, 128×64 graphical LCD and 2.4 inch TFT Touch screen LCD are also used commonly for the electronic projects now-a-days in the market and as well as in the institutions.
Scrolling Text on LCD with Arduino
In the tutorial
Scrolling Text on LCD with Arduino, we are going to learn how to interface a 16×2 lcd to Arduino UNO and how to display the scrolling text on LCD in Proteus ISIS. First I would like to write a simple code to print something on the LCD and then I will update the previously written code to scroll the text printed already on the LCD.
- You candownload the complete simulation here by clicking on the button below.
Arduino Source Code
- Just download .rar file, extract it and enjoy the complete simulation.
Interfacing 16×2 LCD to Arduino uno
LCD modules are most frequently used devices specially in Arduino based electronic projects. So it is essential to share this tutorial based on interfacing LCD module to Arduino UNO and displaying
scrolling text on LCD with all of you. Interfacing of an Arduino UNO to 16×2 LCD is elaborated in this section. The selected LCD module has 16 pins. You can operate this module in 4 bit mode by using only four data lines (from D4 to D7) or 8 bit mode by using all the eight data lines (from D0 to D7).
In this article we are using the LCD module operating in the 4-bit operational mode i.e. we are using only four data pins. I have divided this tutorial in two parts. First of all, I will explain how to display a simple text messages on the 16×2 LCD with Arduino UNO and secondly I will show that how to display
scrolling text on the same LCD interfaced with Arduino UNO. Before the explanation of this design, let’s have a look at the selected LCD. You should also have a look at this
New LCD Library for Proteus.
Designed Circuit in Proteus ISIS
Find Arduino UNO and a 16×2 LCD in the components library of proteus ISIS ISIS. If arduino library is present in your Arduino software then arduino will be shown in the components library otherwise you have to install Arduino library for proteus ISIS. Wiring diagram of the LCD module with Arduino UNO in proteus ISIS is shown in the figure below. You can download this Proteus Simulation from
Interfacing of LCD with Arduino.
- .Now just copy and paste the given source code in the Arduino software
#include<LiquidCrystal.h> //Library for LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);// LCD pins at which it is attached to the Arduino
void setup() //method used to run the source for the one time onlys
{
lcd.begin(16, 2);//LCD order i.e. 16 columns & 2 rows
lcd.print("The Engineering Projects ");//prints on LCD
lcd.setCursor(0,1);//setting cursor on LCD
lcd.print("www.TheEngineeringProjects.com");//prints on LCD
delay(1000);//delay of 1 sec
}
void loop() //method to run the source code repeatedly
{
lcd.noDisplay();//turn off the display of LCD
delay(250);//delay to 0.25 seconds
lcd.display();//turning on the LCD display
delay(250); //delay of 0.25 seconds again
}
- Now compile the source code and get hex file from it as shown in the figure below.
- Copy this address as shown in the figure above.
- Double click on Arduino UNO in proteus, a new window will be opend as shown in the figure below.
- Paste that address in the file menu as encircled in the figure below.
- Run the proteus simulation from the Arduino software from the upper left corner of the software.
- If everything goes perfect you will see the output as shown in the figure below.
- Copy and paste the source given below in your Arduino software.
#include <LiquidCrystal.h>//Library for LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//LCD pins at which it is attached to the Arudino
void setup()//method used to run the code for once
{
lcd.begin(16, 2);//LCD order
lcd.print("The Engineering Projects ");//prints on LCD
lcd.setCursor(0,1);//Setting the cursor on LCD
lcd.print("www.TheEngineeringProjects.com");//prints on LCD
delay(1000);//delay of 1 second
}
void loop() //used to run the code repeatedly
{
for(int PositionCount=0;PositionCount<13; PositionCount++)//loop for scrolling the LCD text
{
lcd.scrollDisplayLeft();//builtin command to scroll left the text
delay(150);// delay of 150 msec
}
for(int PositionCount=0; PositionCount<29; PositionCount++)
{
lcd.scrollDisplayRight(); //builtin command to scroll right the text
delay(150);//delay of 150 msec
}
for(int PositionCount=0; PositionCount<16; PositionCount++)//loop for scrolling the text
{
lcd.scrollDisplayLeft();//builtin command to scroll the text left again
delay(150);//delay of 150 msec
}
}
- Compile the code given above.
- Obtain the hex file as I told above in the figure.
- And open it in your proteus as I described above.
- Run the simulation like the I have previously done.
- You will be able to see the scrolling text on LCD as shown in the figure below.
- That all from this article to show Scrolling Text on LCD using Arduino.
- Was it difficult? I don't think so :)
So, that is all from the tutorial Scrolling Text on LCD using Arduino. I hope you enjoyed this tutorial. If you face any sort of problem, you can ask me in the comments any time. I will try my level best to solve your issues in a better way, if possible. I will explore Arduino by making different projects on it and will share them with you as well. Till then, take care :)
Stepper Motor Speed Control in LabVIEW
Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge about how to make a simple Virtual Instrument (VI) for
Stepper Motor Speed Control in LabVIEW. In my previous tutorials, I have worked on
Stepper Motor Speed Control using Arduino in which I have shown how to control the stepper motor speed using Arduino. Today, I am going to share a new tutorial in which I am gonna do the Stepper Motor Speed Control in LabVIEW. Moreover, you should also have a look at
Stepper Motor Speed Control in Matlab, where I am sending stepper motor speed control commands from MATLAB.
In this tutorial, I am going to work on the program for Stepper Motor speed Control using NI LabVIEW. So, before going into the details of this tutorial, you must go through my previous tutorials because I am going to use the same hardware setup and same Arduino source code as well. I will made a simple GUI (Graphical User Interface) for
Stepper Motor Speed Control in LabVIEW. There will be five different buttons on the GUI for clockwise rotation, counter clockwise rotation, stopping the stepper motor, accelerating and deaccelerating the stepper motor respectively.
Stepper Motor Speed Control in LabVIEW
In the tutorial Stepper Motor Speed Control in LabVIEW, I will explain you a complete step by step procedure to control the clockwise and counter clockwise direction of the stepper motor as well as accelerating and decelerating it with the help of the buttons on the GUI created in NI LabVIEW using serial communication between Arduino and NI LabVIEW.
- You can download the complete simulation for Stepper Motor Speed Control in LabVIEW by clicking below button:
Download LabVIEW Simulation
- Download .rar file, extract the files from the folder and enjoy the complete simulation for Stepper Motor Speed Control in LabVIEW.
Block Diagram
- First of all I would like to explain you the algorithm for Stepper Motor Speed Control in LabVIEW with the help of block diagram.
- Block diagram for this project is shown in the figure below.
- We send commands from the NI LabVIEW through the serial port i.e. NI LabVIEW serially communicates with the Arduino to control the speed of the stepper motor.
- Arduino sends commands to the L298 motor controller and it decides what to do after manipulating the different commands from Arduino.
- Executed commands are also printed on LCD (Liquid Crystal Diode).
Vitual Instrument's (VI's) Description
- First of all open NI LabVIEW software on your laptop or PC.
- Go to the Block Diagram window and Right Click on it.
- Go to Functions-> Instrument I/O-> Serial and you can see different serial blocks like VISA Write, VISA Read, VISA Serial etc.
- Choose the encircled VISA Configure Serial Port and place it on the Block Diagram window.
- VISA Configure Serial Port block will help us to open the Serial Port before executing the algorithm.
- The screen shot of the Block Diagram is shown in the figure below.
- Go to the first input terminal of the VISA Configure Serial Port block and go to Create-> Control.
- Above step will be helpful to select the COM port of the Arduino board in order to run the program properly.
- Updated Block Diagram window is shown in the figure below.
- Now go to Functions-> Instrument I/O-> Serial, you can see there different serial blocks.
- Choose the encircled VISA Close block and place it on the Block Diagram window.
- The VISA Close block is shown in the figure below and it will be help in closing the Serial Port if needed.
- Now, go to the Functions-> Programming-> Structures and you can see the different structures there like For Loop, While Loop, Case Structure etc.
- Choose the encircled block as shown i the figure below.
- Place all the above blocks in a way shown in the figure below.
- Now, go to the Functions-> Programming-> Structures-> Flat Sequence.
- Flat sequence block is encircled and is shown in the figure below.
- Put your cursor and go to Add Frame After.
- Similarly ad another case after this as shown in the figures below.
- Newly added frame is shown in the figure below.
- Now, go to Functions-> Instrument I/O-> Serial, you can see different serial blocks there.
- Choose the encircled VISA Write Block and place it on the Block diagram window.
- The figure shown below elaborates the above steps.
- Make the connections as shown in the figure below.
- Now, go the Functions-> Programming-> Structures and you can see different types of structures like for loop, while loop, flat sequence etc.
- Choose he encircled block as shown in the figure below.
- Select the Case Structure block and place it on the block diagram window.
- The figure shown below displays the above step.
- Now, go to the input terminal of the write block and go to Create-> Control.
- Change the name of this block to Command box as shown in the figure below.
- The block diagram window is shown in the figure below.
- Now, go to Functions-> Programming-> Structures and you can see different structures blocks there.
- Choose the encircled block as shown in the figure below.
- Select the Local Variable Block and place it on the Front Panel.
- Right click on it and select Command box as shown in the figure below.
- Go to the input terminal of this local variable and go to Create-> Constant.
- Place C inside that constant.
- The figure below elaborates the above step.
- The above case structure is for the clock wise rotation of the stepper motor.
- Similarly make four further case structures for counter clockwise rotation, accelerating, de-accelerating and stopping the rotation of the stepper motor.
- All the three case structures are shown in the figure below.
- You can see three different case structures in above figure.
- The command box variable having command C will rotate the stepper motor in clockwise direction.
- A command box variable having command A will rotate the stepper motor in counter clockwise direction.
- The command box variable having command H will rotate the stepper motor at higher and higher speed if it is rotating with a lower speed.
- A command box variable having command L will rotate the stepper motor with slower and slower speed if it is rotating at a higher speed.
- .
- The command box variable having command S will stop the rotation of the stepper motor.
- Now, go to the Front Panel and Right Click on it.
- Go to Controls-> Modern-> Boolean and you can see there different Boolean blocks.
- Choose the encircled block as shown in the figure below.
- Select the Round LED block and place it on the front panel.
- Similarly select two more round LED blocks and place them on the front panel as well.
- Change their names from default to Clockwise, Anti clockwise and Stop Motor.
- All of the above steps are explained visually in the figure shown below.
- The LED shown in the above figure will control the stepper motor on clock wise, counter clock wise direction and will stop the motor as well.
- Now go to the block diagram window and connect these blocks as shown in the figure below.
- At the end, after sending all the commands we must need to close the serial port so that unnecessary exchange of commands could be avoided.
- So I have cleared the all the commands in third frame of the case structure i.e I am sending no commands through the serial port.
- This will be helpful in closing the serial port.
- The figure show below explains all of the above steps visually.
- Now add another case structure to start the program when you want so.
- The figure below shows the newly added case structure.
- Now, go to the Front Panel, the button encircled in the figure shown below is used to start the program when needed.
- Now add a Stop button in order to terminate the program whenever you want so.
- The complete output of the program is shown in the figure below.
- A complete NI LabVIEW Virtual Instrument (VI) is shown in the figure below.
- I have decorated the front panel to make it attractive for the users.
- The final look of the Front panel is shown in the figure below.
- Go to Controls, Modern-> Decorations you can see different decoration blocks there.
- All these blocks are shown in the figure displayed below.
- I have used three decoration blocks encircled with the blue color, to decorate my program.
- Red boundary shows all of the decoration blocks to make your program attractive.
- You can also decorate your programs using this amazing tool.
That is all from the tutorial Stepper Motor Speed Control in LabVIEW. I hope you enjoyed this tutorial on Stepper Motor Speed Control in LabVIEW. If you face any sort of problem you can ask me anytime without even feeling any kind of hesitation. I will try my level best to solve your issues in some better way, if possible. I will explore NI LabVIEW, will make different projects on it and will share them with all of you as well. Till then, Take care :)
Stepper Motor Direction Control in LabVIEW
Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge about how to make a simple Virtual Instrument (VI) for
Stepper Motor Direction Control in LabVIEW. In my previous tutorial, I have worked on
Stepper Motor Direction Control using Arduino, in which I have controlled Stepper Motor Direction Control using Arduino and I am gonna use the same setup but this time I am gonna do the Stepper Motor Direction Control in LabVIEW. Moreover, you should also have a look at
Stepper Motor Direction Control using Matlab.
In this tutorial, I going to work on the program for Stepper Motor Direction Control in LabVIEW. So, before going into the details of this tutorial, you must go through my previous tutorials because I am going to use the same hardware setup and same Arduino source code as well. I will made a simple GUI (Graphical User Interface) for
Stepper Motor Direction Control in LabVIEW. There will be three different buttons on the GUI for clockwise rotation, counter clockwise rotation and stopping the stepper motor respectively.
Stepper Motor Direction Control in LabVIEW
In the tutorial Stepper Motor Direction Control in LabVIEW, I will explain you a complete step by step procedure to control the clockwise and counter clockwise direction of the stepper motor with the help of the buttons on the GUI created in NI LabVIEW using serial communication between Arduino and NI LabVIEW.
- You can download the complete NI LabVIEW simulation here.
- Download .rar file, extract the files from the folder and enjoy the complete NI LabVIEW's simulation:
Download LabVIEW Simulation
VI's Description
- First of all open NI LabVIEW software on your laptop or PC.
- Go to the Block Diagram window and Right Click on it.
- Go to Functions-> Instrument I/O-> Serial and you can see different serial blocks like VISA Write, VISA Read, VISA Serial etc.
- Choose the encircled VISA Configure Serial Port and place it on the Block Diagram window.
- VISA Configure Serial Port block will help us to open the Serial Port before executing the algorithm.
- The screen shot of the Block Diagram is shown in the figure below.
- Go to the first input terminal of the VISA Configure Serial Port block and go to Create-> Constant.
- Above step will be helpful to select the COM port of the Arduino board in order to run the program properly.
- Updated Block Diagram window is shown in the figure below.
- Now go to Functions-> Instrument I/O-> Serial, you can see there different serial blocks.
- Choose the encircled VISA Close block and place it on the Block Diagram window.
- The VISA Close block is shown in the figure below and it will be help in closing the Serial Port if needed.
- Now, go to the Functions-> Programming-> Structures and you can see the different structures there like For Loop, While Loop, Case Structure etc.
- Choose the encircled block as shown i the figure below.
- Place all the above blocks in a way shown in the figure below.
- Now, go to the Functions-> Programming-> Structures-> Flat Sequence.
- Flat sequence block is encircled and is shown in the figure below.
- Put your cursor and go to Add Frame After.
- Similarly ad another case after this as shown in the figures below.
- Newly added frame is shown in the figure below.
- Now, go to Functions-> Instrument I/O-> Serial, you can see different serial blocks there.
- Choose the encircled VISA Write Block and place it on the Block diagram window.
- The figure shown below elaborates the above steps.
- Make the connections as shown in the figure below.
- Now, go the Functions-> Programming-> Structures and you can see different types of structures like for loop, while loop, flat sequence etc.
- Choose he encircled block as shown in the figure below.
- Select the Case Structure block and place it on the block diagram window.
- The figure shown below displays the above step.
- Now, go to the input terminal of the write block and go to Create-> Control.
- Change the name of this block to Command box as shown in the figure below.
- The block diagram window is shown in the figure below.
- Now, go to Functions-> Programming-> Structures and you can see different structures blocks there.
- Choose the encircled block as shown in the figure below.
- Select the Local Variable Block and place it on the Front Panel.
- Right click on it and select Command box as shown in the figure below.
- Go to the input terminal of this local variable and go to Create-> Constant.
- Place C inside that constant.
- The figure below elaborates the above step.
- The above case structure is for the clock wise rotation of the stepper motor.
- Similarly make two further case structures for counter clockwise rotation and stopping the rotation of the stepper motor.
- All the three case structures are shown in the figure below.
- You can see three different case structures in above figure.
- The command box variable having command C will rotate the stepper motor in clockwise direction.
- A command box variable having command A will rotate the stepper motor in counter clockwise direction.
- The command box variable having command S will stop the rotation of the stepper motor.
- Now, go to the Front Panel and Right Click on it.
- Go to Controls-> Modern-> Boolean and you can see there different Boolean blocks.
- Choose the encircled block as shown in the figure below.
- Select the Round LED block and place it on the front panel.
- Similarly select two more round LED blocks and place them on the front panel as well.
- Change their names from default to Clockwise, Anti clockwise and Stop Motor.
- All of the above steps are explained visually in the figure shown below.
- The LED shown in the above figure will control the stepper motor on clock wise, counter clock wise direction and will stop the motor as well.
- Now go to the block diagram window and connect these blocks as shown in the figure below.
- At the end, after sending all the commands we must need to close the serial port so that unnecessary exchange of commands could be avoided.
- So I have cleared the all the commands in third frame of the case structure i.e I am sending no commands through the serial port.
- This will be helpful in closing the serial port.
- The figure show below explains all of the above steps visually.
- Now add another case structure to start the program when you want so.
- The figure below shows the newly added case structure.
- Now, go to the Front Panel, the button encircled in the figure shown below is used to start the program when needed.
- Now add a Stop button in order to terminate the program whenever you want so.
- The complete output of the program is shown in the figure below.
- A complete NI LabVIEW Virtual Instrument (VI) is shown in the figure below.
Decorated Front Panel
- Since, I want to make the better external look of the program so I have decorated a bit.
- The figure shown below shows the decorated Front Panel.
- Go to Controls, Modern-> Decorations you can see different decoration blocks there.
- All these blocks are shown in the figure displayed below.
- I have used three decoration blocks encircled with the blue color, to decorate my program.
- Red boundary shows all of the decoration blocks to make your program attractive.
- You can also decorate your programs using this amazing tool.
Complete Hardware Setup
[ultimate_spacer height="10:]
- A complete hardware setup for different commands is shown in the figure below.
- When you send the command C through the serial port from LabVIEW to the Arduino, the statement Clockwise will be printed on the LCD as shown in the figure below.
- When you send the command S through the serial port from LabVIEW to the Arduino, the statement No rotation will be printed on the LCD as shown in the figure below.
- When you send the command A through the serial port from LabVIEW to the Arduino, the statement Anti Clockwise will be printed on the LCD as shown in the figure below.
This is all from the tutorial Stepper Motor Direction Control in LabVIEW. I hope you all enjoyed this tutorial. If you face any sort of problem you can ask me anytime without feeling any kind of hesitation. I will try my level best to solve your issue in a better way if possible. I will explore NI LabVIEW further in my later tutorials. Till then, Take care :)
Unsung Heroes of Engineering Companies in USA
Hello everyone, I hope you all are doing great. Today, I am going to share a very simple tutorial named Unsung Heroes of Engineering Companies in the USA. From time to time, daring engineers take up projects which are at face value, impossible. However, with much persistence and planning, their efforts pay off and the world is granted splendid structures. Unfortunately, some of these great people never get any recognition for their work. This article looks at unsung heroes of engineering companies in the USA:
Frank Julian Sprague (General Electric)
Sprague was never an employee of General Electric, but his contribution to the invention of the electric motor was quite significant, to the extent that he fought to have Edison’s Medal of Honor changed so that his contribution could not be overrated.
He left to focus on his innovation, the electric motor. He successfully installed it in several elevators in buildings. A year or so after Edison’s motor’s which he had co-created began to sell exponentially, Sprague’s company was bought out by General Electric, and his name faded.
Marcin Mostafa and Natalia Paszkowska (Buro Happold)
These two people are affiliated with Buro Happold, one of the biggest engineering firms in the world with over 20 locations globally, including the USA. These two people enrolled for the Shanghai Expo in 2010 where they came up with the Polish Pavilion.
The design was inspired by folk art paper patterns in the Polish culture. The duo created a modern version of the art which became part of the building’s external structure. Better still; the building does not have any perpendicular walls. All the walls are slanted.
Since Marcin and his partner Natalia were quite young, after winning the competition, they chose Buro Happold to actually bring their design to life. Marcin and Natalia are still architects today under their Polish architectural studio, WWAA.
Pelli Clark Pelli and Thornton Tomasetti
It is extremely difficult to point to a single individual in these two companies. These two firms came together to create the popular Brookfield Place Entry Pavilion. The latter did the architecture part, while the former did the building. Better still, Thornton Tomasetti has carried out many other successful engineering projects all around the world like the signature tower in Malaysia, the Shanghai Tower in China, and the Metrorrey Light Rail.
Most notably, this company has been involved in the investigation of several national tragedies like the 9/11 attack on the world trade center. They not only conducted the investigations but helped to clear debris. They also investigated the collapse of the Interstate Highway 35 West Bridge. Maybe their great company culture where no one owns more than 8% of the shares also has to do with their success.
They were the first to use the nylon lens-shaped inflatable roof that is still used today. Cesar Pelli, the founder of Pelli Clark Pelli, has been ranked among the 10 best living architects in America.
All in all
The above individuals and companies indeed deserve to be recognized more. Unfortunately, they are not among the famous names associated with big achievements in engineering.
Despite this, their contribution has been very significant in the field and they cannot be looked down upon. Other companies should join this list of unsung heroes who have made contributions in fields such as trench shoring and molding.
The former is based on a breakthrough discovery: slide rails, a technology that reduced shoring costs by 40%. The latter has affiliate companies in stamping tools and die tooling to ensure the best quality in metal stamping, molding and assembly solutions.
Indeed, sometimes the best innovations and service delivery in the industry is done by the person or company that does not receive the recognition, yet their mark is left on earth for a very long time.
DC Motor Direction Control in LabVIEW
Hello friends! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge with all of you about how to make a simple program for
DC Motor Direction Control in LabVIEW. In my previous tutorials, I have also worked on
DC Motor Direction Control using Arduino. You should go through these tutorials they will be helpful in better understanding of the tutorial DC Motor Direction control using NI LabVIEW. The word DC
is basically an abbreviation of
Direct current. So, a direct current motor is commonly used motor having two input terminals, one is positive and the other one is negative. If we connect these terminals with the voltage supply the motor will rotate. If you change the polarity then motor will rotate in opposite direction. You should also have a look at
Difference between DC & AC Motors to get a better idea about these motors.
DC motor has a lot of applications. You can use it in automation projects, for controlling static as well as mobile robots, in transport system, in pumps,fans,bowers and for industrial use as well. In this tutorial I will work on
DC Motor Direction Control using NI LabVIEW. In my previous tutorial, I have done the
DC Motor Direction Control in MATLAB and I have used the same hardware but instead of controlling it from NI LabVIEW I have controlled it using MATLAB so you must have a look at that tutorial. Now let's get started with DC Motor Direction Control in LabVIEW.
DC Motor Direction Control in LabVIEW
In this tutorial, I will make a simple program to work on the DC Motor Direction Control in LabVIEW. NI LabVIEW is an amazing software tool specially for the students, because it is very easy to use and understand. So, its a student friendly tool. Before going into the details of this tutorial, you must go through my previous tutorials because I am going to use the same hardware setup and same Arduino source code as well. I will made a simple GUI (Graphical User Interface) in LabVIEW for
DC Motor Direction Control in LabVIEW. There will be three different buttons on the GUI for clockwise rotation, counter clockwise rotation and stopping the stepper motor respectively.
- You can download the complete SImulation for DC Motor Direction Control using NI LabVIEW here:
Download LabVIEW Simulation
- Download .rar file, extract it and enjoy the complete simulation for DC Motor Direction Control using NI LabVIEW.
How to Build Complete VI
- First of all open NI LabVIEW software on your laptop or PC so that we could design the GUI for DC Motor Direction Control in LabVIEW.
- Go to the Block Diagram window and Right Click on it.
- Go to Functions-> Instrument I/O-> Serial and you can see different serial blocks like VISA Write, VISA Read, VISA Serial etc.
- Choose the encircled VISA Configure Serial Port and place it on the Block Diagram window.
- VISA Configure Serial Port block will help us to open the Serial Port before executing the algorithm.
- The screen shot of the Block Diagram is shown in the figure below.
- Go to the first input terminal of the VISA Configure Serial Port block and go to Create-> Constant.
- Above step will be helpful to select the COM port of the Arduino board in order to run the program properly.
- Updated Block Diagram window is shown in the figure below.
- Now go to Functions-> Instrument I/O-> Serial, you can see there different serial blocks.
- Choose the encircled VISA Close block and place it on the Block Diagram window.
- The VISA Close block is shown in the figure below and it will be help in closing the Serial Port if needed.
- Now, go to the Functions-> Programming-> Structures and you can see the different structures there like For Loop, While Loop, Case Structure etc.
- Choose the encircled block as shown i the figure below.
- Place all the above blocks in a way shown in the figure below.
- Now, go to the Functions-> Programming-> Structures-> Flat Sequence.
- Flat sequence block is encircled and is shown in the figure below.
- Put your cursor and go to Add Frame After.
- Similarly ad another case after this as shown in the figures below.
- Newly added frame is shown in the figure below.
- Now, go to Functions-> Instrument I/O-> Serial, you can see different serial blocks there.
- Choose the encircled VISA Write Block and place it on the Block diagram window.
- The figure shown below elaborates the above steps.
- Make the connections as shown in the figure below.
- Now, go the Functions-> Programming-> Structures and you can see different types of structures like for loop, while loop, flat sequence etc.
- Choose he encircled block as shown in the figure below.
- Select the Case Structure block and place it on the block diagram window.
- The figure shown below displays the above step.
- Now, go to the input terminal of the write block and go to Create-> Control.
- Change the name of this block to Command box as shown in the figure below.
- The block diagram window is shown in the figure below.
- Now, go to Functions-> Programming-> Structures and you can see different structures blocks there.
- Choose the encircled block as shown in the figure below.
- Select the Local Variable Block and place it on the Front Panel.
- Right click on it and select Command box as shown in the figure below.
- Go to the input terminal of this local variable and go to Create-> Constant.
- Place C inside that constant.
- The figure below elaborates the above step.
- The above case structure is for the clock wise rotation of the stepper motor.
- Similarly make two further case structures for counter clockwise rotation and stopping the rotation of the stepper motor.
- All the three case structures are shown in the figure below.
- You can see three different case structures in above figure.
- The command box variable having command C will rotate the stepper motor in clockwise direction.
- A command box variable having command A will rotate the stepper motor in counter clockwise direction.
- The command box variable having command S will stop the rotation of the stepper motor.
- Now, go to the Front Panel and Right Click on it.
- Go to Controls-> Modern-> Boolean and you can see there different Boolean blocks.
- Choose the encircled block as shown in the figure below.
- Select the Round LED block and place it on the front panel.
- Similarly select two more round LED blocks and place them on the front panel as well.
- Change their names from default to Clockwise, Anti clockwise and Stop Motor.
- All of the above steps are explained visually in the figure shown below.
- The LED shown in the above figure will control the stepper motor on clock wise, counter clock wise direction and will stop the motor as well.
- Now go to the block diagram window and connect these blocks as shown in the figure below.
- At the end, after sending all the commands we must need to close the serial port so that unnecessary exchange of commands could be avoided.
- So I have cleared the all the commands in third frame of the case structure i.e I am sending no commands through the serial port.
- This will be helpful in closing the serial port.
- The figure show below explains all of the above steps visually.
- Now add another case structure to start the program when you want so.
- The figure below shows the newly added case structure.
- Now, go to the Front Panel, the button encircled in the figure shown below is used to start the program when needed.
- Now add a Stop button in order to terminate the program whenever you want so.
- The complete output of the program is shown in the figure below.
- A complete NI LabVIEW Virtual Instrument (VI) is shown in the figure below.
Decorated Front Panel
- Since, I want to make the better external look of the program for DC Motor Direction Control in LabVIEW, so I have decorated a bit.
- The figure shown below shows the decorated Front Panel.
- Go to Controls, Modern-> Decorations you can see different decoration blocks there.
- All these blocks are shown in the figure displayed below.
- I have used three decoration block encircled with the red color, to decorate my program.
- Thick red boundary shows all of the decoration blocks to make your program attractive.
- You can also decorate your programs using this amazing tool.
This is all from the tutorial DC Motor Direction Control in LabVIEW. I hope you all enjoyed this tutorial. If you face any sort of problem in DC Motor Direction Control in LabVIEW, then you can ask me anytime without feeling any kind of hesitation. I will try my level best to solve your issue in a better way if possible. I will explore NI LabVIEW further in my later tutorials. Till then, Take care :)
DC Motor Speed Control in LabVIEW
Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge with all of you guys, about how to make a simple Virtual Instrument (VI) for
DC Motor Speed Control in LabVIEW. In my previous tutorials, I have worked on
DC Motor Speed Control using Arduino, in which I have controlled the DC Motor Speed using Arduino and after that I made some advancements in it and then created
DC Motor Speed Control in Matlab in which commands were sent from Matlab. So, now we are gonna do the DC Motor Speed Control in LabVIEW.If you are working on DC Motor then you should also have a look at
DC Motor Direction Control using Arduino.
In this tutorial, I am going to work on the program for DC Motor speed Control using NI LabVIEW. So, before going into the detail of this tutorial, you must go through my previous tutorials because I am going to use the same hardware setup and Arduino source code with a bit modification. I will made a simple GUI (Graphical User Interface) for
DC Motor Speed Control in LabVIEW. There will be five different buttons on the GUI for clockwise rotation, counter clockwise rotation, stopping the stepper motor, accelerating and deaccelerating the stepper motor respectively.
DC Motor Speed Control in LabVIEW
In the tutorial DC Motor Speed Control in LabVIEW, I will explain you a complete step by step procedure to control the clockwise and counter clockwise direction of the DC motor as well as accelerating and deacelerating it with the help of the buttons on the GUI created in NI LabVIEW using serial communication between Arduino and NI LabVIEW.
- You can download the complete simulation for DC Motor Speed Control in LabVIEW here:
Download LabView Simulation
- Download .rar file, extract the files from the folder and enjoy the complete DC Motor Speed Control in LabVIEW simulation.
Flow Chart
- First of all I would like you to explain the algorithm of DC Motor Speed Control in LabVIEW with the help of a flow chart.
- Flow chart for this project is shown in the figure below.
- The figure given above can help you to understand the entire algorithm for DC Motor Speed Control in LabVIEW.
Block Diagram
- You can see the assembling of all the components used in DC Motor Speed Control in LabVIEW, in the block diagram.
- Block diagram for this particular tutorial is shown in the figure below.
- Initially commands are exchanged from NI LabVIEW to the Arduino using serial communication.
- Then Arduino transfers these commands to L98 motor controller, hence in this way the DC motor.
- LCD displays the executed commands.
Vitual Instrument's (VI's) Description
- First of all open NI LabVIEW software on your laptop or PC.
- Go to the Block Diagram window and Right Click on it.
- Go to Functions-> Instrument I/O-> Serial and you can see different serial blocks like VISA Write, VISA Read, VISA Serial etc.
- Choose the encircled VISA Configure Serial Port and place it on the Block Diagram window.
- VISA Configure Serial Port block will help us to open the Serial Port before executing the algorithm.
- The screen shot of the Block Diagram is shown in the figure below.
- Go to the first input terminal of the VISA Configure Serial Port block and go to Create-> Control.
- Above step will be helpful to select the COM port of the Arduino board in order to run the program properly.
- Updated Block Diagram window is shown in the figure below.
- Now go to Functions-> Instrument I/O-> Serial, you can see there different serial blocks.
- Choose the encircled VISA Close block and place it on the Block Diagram window.
- The VISA Close block is shown in the figure below and it will be help in closing the Serial Port if needed.
- Now, go to the Functions-> Programming-> Structures and you can see the different structures there like For Loop, While Loop, Case Structure etc.
- Choose the encircled block as shown i the figure below.
- Place all the above blocks in a way shown in the figure below.
- Now, go to the Functions-> Programming-> Structures-> Flat Sequence.
- Flat sequence block is encircled and is shown in the figure below.
- Put your cursor and go to Add Frame After.
- Similarly ad another case after this as shown in the figures below.
- Newly added frame is shown in the figure below.
- Now, go to Functions-> Instrument I/O-> Serial, you can see different serial blocks there.
- Choose the encircled VISA Write Block and place it on the Block diagram window.
- The figure shown below elaborates the above steps.
- Make the connections as shown in the figure below.
- Now, go the Functions-> Programming-> Structures and you can see different types of structures like for loop, while loop, flat sequence etc.
- Choose he encircled block as shown in the figure below.
- Select the Case Structure block and place it on the block diagram window.
- The figure shown below displays the above step.
- Now, go to the input terminal of the write block and go to Create-> Control.
- Change the name of this block to Command box as shown in the figure below.
- The block diagram window is shown in the figure below.
- Now, go to Functions-> Programming-> Structures and you can see different structures blocks there.
- Choose the encircled block as shown in the figure below.
- Select the Local Variable Block and place it on the Front Panel.
- Right click on it and select Command box as shown in the figure below.
- Go to the input terminal of this local variable and go to Create-> Constant.
- Place C inside that constant.
- The figure below elaborates the above step.
- The above case structure is for the clock wise rotation of the stepper motor.
- Similarly make four further case structures for counter clockwise rotation, accelerating, de-accelerating and stopping the rotation of the stepper motor.
- All the three case structures are shown in the figure below.
- You can see three different case structures in above figure.
- The command box variable having command C will rotate the stepper motor in clockwise direction.
- A command box variable having command A will rotate the stepper motor in counter clockwise direction.
- The command box variable having command H will rotate the stepper motor at higher and higher speed if it is rotating with a lower speed.
- A command box variable having command L will rotate the stepper motor with slower and slower speed if it is rotating at a higher speed.
- .
- The command box variable having command S will stop the rotation of the stepper motor.
- Now, go to the Front Panel and Right Click on it.
- Go to Controls-> Modern-> Boolean and you can see there different Boolean blocks.
- Choose the encircled block as shown in the figure below.
- Select the Round LED block and place it on the front panel.
- Similarly select two more round LED blocks and place them on the front panel as well.
- Change their names from default to Clockwise, Anti clockwise,Stop Motor, Accelerate and Deaccelerate.
- All of the above steps are explained visually in the figure shown below.
- The LED shown in the above figure will control the stepper motor on clock wise, counter clock wise direction and will stop the motor as well.
- Now go to the block diagram window and connect these blocks as shown in the figure below.
- At the end, after sending all the commands we must need to close the serial port so that unnecessary exchange of commands could be avoided.
- So I have cleared the all the commands in third frame of the case structure i.e I am sending no commands through the serial port.
- This will be helpful in closing the serial port.
- The figure show below explains all of the above steps visually.
- Now add another case structure to start the program when you want so.
- The figure below shows the newly added case structure.
- Now, go to the Front Panel, the button encircled in the figure shown below is used to start the program when needed.
- Now add a Stop button in order to terminate the program whenever you want so.
- The complete output of the program is shown in the figure below.
- A complete NI LabVIEW Virtual Instrument (VI) is shown in the figure below.
- I have decorated the front panel to make it attractive for the users.
- The final look of the Front panel is shown in the figure below.
- Go to Controls, Modern-> Decorations you can see different decoration blocks there.
- All these blocks are shown in the figure displayed below.
- I have used three decoration blocks encircled with the blue color, to decorate my program.
- Red boundary shows all of the decoration blocks to make your program attractive.
- You can also decorate your programs using this amazing tools.
That is all from the tutorial DC Motor Speed Control in LabVIEW. I hope you enjoyed this tutorial. If you face any sort of problem you can ask me anytime without even feeling any kind of hesitation. I will try my level best to solve your issues in some better way, if possible. I will explore NI LabVIEW, will make different projects on it and will share them with all of you as well. Till then, Take care :)
Stepper Motor Speed Control in Matlab
Hello friends! I hope you all will be absolutely fine and having fun. Today, I am going to tell you guys that how to design a simple algorithm for
Stepper Motor Speed Control in MATLAB by simply sending different commands to the serial port from Matlab to Arduino. You should first read
Stepper Motor Speed Control using Arduino because I am gonna take that tutorial further and will do the Stepper Motor Speed Control in Matlab. So, I would suggest you to first have a look at that tutorial before reading this one. Moreover, you should also have a look at
DC Motor Direction Control in Matlab,
DC Motor Speed Control using Arduino. Stepper Motor Direction Control Direction Control in Matlab, Stepper Motor Direction Control using NI LabVIEW and Stepper Motor Speed Control using Arduino in which I have discussed in detailed about how to make simple and easy programs to control the direction of DC motor in both clockwise and anti clockwise direction and how to control the stepper motor direction and speed as well.
So, you must go through my previous tutorials before going into the detail of today's tutorial because I have used the same hardware setup and a bit changed Arduino source code. Now, in this tutorial I will elaborate you that how can you send different commands through serial port from Matlab to the Arduino. I will create a simple GUI having different buttons on it through the direction as well as the speed of the DC motor can easily be controlled. So, let's have a look at
Stepper Motor Speed Control in MATLAB.
Stepper Motor Speed Control in Matlab
Here, in this tutorial I will explain about how can make a program for Stepper Motor Speed Control in Matlab
by creating a GUI having different buttons on it to control the direction of rotation of the stepper motor as well as the speed of the stepper motor by sending different commands through the serial port.
- Here, you can download the complete simulation for Stepper Motor Speed Control in Matlab by clicking on the button below.
Download MATLAB Simulation
- Download .rar file, extract it and enjoy the complete Matlab simulation.
Block Diagram
- First of all I would like to elaborate the algorithm for Stepper Motor Speed Control in Matlab with the help of a block diagram.
- Block diagram is shown in the figure below:
- Fist of all power is supplied to the whole system to run it.
- Matlab sends commands towards the Arduino UNO through the serial port using serial communication.
- Arduino transfers those commands to the L298 motor controller andL298 drive the motor.
- Arduino prints the executed commands on the LCD as well.
Initial GUI
- First of all I have created a very simple GUI (Graphical User Interface) for Stepper Motor Speed Control in Matlab.
- GUI has two different panels, Serial Port and Motor Controls.
- Serial Port panel has two buttons for opening and closing the serial port.
- Motor Controls panel has five buttons for clockwise and anti clockwise rotation, accelerating and deaccelerating the Stepper motor and stopping the stepper motor.
- Screen shot of the simple GUI for Stepper Motor Speed Control in Matlab is shown in the figure below.
- Then I made few of the changes by double clicking on all the buttons to make the GUI beautiful.
- The updated GUI is shown in the figure below.
- The figure shown above is the starting GUI when you just run the program.
- You can see below, after entering different commands GUI updates its text according to the command sent to the serial port.
Source Code Description
- First of all you must have to open the serial port by clicking on the button Start Serial.
- Go to the callback function of Start Serial button in the Matlab code.
- Just copy and paste the source code given below, in its callback function.
clc
global tep;
disp('Welcome to TEP');
disp('');
disp('www.TheEngineeringProjects.com');
disp('');
tep=serial('COM5'); % assign serial port object
set(tep, 'BaudRate', 9600); % set BaudRate to 9600
set(tep, 'Parity', 'none'); % set Parity Bit to None
set(tep, 'DataBits', 8); % set DataBits to 8
set(tep, 'StopBit', 1); % set StopBit to 1
%display the properties of serial port object in MATLAB Window
disp(get(tep,{'Type','Name','Port','BaudRate','Parity','DataBits','StopBits'}));
fopen(tep); % Open Serial Port Object
disp('Serial port is opened');
set(handles.text3, 'String','Serial port is opened');
- Now, as you press this button GUI will update its text as Serial port is opened.
- The updated GUI is shown in the figure below.
- Now, go the callback function of Clockwise button inside the Matlab source code.
- Just copy and paste the code given below in its call back function.
global tep
fwrite(tep,'C'); %Print character ‘a’ to the serial port
disp('Charater sent to Serial Port is “C”.');
set(handles.text1, 'String','Motor is rotating in clockwise direction'); %setting static text's text
- Now, if you press the Clockwise button the command C will be sent from Matlab to arduino via serial port.
- The GUI will update its text as Motor is rotating in clockwise direction.
- The screenshot of the updated GUI is shown in the figure below.
- Go to the callback function of Accelrate button and copy paste the code given below, in its callback function.
global tep
fwrite(tep,'H'); %Print character ‘a’ to the serial port
disp('Charater sent to Serial Port is “H”.');
set(handles.text1, 'String','Motor is accerating slowly'); %updating text on GUI
- As you press the Accelrate button the command H will be sent from Matlab to Arduino via serial port.
- The GUI will update its text as Motor is accelerating.
- If you press this button again and again, motor will continue to rotate at higher and higher speed.
- The screenshot of the updated GUI is shown in the figure below.
- Now, go the callback function of the Deaccelrate button in the Matlab source code.
- Just copy and paste the code given below in the callback function of this button.
global tep
fwrite(tep,'L'); %Print character ‘a’ to the serial port
disp('Charater sent to Serial Port is “L”.');
set(handles.text1, 'String','Motor is deaccerating slowly'); %updating GUI text
- As you press the Deaccelrate button the command L will be sent from Matlab to Arduino via serial port.
- The GUI will update its text as Motor is deaccelerating.
- If you press this button again and again, motor will continue to rotate at slower and slower speed.
- The screenshot of the updated GUI is shown in the figure below.
- Now, go the callback function of the Anti Clockwise button in the Matlab source code.
- Just copy and paste the code given below in the callback function of this button.
global tep
fwrite(tep,'A'); %Print character ‘a’ to the serial port
disp('Charater sent to Serial Port is “A”.');
set(handles.text1, 'String','Motor is rotating in anti clockwise direction'); %updating the text onto the GUI
- As you press the Anti Clockwise button the command A will be sent from Matlab to Arduino via serial port.
- The GUI will update its text as Motor is rotating in anti-clockwise direction.
- If you press this button again and again, motor will continue to rotate in anti clockwise direction.
- The screenshot of the updated GUI is shown in the figure below.
- Go to the call back function of the Stop Motor button inside the Matlab source code.
- Copy and just paste the code given below in its all back function.
global tep
fwrite(tep,'S'); %Print character ‘a’ to the serial port
disp('Charater sent to Serial Port is “S”.');
set(handles.text1, 'String','Motor is stopped');%Updating text on the GUI
- Now, if you press the Stop Motor button the command S will be sent from Matlab to Arduino via serial port.
- The GUI will update its text as Motor is stopped.
- The screenshot of the updated GUI is shown in the figure below.
- Go to the call back function of the Stop Serial button in the Matlab code.
- Copy and just paste the code given below in its call back function.
global tep;
fclose(tep);
set(handles.text1, 'String','Serial port is closed');%updating the text on the GUI
- At the end you must need to close the serial port.
- As you press the Stop Serial button the serial port will be closed.
- The GUI will update its text as Serial port is closed.
- The screenshot of the updated GUI for Stepper Motor Speed Control in Matlab is shown in below figure.
That's all from the tutorial
Stepper Motor Speed Control in Matlab. I hope you enjoyed this tutorial. If you face any sort of problem anytime, you can ask me freely without even feeling any kind of hesitation. I will try my level best to solve your problem in a better way, if possible. I will explore Matlab by making different projects and I will share them with you as well in my later tutorials. Till then, take care :)
Stepper Motor Speed Control using Arduino
Hello everyone! I hope you all will be absolutely fine and fun. Today, I am going to tell you that how to make a simple algorithm for
Stepper Motor Speed Control using Arduino. I have already discussed with you about
DC Motor Direction Control using Arduino,
Matlab and NI LabVIEW. Moreover, I have also discussed the
DC Motor Speed Control using Arduino,
Matlab and LabView. If you are working on Stepper Motor, then you must have a look at
Stepper Motor Direction Control using Arduino,
Stepper Motor Direction Control using Matlab and Stepper Motor Direction Control using NI LabVIEW. Now, in this tutorial I will explain you about the program which will helpful for Stepper Motor Speed Control using Arduino. Before going into the details of this tutorial you must have go through my previous tutorials because I am using the same hardware. So, they will be a lot helpful for the better understanding of this tutorial.
In this tutorial I will explain you about making an Arduino program for
Stepper Motor Speed Control using Arduino with the help of the serial communication. If the stepper motor is rotating at its maximum speed and you are continuously sending the command through the serial port to reduce its speed, it s speed will be reduced in proportion to the number of command sent through the serial port. Similarly the same procedure will be followed to increase the speed of the stepper motor.
Stepper Motor Speed Control using Arduino
In the tutorial Stepper Motor Direction Control using Arduino, I will explain you about making an algorithm to run the stepper motor at different speed. If the stepper motor is already running at its maximum speed and you want want to accelerate it further then nothing will happen to the speed of the stepper motor. If the stepper motor is rotating slowly and you enhance its speed, then the speed of the motor will increase in proportion to the number of accelerating command sent through the serial port.
- You can download the complete Arduino source code here by clicking on the button below.
Download Arduino Code
- Download .rar file, extract it and enjoy the complete source code.
Flow Chart
- I have made a flow chart so that you can easily understand the entire algorithm because sometimes it becomes difficult to understand the algorithm with the help of the source code.
- Flow chart for the Stepper Motor Speed Control using Arduino is shown in the figure below.
- First of all we need to start the serial port so that our communication could be started.
- Then there is a method to check the speed, if the speed is greater than the maximum speed of the stepper motor then the program will wait for the next command.
- If the stepper motor is not rotating with its maximum speed then we can increase its speed.
- Similarly if the minimum speed of the stepper motor is reached then the program will rotate for the next commands.
- If the minimum limit of the speed of the stepper motor is not reached then we have a option to reduce its further.
- At the end we should close the serial port so that exchange of unnecessary commands through the serial port could be avoided.
Block Diagram
- Block diagram will be helpful for use for the better understanding of the exchange of information.
- It tells us that how the information is exchanged sequentially among all the components used.
- Block diagram is shown in the figure below.
- Arduino UNO communicates with the L298 motor controller to control the speed of the stepper motor.
- L298 Motor controller manipulates the Arduino's commands and starts to control the speed of the stepper motor.
Arduino Code Description
In this section of the tutorial Stepper Motor Speed Control using Arduino, I am going to elaborate you about the Arduino source.
- I have made two different functions for increasing (accelerating) the speed of the stepper motor and for decreasing (deaccelerating) the speed of the stepper motor respectively.
- I have declared a variable named as count.
- In Accelerate function, you have to send the command H through the serial port to increase the speed of the stepper motor.
- In this function, I am continuously increasing the value of the count i.e as many times you send the command H the speed of the stepper motor will increase continuously.
- The source code of the Accelerate function is given below.
void Accelerate_Motor()
{
count=count+10; //Speed will increase continuously as we continue to press H
if (count>120) //Speed must not be greater than 120
{
count=120;
}
Serial.println("Accelerating"); //printing on the serial port
Serial.println("");//prints blank line on the serial port
myStepper.step(stepsPerRevolution);//counter clockwise rotation
myStepper.setSpeed(count); //Updating the speed of the motor
lcd.setCursor(3,0);//setting LCD cursor
lcd.print("Acelerating"); //printing on LCD
}
- In Deaccelerate function, you have to send the command L through the serial port to increase the speed of the stepper motor.
- In this function, I am continuously reducing the value of the count i.e as many times you send the command L the speed of the stepper motor will reduce continuously.
- The source code of the Deaccelerate function is given below.
void Deaccelerate()
{
count=count-10; //reducing the speed of the motor
if (count<20) //speed of the motor must not be less than 20
{
count=20;
}
Serial.println("Deaccelerating"); // prints on the serial port
Serial.println(""); //prints blank line on the serial port
myStepper.step(stepsPerRevolution);
myStepper.setSpeed(count); //Updating the speed of the motor
lcd.setCursor(3,0); //setting cursor on LCD
lcd.print("Deaccelerating"); //prints the command on LCD
}
- In the main source inside the loop I am calling both of these Accelerate and Deaccelerate functions.
- The executed commands will also be printed on the LCD (Liquid Crystal Diode).
- The main source code is given below.
#include <LiquidCrystal.h>//Library for LCD
#include <Stepper.h> //Library for Stepper motor
const int stepsPerRevolution = 255;
// initialize the stepper library on pins
Stepper myStepper(stepsPerRevolution, 4, 5, 6, 7);
char data;
int count = 120;
//LCD pins assigning
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
void setup() {
// set the speed at 60 rpm
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);// rate at which the arduino communicates
lcd.begin(20, 4);//LCD type
lcd.setCursor(3,0);//setting LCD cursor and printing on it
lcd.print("Stepper Motor");
lcd.setCursor(6,1);
lcd.print("Speed");
lcd.setCursor(5,2);
lcd.print("Control");
lcd.setCursor(2,3);
lcd.print("via Arduino UNO");
delay(3000);
lcd.clear ();//Clearing the LCD screen
lcd.setCursor(0,2);
lcd.print("www.TheEngineering");
lcd.setCursor(4,3);
lcd.print("Projects.com");
}
void loop() {
if(Serial.available())
{
data = Serial.read(); //Reading the data from serial port
}
if(data == 'C'){Clockwise();} //Clockwise rotation
if(data == 'A'){AntiClockwise();} //Anti-clockwise rotation
if(data == 'S') //stopping the stepper motor
{
data = 0;
lcd.setCursor(3,0);
lcd.print("No rotation");
Serial.println("No rotation");//print on the serial
}
if(data == 'H'){Accelerate_Motor();}
if(data == 'L'){Deaccelerate();}
}
Complete Hardware Setup
- In this section of the tutorial, I will show you the complete hardware setup that I have used for this project.
- Hardware consists of 12V power supply, Arduino UNO, L298 motor controller.
- When you upload the code to the Arduino board the system will look like the figure shown below.
- When you press H to increase the speed of the stepper motor, the statement accelerating will be printed on the LCD.
- The printed executed command is printed on the LCD and is shown in the figure below.
- When you press L to reduce the speed of the stepper motor, the statement Deaccelerating will be printed on the LCD.
- The printed executed command is printed on the LCD and is shown in the figure below.
That is all from the tutorial Stepper Motor Speed Control using Arduino. I hope you all have enjoyed this tutorial. If you face any sort of problem regarding anything you can ask me anytime without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way if possible. I will explore Arduino by making further projects and I will share them with all of you as well in my later tutorials. So, till then, Take Care :)