How to Clear MATLAB Windows
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 Clear MATLAB Windows. If the command window and workspace window are not clear they present a very complicated look and hence the user feel it difficult to write code on command window. Here, I have compiled a list of awesome
MATLAB Image Processing Projects so must check them out to get some inspiration. :)
So, for the ease of the user we need to clear the both window specially the command window because it contains the entire code for any of the task. Before going into the details of this tutorial, you should go through
Introduction to MATLAB and
Declaration of Variables in MATLAB for the better understanding of this tutorial. If we want to avoid the complications while writing the code on command window we must need to clear the both command window as well as the workspace window. If you don't wanna work on Command Windows then you should have a look at
How to Create m File in MATLAB. Anyways, in today's tutorial we are gonna have a look at matlab clear command window and its quite easy but I must say its quite handy, especially when you are working on some complex MATLAB Project.. So, now let's get started with today's tutorial and have a look at How to Clear
MATLAB Windows:
How to Clear MATLAB Windows ???
In the tutorial,
Clearing MATLAB Windows I will show that which commands are required to use to clear the command window and workspace window In order to avoid the complications for the user while writing the source code on the command window.
- The commands for clearing the command window and workspace window are shown below.
- clear all (used to clear the workspace window)
- clc (used to clear the entire command window)
- The command window with some of the commands written on it is shown in the figure below.
- The workspace window having some of the variables is shown in the figure below.
Clearing both the Windows
- First of all I will show you that how to clear the workspace window.
- Go to the command window and write the command clear all and press
- All of the above steps are shown in the figure below.
- You will see that all the variables from the workspace window has been removed.
- The cleared workspace window is shown in the figure below.
- Now go to the command window and write the command clc on it.
- The command written on the command window is shown in the figure below.
- If you press Enter after writing the command show in the figure above, on the command, you will see that the command window has be cleared.
- The empty command window is shown in the figure below.
- So, by clearing both of these window a user can easily make an algorithm without any complication.
- You should also have a look at this video tutorial as well:
That is all from the tutorial, Clearing Command Window and Workspace in
MATLAB. I hope you enjoyed this tutorial. If you face any sort of problem in clear command window matlab, you can ask me in comments anytime without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. In my next tutorial I will explain you that how to Calculate the Values of the Trigonometric Functions in MATLAB. I will explore MATLAB further in my later tutorials and will share all of them with all of you as well. So, till then, Take Care :)
Creating First Program with myRIO
Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge about
Creating First Program with myRIO. Before doing anything on NI myRIO you must know that how to configure this device. So, before going into the details of this tutorial I would like to suggest you to must visit
Getting Started with myRIO and
How to Configure myRIO on WiFi for the better understanding of this tutorial.
NI myRIO is an amazing processing tool that has a very high processing speed as compared to other microcontroller e.g. Arduino, raspberry pi, gellilio etc. So, it can be used for the real time projects where there is need to respond very quickly according to the assigned tasks. NI myRIO was launched by National Instrument. It has different models. In this tutorial I am going to use NI myRIO. This module has a built-in Wifi as well as USB cable supported. The device has its own IP address which helps while configuring it. If we want tmo connect it over internet then the IP address changes to access the device online. It operates on 667MHz. It’s a fully secured device with a strong casing around the circuitry. There are on board four LED lights on NI myRIO for the configuration test, whether the device is properly attached to the computer or not.
Creating First Program with myRIO
Here, in the tutorial
Creating First Program with myRIO, I will tell you the step by step procedure for creating your first program using NI myRIO. The tutorials basically focuses on controlling an LED on Front Panel with the help of the on board button on the device.
- You can download the complete Virtual Instrument (VI) for controlling LED using on board button here by clicking on the button below.
- Download .rar file, extract it and enjoy the LabVIEW NI myRIO’s simulation.
Virtual Instrument (VI) Creation
- First of all open the NI LabVIEW software from the softwares list.
- The starting window of the software is shown in the figure below.
- You can see a lot of options on the starting window having different individual functions.
- Now, click on the encircled button Create Project.
- As you press this button a new window will be appeared on your computer screen.
- The new window with multiple options is shown in the figure below.
- Go to the myRIO option as shown in the figure below.
- While clicking on myRIO option, you can see the display on the right side will change by doing so.
- Select the myRIO Project from the right portion of the window.
- The both of the above steps are shown in the figure below.
- Now, press the Next button as shown in the figure below.
- Just after pressing this button you will be able to see a new window on your computer’s screen.
- Select the Plugged into USB option and press Refresh button, your attached myRIO device will be detected in this way.
- IP address of the used NI myRIO is encircled in the below figure as 22. 11.2.
- The newly opened window with a bit detail is shown in the figure below.
- The destination of the file which is being created is shown in the figure below.
- Now, press the Finish button as highlighted in the figure shown below.
- As you press this button a new window will again appear on your computer’s screen.
- Go to the Medical Kit (172.22.11.2) as encircled in the figure below.
- The new window appeared with all of the above steps is shown in the figure below.
- Now go to the Medical Kit option and Right Click on it.
- By doing so, you can see a lot of options here in the new mini window, go to New-> VI.
- The above steps are shown in the figure given below.
- As u press the VI two windows, Front Panel and Block Diagram will be appeared on your computer’s screen.
- Both the windows are shown in the figure below.
- Now, press Ctrl+t, both of the windows will be aligned in this way.
- Now go to the Block Digram window and Right Click on it.
- Go to the Functions-> Programming-> Structures here you can see different structures blocks.
- Select the While Loop as encircled in the figure shown below.
- Select this block and place it on the Block Diagram window as shown I the figure below.
- Now, go to the Functions-> Programming-> Structures once again.
- Select the Flat Sequence and place it around the While Loop.
- Now put your cursor on the right side of the Flat Sequence and Right Click on it.
- Go to the Add Frame After as shown in the figure below.
- Now, Right Click on the Block Diagram window and go to Functions-> myRIO-> Device Management, here you can see the two different management blocks.
- Select the encircled block Reset myRIO as shown in the figure below.
- Place the encircled block Reset myRIO inside the second frame of the Flat Sequence.
- Now go to the Functions-> myRIO and here you can see the different myRIO blocks.
- Select the encircled block Button as shown in the figure below.
- Place Button inside the While Loop.
- As you place the button a new window will be appeared on your screen.
- New window is shown in the figure below, just press Ok as shown below.
- All of the above steps are shown in the figure below.
- Now go the Functions-> Programming-> Structures, here you can see the different structure blocks.
- Select the encircled block Case Structure as shown in the figure below.
- Now go to the Functions-> myRIO, here you will see a lot of myRIO blocks.
- Select the encircled block LED as shown in the figure below.
- Select the encircled block and place it inside the Case Structure.
- As you place the LED in the Case Structure a new window will be appeared on the screen, just press Ok.
- The figure shown below exhibits the above steps.
- Now to the First input terminal of the LED and Right Click on it and go to Create-> Constant.
- By doing so, four inputs will be added to the LED.
- The above step is shown in the figure below.
- And change the condition from False to the True e.g. F to
- The figure shown below exhibits the above step.
- Now copy the entire code inside the Case Structure and go to the False Option.
- Paste the copied code inside the False Option and change the condition from True to False i.e. form T to
- The above step is shown in the figure below.
- Now go to the bottom right of the While Loop and go to Create-> Control as shown in the figure below.
- Now go to output terminal of the Button right click on it.
- Go to the Create-> Indicator as shown in the figure below.
- By doing so, a new indicator will be added on the block diagram window to show the state of the button i.e. whether it is pressed or not.
- The above step is exhibited in the figure below.
- Now run the program and the code will be started to upload on the NI myRIO.
- The uploading in process is shown in the figure below.
- The Front Panel is shown in the figure below.
- Now if you press the button on the myRIO the Green LED on the Front Panel will be turned on.
- The figure shown below exhibits the above step.
- The ON state of the LED shows that the button on the myRIO is pressed.
So, that is all from the tutorial Creating First Program with myRIO. I hope you enjoyed this first project with myRIO. You should also have a look at these
LabView Projects. If you find any sort of problem, you can ask in comments anytime without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. In my next tutorial I will elaborate that how to control the servo motor using NI LabVIEW and NI myRIO. I will further explore NI LabVIEW and NI myRIO in my later tutorials. So, till then, Take Care :)
How to Create m File in MATLAB
Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge about
How to Create m File in MATLAB. It is also known as
New Script or
Editor in the MATLAB. It's an amazing MATLAB tool. We can write the complete source code on editor. If we want to visualize the result of the particular statement we should not put a semicolon after that statement in MATLAB. Before going into the details of this tutorial, you must first have a look at
Introduction to MATLAB and if you don't know about MATLAB variables then you must read
Declaration of Variables in MATLAB.
By doing this and by pressing the
Run (Green Color) button at the top of the editor we will be able to see the result on the command window. In other words, we have to write the entire source code in the editor and to run the program and the desired results will be displayed on the command window. It is easy to do so as compared to write and manipulate every single statement on command window.
How to Create m File in MATLAB ???
Here, in the tutorial
How to Create m File in MATLAB, I will show you the step by step procedure to create an m file in MATLAB first and then to observe the desired results on command window.
- First of all you need to open your MATLAB software.
- Go to the top left corner of the front window of the MATLAB and click on New Script.
- The above steps are shown in the figure below.
- A new window will be appeared on your screen right after clicking on the New Script.
- The second window appeared on the screen is shown in the figure below and it is also known as an Editor.
- A very simple code written on the editor by declaring three different kinds of variables and their manipulation is shown in the figure below.
- Now, if you want to observe the result on the command window you have to do two things.
- The first thing is to remove the semicolon at the end of the statement as shown in the figure above.
- And the second thing is to press Run button encircled in the figure shown above.
- After following all of the above steps you will be able to visualize the results on the command window of the amazing software i.e. MATLAB.
- The result observed on the command window is shown in the figure below.
- You can see the result is obtained in the form of an equation.
- That was the detailed discussion on Creating m.file in MATLAB.
So, that is all from the tutorial Creating m.file in MATLAB. I hope you enjoyed this tutorial. If you face any sort of problem you can ask me in comments anytime without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. In my next tutorial I will explain you that how to Calculate the Values of the Trigonometric Functions in MATLAB. I will explore MATLAB further in my later tutorials and will share all of them with all of you as well. So, till then, Take Care :)
DC Motor Projects
Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share a list of tutorials on
DC Motor Projects using different software e.g. Arduino,
Matlab and NI LabVIEW. I have already shared these tutorials but they are posted randomly. So, today I thought that I should combine all those tutorials into a single one. So I am going to share the links of all of those tutorials in this tutorial so that it may be helpful for engineering students or anyone who wants to visit. This tutorial will help you to visit all of my tutorials related to DC motor control.
The links of all the tutorials will be given and you will be able to download the desired tutorial from the corresponding link. I will make separate sections for each software to control DC motor. In each section all the possible controls of DC motor will be given in detail. If you have any sort of problem, you can ask in comments. I will try my level best to solve your issues. In today's tutorial, I have simply combined all the DC Motor Projects posted on our blog. I will update this list in future. So, let's get started with
DC Motor Projects:
DC Motor Direction Control - DC Motor Projects
In this section of DC Motor Projects, I will provide you the list of the tutorials in which I have already controlled the direction of the DC motor using three different software e.g.
Arduino, Matlab and NI LabVIEW. I have used the same hardware and Arduino source code in all of these tutorials. In case of Matlab and NI LabVIEW I have sent commands through the serial monitor towards Arduino and hence the whole system works. So, let's get started with these DC Motor Projects:
1- DC Motor Direction Control using Arduino
In the tutorial DC Motor Direction Control using Arduino, I have interfaced a DC motor with Arduino UNO board to control its clockwise and counter clockwise direction. I have used a motor controller named as H-Bridge to control the direction of DC motor. It can simultaneously control two DC motors. The algorithm was very simple. Commands for clockwise and counter clockwise rotation are sent through the serial monitor of Arduino software. Its one of the basic DC Motor Projects.
These commands are then passed to the motor controller and then it decides the direction of rotation of DC motor after manipulating the Arduino commands. Direction of DC motor can be reversed by simply changing the polarity so L298 controls the direction of the DC motor by continuously making its pins low, high and vice versa.
- I have posted a detailed tutorial on DC Motor Direction Control using Arduino.
- You can read that tutorial and download the complete simulation & code by clicking the below button:
Download DC Motor Direction Control Arduino Source Code
2- DC Motor Direction Control using Matlab
In this DC Motor Project, I have done the DC Motor Direction Control in Matlab, I have created a simple Graphical User interface (GUI) in Matlab having three different buttons for controlling the clockwise, counter clockwise direction of the Dc motor and to stop the DC motor as well. Two more buttons are also there on the GUI for opening and closing the serial port.
As we press any of the buttons, corresponding command is sent through the serial port from Matlab to Arduino and then Arduino transfers those commands to the H Bridge and hence the entire process gets completed. Pressing the Open Serial Port button, serial port will be opened and we will be able to communicate with the Arduino using serial communication and at the end we must close the serial port in order to avoid the exchange of unnecessary commands being sent through the serial port.
- You can download the complete simulation here.
- Download .rar file, extract it and start playing with the simulation. I hope you have enjoyed this DC Motor Project.
Download DC Motor Direction Control Matlab Simulation
3- DC Motor Direction Control using NI LabVIEW
In the tutorial DC Motor Direction Control in NI LabVIEW, I have controlled the clockwise and counter clockwise direction of the DC motor using serial communication between NI LabVIEW and Arduino. Commands like
C, S and
A are sent through NI LabVIEW towards Arduino for clockwise rotation of the DC motor, stop the DC motor and anti clockwise rotation of the same DC motor respectively.
There are three different buttons on the front panel of NI LabVIEW. These buttons are used to send commands
C, S and
A from NI LabVIEW to Arduino using Serial communication.
- You can download the complete simulation here.
- Download .rar file, extract it and start playing with the simulation.
Download DC Motor Direction Control LabVIEW Simulation
4- DC Motor Direction Control with Arduino in Proteus
In the tutorial, DC Motor Direction Control with Arduino in Proteus, I have designed a complete simulation in Proteus, which will help you in understanding the controlling of DC motor. I have designed
DC Motor Drive Circuit in Proteus ISIS. for the DC Motor Direction Control.
I have provided the complete simulation and the source code for DC Motor Direction Control in Proteus but I would recommend you to design it on your own, it would be better for you. So, when you send the character
C on serial terminal then the motor will rotate in clockwise direction and when the character sent through the serial terminal is
A, the motor will rotate in counter clockwise direction and will stop when the character
S is sent.
- You can download the complete simulation here.
- Download .rar file, extract it and start playing with the simulation.
Download DC Motor Direction Control Proteus Simulation
DC Motor Speed Control - DC Motor Projects
In this section of DC Motor Projects, I will provide you the list of the tutorials in which I have already controlled the speed of the DC motor using three different software e.g. Arduino, Matlab and NI LabVIEW. I have used the same hardware and Arduino source code in all of these tutorials. In case of Matlab and NI LabVIEW I have sent commands through the serial monitor towards Arduino and hence the whole system works. So, let's get started with these DC Motor Projects:
1- DC Motor Speed Control using Arduino
In DC Motor Speed Control using Arduino, I have actually used the concept of Pulse Width Modulation (PWM). For this purpose, I have used PWM pins EnA and EnB of L298 motor control to control the speed of the DC motor. PWM basically control the electronic pulse duration. When the state of the PWM pins of L298 motor controller is high, the output power will be supplied. I have controlled the speed of the DC motor by turning applied voltage on and off.
Duty cycle is the main factor while controlling the speed of the DC motor. When the duty cycle is long i.e signal is power is supplied for a long time, Dc motor will rotate at fast speed and vice versa. Usually the PWM duty cycle is less than 90%. I have also printed the executed commands on LCD for this project.
- You can download the complete simulation here.
- Download .rar file, extract it and start playing with the simulation.
Download DC Motor Speed Control Arduino Source Code
Note:
2- DC Motor Speed Control in Matlab
In DC Motor Speed Control in Matlab, I have also created a GUI in Matlab having two extra buttons as compared to the GUI of DCMotor Direction Control in Matlab. One for continuously accelerating the speed of the DC motor and the other for continuously deaccelerating the speed of the same motor.
As we press any button, corresponding command will be sent through the serial port from Matlab to Arduino using serial communication. The logic created is pretty simple, the speed of the motor will accelerate continuously as many time we press the button and if the maximum speed is reached, motor maintains the same speed even we continue to enhance its speed. Same procedure will be followed to reduce the speed of the DC motor.
- You can download the complete simulation here.
- Download .rar file, extract it and start playing with the simulation.
Download DC Motor Speed Control Matlab Simulation
3- DC Motor Speed Control using NI LabVIEW
In DC Motor Speed Control in NI LabVIEW, I have have placed five different buttons on the front panel to control the direction as well as the speed of the DC motor. By pressing the
Accelerate button again and again speed of the DC motor will increase in proportion to the number of times the buttons is pressed.
Similarly, by pressing
Deaccelerate button again and again the speed of the DC motor will decrease in proportion to the number of times the button is pressed. First of all you need to press the
Start button in order to start the serial communication between NI LabVIEW and Arduino. After pressing it you will be able to send the commands serially from NI LabVIEW towards Arduino.
- You can download the complete simulation here.
- Download .rar file, extract it and start playing with the simulation.
Download DC Motor Speed Control LabVIEW Simulation
4- DC Motor Speed Control with Arduino in Proteus
In the tutorial DC Motor Speed Control using Arduino in Proteus, I have controlled both the direction as well as the speed of the DC motor. For the direction control of DC motor the functionality remains the same as it was in DC Motor Direction Control with Arduino in Proteus but for the speed control, I have placed an Light Dependent Resistor (LDR) sensor in the simulation and depending on the value of the LDR sensor the speed DC motor will either increase or decrease.
- You can download the complete simulation here.
- Download .rar file, extract it and start playing with the simulation.
Download DC Motor Speed Control Proteus Simultation
This is all from the tutorial DC Motor Projects. I hope you all 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 issue in a better way, if possible. I will explore Arduino, Matlab and NI LabVIEW further in my later tutorials. Till then, Take care :)
Declaration of Variables in MATLAB
Hello everyone! I hope you all will be absolutely fine and having fun. In the tutorial
Declaration of variables in MATLAB, I will elaborate you that how to declare different variables in MATLAB and how to manipulate those variables without assigning them with the values. Before going into the details of this tutorial you must go through
Introduction to MATLAB, because understanding MATLAB first is better. This will help you in better understanding of this tutorial.
Variable declaration is one of the most important and compulsory steps while writing the code to perform any task. Without the declaration of the variables we can not proceed further to perform our task properly. So, if we want to do the different tasks in a proper way we must need to declare the variable before doing anything in the code. Once the variables have been declared, we can proceed further to explore the desired task.
Declaration of Variables in MATLAB
Here, in the tutorial
Declaration of variables in MATLAB, I will show you that how the variables can be declared in the MATLAB and how to manipulate them without assigning them with the values. The command
syms is used to declare the different variables in the
MATLAB.
- Here, I will show you that what happens if you have not declared the variables.
- The error is shown in the figure below, when you have not declared the variables.
- I have written an equation having three different variables named as f,t and r without declaring these variables.
- MATLAB has shown an error on the command window as undefined function or variable.
- So the error shown in the above figure shows the desired results can not be obtained without declaring the variables first.
- Now, I am going to declare all the variables first and will then manipulate them.
- The declared variables are shown in the figure below.
- Since I have declared all of the variables now which are being used in the equation.
- So, now I am going to manipulate them and going to observe the results.
- The result of the addition of the two variables, which is stored in the third variable, is shown in the figure below.
- The above figure shows the result of the addition of the two different variables in the form of an equation.
- The result has been obtained because all of the variables has been declared first, i.e. declaration of variables plays a very important role while writing an algorithm to perform any task either simple or complicated.
- You can also see all of the process in the video given below:
So, that is all from the tutorial Declaration of Variables in
MATLAB. I hope you enjoyed this tutorial. If you find any sort of problems you can ask me 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. In my next tutorial I will explain you that how to create an m.file in MATLAB. I will further explore MATLAB in my later tutorials and will share all of them with you as well. So, till then, Take Care :)
Introduction to MATLAB
Hello everyone! I hope you all will be absolutely fine and having fun. In this tutorial, I am going to give you a detailed
Introduction to MATLAB. I will explain in detail, step by step procedure of using
MATLAB for the first time. First of all, I would like to tell you a bit about the MATLAB software. MATLAB basically works on matrices and it is an excellent software for different kinds of simulation based projects as well as hardware based projects and specially, it is good for the
Engineering Projects.
MATLAB can be used for the manipulation purpose in order to obtain the proper results. It is very easy to use this software and most of the students prefer to use this software for their projects. So, this shows that MATLAB is a user friendly software as well. MATLAB has a very wide range of applications. It can also be used for the real time projects. Robotics, image processing and medical related projects are its major applications. You should also have a look at
How to Create GUI in MATLAB. So, let's get started with
Introduction to MATLAB:
Introduction to MATLAB
So, in the Introduction to MATLAB, I will show you the step by step procedure about how to use the MATLAB software for the first time.
- As you open the MATLAB software, a new window will be appeared on your screen.
- The window is shown in the figure below.
- The above window is the starting window which appears on the screen when you open the MATLAB.
- After sometime, you will be able to see another window on the screen.
- The second window is shown in the figure below.
Sections of MATLAB
There are six basic section of the MATLAB and understanding them is essential part of Introduction to MATLAB. The names of all of these sections are given below.
- Current Folder
- Command Window
- Workspace
- Command History
- View or Change Directory
- Help Section
Current Folder is the first section of the MATLAB’s front window at the left side of the window. It displays the files that has already been saved. You can open the files that are already saved somewhere in your PC or laptop.
- The current folder section is shown in the figure below.
Command Window is the second section and is used to show the results of the entire source code. If we want to observe the results on the command window, we must not put a semicolon after the statement then. If there is a semicolon at the end of the statement, result of that statement will not be shown on the command window.
- The command window section is shown in the figure below.
Workspace is the third section of the MATLAB’s front window which shows all the variables that are used while writing the complete algorithm.
- Workspace section is shown in the figure below.
Command History is the fourth and the last section of the MATLAB’s front window. It shows all of the commands that have been used in the entire algorithm.
- The command history section is shown in the figure below.
View or Change Directory helps us to view the directory or the complete destination of the file that is opened in the MATLAB. You can also open a new file by changing its directory.
- Directory box is shown in the figure below.
Help Section is also an amazing tool of the MATLAB. It provides help regarding of the command or any other thing related to MATLAB. By typing the thing which is not clear, you will be able to find a lot of help.
- The button to open the help section is shown in the figure below.
- As you press this button a new named as help will be appeared on your screen to help you.
- The help window is shown in the figure below.
- So that was the brief discussion about how to getting started with the MATLAB.
So, that is all from the tutorial Introduction to MATLAB. I hope you have enjoyed this tutorial. If you find any sort of problem in introduction to matlab, you can ask in comments anytime without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. In my next tutorial I will elaborate the
Declaration of Variables in MATLAB and how to manipulate them without assigning them with the values. Moreover, you should also have a look at
How to Create m file in MATLAB. I will further explore MATLAB in my later tutorials. So, till then, Take Care :)
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 :)