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 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 :)
Stepper Motor Direction Control using Matlab
Hello friends! I hope you will be absolutely fine and having fun. Today, I am going to share that how to make a program for
Stepper Motor Direction Control using Matlab. I am going to share this tutorial on demand. I have also make different programs for
DC Motor Direction Control using Arduino,
DC Motor Direction Control in Matlab, DC Motor Direction Control using LabVIEW,
DC Motor Speed Control using Arduino, DC Motor Speed Control using Matlab and Stepper Motor Direction using Arduino in my previous tutorials. So before going into the detail of this tutorial you must have to go through these tutorial because I will use the same hardware and a bit changed Arduino source code. In this tutorial I will make an algorithm to send different commands from the Matlab to Arduino using the serial port.
I have created a simple GUI (Graphical User Interface) in Matlab having two different panels. The first panel contains two and the second panel contains three buttons respectively. Each button sends the corresponding command through the serial port from Matlab to the Arduino and hence the corresponding action takes place.
Stepper Motor Direction Control using Matlab
Here's the tutorial on Stepper Motor Direction Control using Matlab, I will elaborate you that how can you make a Matlab program to send different commands from Matlab to Arduino using serial communication. I have made a simple GUI first containing two different panels having five buttons in total for different purposes.
Initial GUI
- The initial diagram of the GUI for Stepper Motor direction control using Matlab, is shown in the figure below.
- Here you can download the complete Matlab Simulation.
Download Matlab Simulation
- Once the code is downloaded, simply extract the zip file and copy past the code in you Matlab software and enjoy the results. :)
- I have changed some of the properties of the GUI to make its external look better.
- The updated GUI is shown in the figure below.
Matlab Code Description
- Here I am going to explain the logic designed for this project Stepper Motor Direction Control using Matlab.
- Go to the callback function of the Start Serial button in the Matlab code.
- Copy and just paste the source code given below in its callback function.
clc
disp('Welcome to TEP');
disp('');
disp('www.TheEngineeringProjects.com');
disp('');
global tep
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
set(handles.text1,'String','Serial port os opened');
- The code given above first of all creates an object for the serial port named as tep.
- tep is made global so that it can be used in all the functions.
- Then it, opens the serial port and then sends command through the serial port.
- This code also prints baud rate, data bits, stop bit etc on the serial port as mentioned in the comments of the code given above.
- After sending the commands it also prints the commands executed on the GUI as well.
- The GUI with the printed command is shown in the figure below.
- Go to the callback function of the Clockwise button in the Matlab code.
- Copy and just paste the source code given below in its callback function.
global tep %making the serial port vaiable global
fwrite(tep,'C'); %sending C through the serial port
disp('Character C is sent to the serial port'); %displaying on the serial port
set(handles.text1,'String','Clockwise rotation'); %prints on the GUI
- The code given above send the command C through the serial port in order to rotate the motor in clockwise direction.
- It prints the command on the serial port as well as on the GUI created in Matlab.
- The GUI with the updated text for Stepper Motor Direction Control using Matlab is shown in the figure below.
- Now, go to the callback function of the Anti Clockwise button in the Matlab code.
- Copy and just paste the source code given below in its callback function.
global tep
fwrite(tep,'A'); %sending command to the serial port
disp('Character A is sent to the serial port'); %displaying on the serial port
set(handles.text1,'String','Anti clockwise rotation'); %prints on the GUI
- The code given above send the command A through the serial port in order to rotate the motor in anti clockwise direction.
- It prints the command on the serial port as well as on the GUI created in Matlab.
- The GUI with the updated text is shown in the figure below.
- Now, go to the callback function of the Stop button in the Matlab code.
- Copy and just paste the source code given below in its callback function.
global tep
fwrite(tep,'S'); %sends S to the serial port
disp('Character S in sent to the serial port'); %prints on the serial port
set(handles.text1,'String','Motor is stopped'); %prints on the GUI as well
- The code given above send the command S through the serial port in order to stop the rotation of the motor.
- It prints the command on the serial port as well as on the GUI created in Matlab.
- The GUI with the updated text is shown in the figure below.
- Now, go to the callback function of the Stop Serial button in the Matlab code.
- Copy and just paste the source code given below in its callback function.
global tep
fclose(tep);%Close Serial Port Object
set(handles.text1,'String','Serial port is closed');%prints the executed command on the GUI
- The code given above prints the command Serial port is closed on the serial port as well as on the GUI created in Matlab.
- The GUI with the updated text is shown in the figure below.
- Was it difficult! I do not think so ;)
- So, try to make the same project and observe the results, are they closed to me?
That's all from the tutorial
Stepper Motor Direction Control using Matlab. I hope you enjoyed this tutorial. If you face any sort of problem you an ask me any time without feeling any kind of hesitation. I will try my level best to solve your issue in a better way way if possible. I will explore Matlab and will share with all of you, by making different projects on it in my later tutorials. Till then, Take care :)
Stepper Motor Direction Control using Arduino
Hello friends! I hope you all will be absolutely fine and having fun. Today, I will elaborate you that how can we make a simple algorithm for
Stepper Motor Direction Control using Arduino. In my previous tutorials I made algorithm for
DC Motor Direction Control using Arduino,
DC Motor Direction Control using Matlab,
DC Motor Speed Control using Arduino and
DC Motor Speed Control using Matlab. Now, in this tutorial I will control a stepper motor using Arduino by entering the different commands through its serial port.
Before going into the detail of this tutorial, you must know the basic difference between stepper and DC motors. DC motors have only two input terminal one is positive and the other one is negative. You just have to provide the power supply and it will start rotating but this is not the case in stepper motor. The stepper motor which I will use in this tutorial, has six pins out of which four pins provide pulses or steps and the other two pins are power pins. So, in this tutorial I will control this six pins stepper motor using L298 motor controller and Arduino UNO board. Basically we can use stepper motor where precision is required. Stepper motor has wide range of applications e.g robotics, CNC machines, home automation etc. In simple word, we can say that stepper motor can be used where there is a need to move at particular angle. So, let's get started with Stepper Motor Direction Control using Arduino:
Stepper Motor Direction Control using Arduino
In this tutorial we will learn how to make a program for
Stepper Motor Direction Control using Arduino by sending dfferent commands from the serial port. First of all, I am going share the list of components used for this mini project.
- Arduino UNO
- Stepper motor (6 wire)
- L298 Motor Controller (H-Bridge)
- Voltage Regulator (7805)
- 1000uF
- Jumper Wires
- Solderig Iron
- Soldering Wire
I want to tell you a bit about the stepper motor because all the other components are discussed in detail in
DC Motor Direction Control using Arduino.
Stepper Motor
Basically, stepper motors are like the DC motors that rotate in discrete steps. They have multiple arranged coils and they are usually known as phases. Motor will rotate one step at a time if we energize each phase sequence. High levels of precision can be achieved by controlling the stepper motor with computer. Steppers motors are available in the market in many different sizes. The speed of the stepper motor is controlled by frequency of pulses generated. They have wide range of applications like hard disk drives, robotics, telescope, antenna, toys etc. A six wire stepper motor is shown in the figure below.
- You can download complete source code for Stepper Motor Direction Control using Arduino by clicking the below button:
Download Arduino Source Code
Selection of Wires
- I have used 6 wire stepper motor and each wire has its own function.
- I have first divided these six wires into two pair.
- Each pair is consisting of three wires out of which one wire is common and the other two generate pulses.
- The two pair of three wires are shown in the figure below.
- Then, I have chosen a common wire in each pair from which the resistance to the other two wires is common.
- I have checked the resistance from the common wire to the both of the other wires of the same pair.
- I found that the resistance from the common wire to both of the other wires is same.
- We can see in the figure above the blue, pink and white wires belong to the same pair out of which white is a common wire.
- Here is the screen shot of the figure when I found the resistance between white and blue wire and I found it to be 8.0 ohms.
- The screen shot of the above steps is shown in the figure below.
- After that. I checked the resistance between white and pink wire and found it to be 8.1 which is almost the same as 8.0 so, this shows that the white wire is common to both of the blue and pink wire.
- Here is the screen shot of the above step.
- Then I found the resistance between pink and blue wire and it was 15.6 which is exactly the double of the earlier resistance.
- It is shown in the figure below.
- I have connect the both common wires as shown in the figure below.
- Here's the video in which I have discussed it in detail How to identify the wires of Stepper Motor:
- The remaining four wires are used to generate pulses which are also know as steps
- I have connected theses four wires to the output pins OUT1, OUT2, OUT3 and OUT4 of the L298 micro controller.
- Input pins of L298 micro controller In1, In2, In3 and In4 are connected to the pin no 7, 6, 5 and 4 of the Arduino UNO's board respectively.
Note:
I have also controlled the stepper motor using PIC micro controller so I would suggest all of you to first go through that tutorial before going into the details of this tutorial.
Block Diagram
- I have made a simple block diagram for Stepper Motor Direction Control using Arduino, which will be helpful to clearly understand the algorithm and the assembling of the components of Stepper Motor Direction Control using Arduino.
- The screenshot of the block diagram is shown in the figure below.
- First of all we need a power supply to run the project properly.
- Arduino reads the commands from the serial port and sends to the L298 motor driver to rotate the stepper motor.
- The commands got printed on the LCD (Liquid Crystal Display).
Arduino Source Code Description
- The main function of the Stepper Motor Direction Control using Arduino 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;
//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);
lcd.begin(20, 4);//LCD type
lcd.setCursor(3,0);//setting LCD cursor and printing on it
lcd.print("Stepper Motor");
lcd.setCursor(5,1);
lcd.print("Direction");
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");}
}
- In the code given above we have first initialized the LCD and Stepper motor libraries.
- Then, I assigned stepper motor pins at which it is connected to the Arduino.
- After that I initialized the LCD pins at which it is connected to Arduino UNO.
- Then I have made three different if statements, C for the clockwise, A for the anti clockwise rotation and S for the no rotation.
- Then in the loop I called clock wise and anti clockwise functions whose source code will be give and explained below.
- Then, I cleared the serial data in order to stop the rotation of the motor.
- The source code of the clockwise function is given below.
void Clockwise()//function for clockwise rotation
{
Serial.println("clockwise"); //printing on the serial port
Serial.println("");//prints blank line on the serial port
myStepper.step(stepsPerRevolution);//counter clockwise rotation
lcd.setCursor(3,0);//setting LCD cursor
lcd.print("Clockwise"); //printing on LCDa
}
- The source code for the anti clockwise function is given below.
void AntiClockwise()//function for anti clockwise rotation
{
Serial.println("anti-clockwise");//print on the serial
Serial.println("");//prints a blank line on the serial
myStepper.step(-stepsPerRevolution);//clockwise movement
lcd.setCursor(3,0);//setting LCD cursor
lcd.print("Anti-clockwise");//printing on LCD
}
- Now, open your Arduino software, just copy and paste the source code given above.
- Run the program and open the Serial Port at the top right of the Arduino software.
- Now, when you enter the command C stepper motor will start running in clockwise direction.
- If you send the command A through the serial port stepper motor will start to rotate in counter clockwise direction.
- If you send the command S the rotation of the stepper motor will be stopped.
Actual Hardware Setup
- The actual hardware operating setup for Stepper Motor Direction Control using Arduino is given in the figure below:
- Now, if you send the command C through the serial port the stepper motor will start to rotate in clockwise direction and the command will also be printed on the LCD.
- The screenshot of the printed command on LCD is shown in the figure below.
- Now, if you send the command A through the serial port the stepper motor will start to rotate in anti clockwise direction and the command will also be printed on the LCD.
- The screenshot of the printed command on LCD is shown in the figure below.
- Now, if you send the command S through the serial port the stepper motor will show no more rotation and the command will also be printed on the LCD.
- The screenshot of the printed command on LCD is shown in the figure below.
- Here's the complete video demonstration of Stepper Motor Direction Control using Arduino, I hope it will help as well:
That's all from the tutorial
Stepper Motor Direction Control using Arduino. I hope you 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 problem in a better way if possible. I will explore Arduino by making different projects on it. Till then, Take care :)
DC 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
DC Motor Speed Control in MATLAB by simply sending different commands to the serial port from Matlab to Arduino. In my previous tutorials,
DC Motor Direction Control using Arduino, we have seen the direction control of DC Motor via Arduino. 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 and
DC 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.
I have also given a detailed discussion about the PWM (Pulse Width Modulation) concept as well as about the duty cycle of the digital signal. I have also discussed that how to control the speed of the DC motor using PWN pins of the motor controller L298 in Arduino software. 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
DC Motor Speed Control in MATLAB:
DC Motor Speed Control using Matlab
Here, in this tutorial I will explain about how can make a program for DC Motor Speed Control in Matlab
by creating a GUI having different buttons on it to control the direction of rotation of the DC motor as well as the speed of the DC motor by sending different commands through the serial port.
Note:
Since you are working on the DC motor so you must also go through my previous tutorials, they will be helpful for you to simulate this project as well:
Here, you can download the complete simulation for DC Motor Speed Control in Matlab by clicking on the button below.
Download MATLAB Simulation
GUI Design and Matlab logic Description
- First of all I have created a very simple GUI (Graphical User Interface) 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 DC motor and stopping the DC motory.
- Screen shot of the simple GUI 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.text3, 'String','Motor is rotating in clockwise direction');
- 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 C_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.text3, 'String','Motor is accerating slowly');
- As you press the C_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 C_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.text3, 'String','Motor is deaccerating slowly');
- As you press the C_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.
- 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.text3, 'String','Motor is stopped');
- 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);
disp('Serial port is closed');
set(handles.text3, 'String','Serial port is closed');
- 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 DC Motor Speed Control in Matlab is shown in below figure:
That's all from the tutorial
DC 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 feeling any kind of hesitation. I will try my level best to solve your problem if possible. I will explore the Matlab by making different projects on it in my later tutorials. Till then, take care :)
Starting a SEO Consulting Business
Hello friends, I hope you all are doing great and having fun. Today, I am going to share a new tutorial in which I am gonna show you How to start a new
SEO Consulting Business. SEO is a particular type of Internet marketing that makes websites reach a higher rank when it comes both to organic and paid online services. Naturally, search keywords and key phrases change over time, which makes this business truly dynamic. As such, experts have to learn all the time and to perfect their manner of knowing ranking and advertising each year.
There are lots of SEO experts around, and one option, besides working for a company, is to offer consulting services to other businesses too. However, if you choose this path, you will have to invest in education,
marketing and business organization if you want to obtain some profit too.
I am sharing this tutorial for computer Engineering students because starting a SEO consulting business is an excellent option for Computer Software Engineers. One of my friends started this business around 2 years ago and rite now he is earning a handsome amount plus he has quite big staff working under him. So, if you understand the basics behind SEO then you can also do the same. Now I am gonna briefly explain some steps which are essential for starting a SEO Consulting Business:
Step 1: Learn SEO skills
You would think this goes without saying, but you’d be surprised to know how many people want to start a SEO consulting business without knowing SEO that well. It takes a couple of years of working with websites, analyzing web traffic and writing articles in order to become proficient in SEO. There are some basic skills you should already have, such as identifying and analyzing keywords, writing quality content, using Google Analytics or other similar analytic programs, writing meta tags and meta descriptions etc.
Step 2: Be an expert in SEO Consulting Business
Before starting your own business, it is advisable to work at least one year offering SEO solutions. In this way you can improve your expertise by attending conferences (such as Pubcon, MozCon and SEMPDX), optimizing your websites, write a blog and even an eBook. This is particularly useful for the marketing process, but you can also practice your research and get to know more about SEO.
Moreover, you can approach other businesses and experts and “steal” from their knowledge. A simple Google query for the Chicago area shows a lot of useful results for someone looking for
seoservicesusa seo chicago agency.
Step 3: Take business courses
Naturally, not everybody is good with business. You may have a degree in marketing or lots of experience in this domain, but you will still need some skills in order to run your own business. Take courses on tax preparation, finance, bookkeeping, business plan writing and any other topic that you don’t master. In this way, you will have a couple of advantages when you will start up the business.
Step 4: Write your business plan
After you took the special course (or not), you should write a business plan. Knowing beforehand what your goals and objectives are will make everything easier. Write down your plans on 5 years for management, marketing, finance and staff. Moreover, think about the fact that you could use these plans in order to get a loan or obtain an investment.
So, that's all about starting a SEO Consulting Business. I hope you guys get someknowledge out of it. Will meet you guys in the next tutorial. Till then take care and have fun !!! :)
DC Motor Speed Control using Arduino
Hello friends! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge about how can you make a simple program for
DC Motor Speed Control using Arduino UNO. In my previous tutorial,
DC Motor Direction Control using Arduino, I have just controlled the DC motor in both directions at constant speed using Arduino. I have also performed the
DC Motor Direction Control in Matlab by sending different commands through serial port from Matlab and LabVIEW to the Arduino and then controlled the direction of rotation of DC motor. But in this tutorial I will rotate the same DC motor at variable speed in both clockwise and anti clockwise directions.
In my previous tutorial, we have seen that input pins
In1 &
In2 of motor control driver L298 (H-Bridge) are useful to control the direction of rotation of the DC motor. In this tutorial, I have controlled its speed as well by providing different voltage levels at the
enable pin of the DC motor control driver L298. It will be helpful to vary the speed of the DC motor in either clockwise or in anti clockwise direction. So, let's get started with
DC Motor Speed Control using Arduino UNO:
DC Motor Speed Control using Arduino UNO
In this tutorial we will learn that how to make an algorithm for DC Motor Speed Control using Arduino UNO. Speed control of any motor is always done y Pulse Width Modulation, abbreviated as PWM. PWM pulse can be generated using Arduino and L298 Enable Pin is used to get that PWM pulse and then it controls the motor speed accordingly. Before going into the further details I would like to tell you about the concept of PWM for controlling DC motor. Moreover, you can download the complete Arduino code for DC Motor Speed Control using Arduino by clicking the below button:
Download Arduino Source Code
Pulse Width Modulation (PWM)
PWM stands for Pulse Width Modulation. It basically describes the type of the digital signal. PWM technique is an excellent technique to control the analog circuits with microcontroller's digital PWM output. In this technique we can get analog results with the digital means. Digital control is used to create square wave. This pattern can vary voltages between full on i.e.
5V and full off i.e.
0V. The duration of on time i.e. when the the signal is present is known as
pulse width. PWM waves for the different duty cycles are shown in the figure below.
Duty cycle is basically the proportion of the time during which a system is operated. It can be expressed as a percentage. For example motor rotates for 1 second out of 100 seconds, it duty cycle can be represented as 1/100 or as 1%. For Arduino software coding the command
analogWrite(255) shows the maximum i.e. 100% duty cycle. To achieve 50% duty cycle we have to update this command to
analogWrite(127). Arduino UNO's pin no
3, 5, 6,10 and
11 are used as PWM pins. In this project we can control the speed of the DC motor by providing
high and
low voltages to the
enable pin of the motor control driver L298. For example, if a motor rotates with the maximum speed and 100% duty cycle at
12V and we provide it with the
6V then it will rotate with the half of the initial speed having 50% duty cycle.
Motor Controller L298
The pins
EnA and
EnB of the motor controller L298 are used as the PWM pins. We can rotate the DC motor at different speed providing different high and low voltage levels to these pins of the motor control driver. If we start to reduce the maximum voltage at which the motor rotates at maximum speed, the speed of the motor also starts to reduce. In this way these enable pins are helpful to control the speed of the DC motor.
Algorithm design and descrition
In this section of the tutorial
DC Motor Speed Control using Arduino UNO, I am going to explain you about designing as well as a detailed description of the designed algorithm. I will tell you about the entire algorithm in step by step procedure.
Note:Since you are working on the DC motor so you must also have a look at my previous tutorials, they will be helpful for you to simulate this project as well.
Open your Arduino software, copy and paste the source code given below in your software.
#include <LiquidCrystal.h>
//Keyboard Controls:
//
// C - Clockwise
// S - Stop
// A - Anti-clockwise
// Declare L298N Controller pins
// Motor 1
int count=255;
int dir1PinA = 2;
int dir2PinA = 5;
int speedPinA = 6; // PWM control
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
void setup() {
Serial.begin(9600); // baud rate
lcd.begin(20, 4);
lcd.setCursor(5,0);
lcd.print("DC Motor");
lcd.setCursor(5,1);
lcd.print("Direction");
lcd.setCursor(5,2);
lcd.print("Control");
lcd.setCursor(2,3);
lcd.print("via Arduino UNO");
delay(3000);
lcd.clear ();
lcd.setCursor(0,2);
lcd.print("www.TheEngineering");
lcd.setCursor(4,3);
lcd.print("Projects.com");
//Define L298N Dual H-Bridge Motor Controller Pins
pinMode(dir1PinA,OUTPUT);
pinMode(dir2PinA,OUTPUT);
pinMode(speedPinA,OUTPUT);
analogWrite(speedPinA, 255);//Sets speed variable via PWM
}
void loop() {
// Initialize the Serial interface:
if (Serial.available() > 0) {
int inByte = Serial.read();
int speed; // Local variable
switch (inByte) {
case 'C': // Clockwise rotation
//analogWrite(speedPinA, 255);//Sets speed variable via PWM
digitalWrite(dir1PinA, LOW);
digitalWrite(dir2PinA, HIGH);
Serial.println("Clockwise rotation"); // Prints out “Motor 1 Forward” on the serial monitor
Serial.println(" "); // Creates a blank line printed on the serial monitor
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("Clockwise rotation");
break;
case 'S': // No rotation
//analogWrite(speedPinA, 0); // 0 PWM (Speed)
digitalWrite(dir1PinA, LOW);
digitalWrite(dir2PinA, LOW);
Serial.println("No rotation");
Serial.println(" ");
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("No rotation");
break;
case 'H': //Accelrating motor
count=count+20;
if (count>255)
{
count =255;
}
analogWrite(speedPinA,count);
delay(50);
//digitalWrite(dir1PinA, LOW);
//digitalWrite(dir2PinA, HIGH);
Serial.println("Motor is accelrating slowly");
Serial.println(" ");
Serial.println(count);
lcd.setCursor(0,0);
lcd.print("Motor is accelrating");
break;
case 'L': //Deaccelrating motor
count=count-20;
if (count<20)
{
count=20;
}
analogWrite(speedPinA,count);
delay(50);
//digitalWrite(dir1PinA, LOW);
//digitalWrite(dir2PinA, HIGH);
Serial.println("Motor is deaccelrating slowly");
Serial.println(" ");
Serial.println(count);
lcd.setCursor(0,0);
lcd.print("Motor Deaccelrates");
break;
case 'A': // Anti-clockwise rotation
//analogWrite(speedPinA, 255); // Maximum PWM (speed)
digitalWrite(dir1PinA, HIGH);
digitalWrite(dir2PinA, LOW);
Serial.println("Anti-clockwise rotation");
Serial.println(" ");
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("Anti-clockwise");
break;
default:
// Turn off the motor if any other key is being pressed
for (int thisPin = 2; thisPin < 11; thisPin++) {
digitalWrite(thisPin, LOW);
}
Serial.println("Wrong key is pressed");
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("Wrong key is pressed");
}
}
}
- In the previous tutorials, DC Motor Direction Control using Arduino and DC Motor Direction Control using Matlab we have learnt that how to control the direction of the DC motor.
- We used the commands C, A and S for the clockwise rotation, anti clockwise rotation and stopping the motor respectively.
- In this tutorial, we have added two further commands H and L for accelerating and de-accelerating the DC motor.
- If we send the command H different times consecutively the speed of the motor will increase continuously.
- If we send the command L different times consecutively, the speed of the motor will start to decrease.
- Now, upload the source code to your Arduino UNO's board.
- Open the serial monitor at the top right of the Arduino Software.
- And enter the commands in serial monitor periodically as explained above.
Actual Hardware Setup
- When we enter the command C in the serial monitor of the Arduino software. Motor will start rotating in the clockwise direction and a statement Clockwise rotation will be printed on serial port.
- The same statement will be printed on the LCD as well as shown in the figure below.
- When we enter the command A in the serial monitor of the Arduino software. Motor will start rotating in the anti clockwise direction and a statement Anti clockwise rotation will be printed on serial port.
- The same statement will be printed on the LCD as well as shown in the figure below.
- When we enter the command H in the serial monitor of the Arduino software. Motor will start accelerating and a statement Motor is accelerating will be printed on serial port.
- The same statement will be printed on the LCD as well as shown in the figure below.
- When we enter the command L in the serial monitor of the Arduino software. Motor will start to deaccelerate and a statement Motor Deaccelerates will be printed on serial port.
- The same statement will be printed on the LCD as well as shown in the figure below.
Thats all from the tutorial
DC Motor Speed Control using Arduino UNO. I hope you have enjoyed this tutorial. If you face any sort of problem, you can ask me anytime without feeling any kind of hesitation. I will further explore my knowledge about
Arduino projects in my later tutorials. Till then, Take care :)