Stepper Motor Projects

Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share a list of Stepper Motor Projects using different software e.g. Arduino, Matlab and NI LabVIEW. I have already shared these projects but they are posted randomly. So, today I thought that I should combine all those projects 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 Stepper Motor Projects. You should also have a look at this Stepper Motor Simulation in Proteus. The links of all the tutorials will be given and you will be able to download the desired project code or simulation from the corresponding link. I will make separate sections for each software to control stepper motor. In each section all the possible controls of stepper 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. So, let's get started with Stepper Motor Projects. first of all, I will post projects i which I have done direction control of stepper motor:

Stepper Motor Projects

In this section of Stepper Motor Projects, I will provide you the list of the tutorials in which I have already controlled the direction of the stepper 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.
Stepper Motor Direction Control using Arduino
In the tutorial Stepper Motor Direction Control using Arduino, I have interfaced a stepper motor with Arduino UNO board to control its clockwise and counter clockwise direction. I have used a motor controller named as H-Bdridge to control the direction of stepper motor. It can control only one stepper motor at a time.. The algorithm was very simple. Commands for clockwise and counter clockwise rotation are sent through the serial monitor of Arduino softwrare. These commands are then passed to the motor controller and then it decides the direction of rotation of stepper motor after manipulating the Arduino commands. Direction of stepper motor can be reversed by simply changing the polarity so L298 controls the direction of the stepper motor by continuously making its pins low, high and vice versa.
  • You can download the complete simulation there.
  • Download .rar file, extract it and enjoy the complete simulation:
Stepper Motor Direction Control Using Arduino
Stepper Motor Direction Control using Matlab
In the tutorial Stepper 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 stepper motor and to stop the stepper 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.
Stepper Motor Direction Control Using MATLAB
Stepper Motor Direction Control using NI LabVIEW
In the tutorial Stepper Motor Direction is Controlled in NI LabVIEW, I have controlled the clockwise and counter clockwise direction of the stepper motor using serial communication between NI LabVIEW and Arduino. Commands like C, S and are sent through NI LabVIEW towards Arduino for clockwise rotation of the stepper motor, stop the stepper motor and anti clockwise rotation of the same stepper motor respectively. There are three different buttons on the front panel of NI LabVIEW. These buttons are used to send commands C, S and 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.
Stepper Motor Direction Control in LabVIEW
Stepper Motor Direction Control using PIC Microcontroller
First of all I have made Stepper Motor Drive Circuit in Proteus ISIS and I have controlled the speed angle as well as the direction of the stepper motor using PIC micro controller. I have made a pretty simple logic. I have placed a serial terminal in my Proteus simulation. You have to sent the commands through that serial terminal. The stepper motor will change its direction as well the speed after manipulating those commands.
  • You can download the complete simulation here.
  • Download .rar file, extract it and start playing with the simulation.
Stepper Motor Direction Control using PIC Microcontroller

Stepper Motor Speed Control

In this section of Stepper Motor Projects, I will provide you the list of the tutorials in which I have already controlled the speed of the stepper 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.
Stepper Motor Speed Control using Arduino
In Stepper Motor Speed Control using Arduino, I have actually used the builtin command myStepper.step to control the speed for the stepper motor. For this purpose, I have not used PWM pins of L298 motor controller instead I only used input pins of it, to control the speed of the stepper motor. By assigning higher values to the myStepper.step motor can be rotated at higher speed. Similarly motor will rotate slowly if the value of myStepper.step is lower. All the executed commands are printed on the serial monitor and I have also printed those executed commands on LCD as well for this project.
  • You can download the complete Arduino Source code here.
  • Download .rar file, extract it and start playing with the simulation.
Stepper Motor Speed Control using Arduino
Stepper Motor Speed Control in Matlab
In Stepper Motor Speed Control in Matlab, I have created a  Graphical User Interface (GUI) in Matlab having two extra buttons as compared to the GUI of Stepper Motor Direction Control in Matlab. One for continuously accelerating the speed of the stepper motor and the other for continuously deaccelerating the speed of the same stepper 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 stepper motor.
  • You can download the complete simulation here.
  • Download .rar file, extract it and start playing with the simulation.
Stepper Motor Speed Control using MATLAB
Stepper Motor Speed Control using NI LabVIEW
This one is the last one among Stepper Motor Projects, named as Stepper 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 stepper 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 stepper 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.
Stepper Motor Speed Control using LabVIEW These are all Stepper Motor Projects posted yet on our blog. 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 :)

LCD Interfacing with Microcontrollers

Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to combine all of my previous tutorials for LCD Interfacing with Microcontrollers, at a single platform for your easiness. You will able to see and learn the interfacing of LCD with three different microcontrollers. Before going into any detail I would like to tell you a bit about the history of LCD. There are a lot of devices in the market now a days, which can be used as the displaying devices. LCD's are also among those devices and considered as the one of the most important devices specially for the microcontroller based projects. The word LCD is basically abbreviated from Liquid Crystal Display because it is made up of Liquid Crystal Technology. LCD is also a great debugging tool just like Serial Port. It becomes a lot difficult to use any debugger every time and is not reliable too. Where as LCD's can used to observe the output quickly while making changes in your code. It plays a vital role in almost all kinds of microcontroller based as well as electronic based projects. While making these types of projects we need to display the output and some messages. Seven segment is the basic the device to do that task but it has a lot of limitations. Another best option available is LCD. It comes in different dimensions. The most commonly used LCD's have dimensions of 16×2 i.e. 16 columns and 2 rows. It is capable of displaying 32 ASCII characters, 16 characters per line. Other dimensions of the LCD includes 20×4, 128×64 etc. You just need to know how to interface the LCD and then you will find that it is the easiest, cheapest and reliable output device available in the market. LCD has a wide range of applications e.g. robotics, power electronic based projects, microcontroller based projects, mobile phones, cameras, high resolution color displays.

LCD Interfacing with Microcontrollers

Here in the tutorial, LCD Interfacing with Microcontrollers, I will tell you about the configuration of the LCD, its pins specifications and about the procedure to interface it with different microcontrollers e.g Arduino, PIC Microcontroller and 8051. First of all, I would like to tell about the desired components and their specifications in the form of a list.
Components Required
The list for the basic and necessary components required while LCD Interfacing with Microcontrollers is given below.
  1. Microcontroller (Arduino, PIC, 8051)
  2. Jumper Wires (Male-female)
  3. Soldering Iron
  4. Soldering Iron and Gum
  5. Male Pins for LCD
  6. LCD (either 16×2 or 20×4)
Components Description
  • Microcontroller acts as the back bone of any project because it controls and handles all the tasks and is used to exchange the desired commands either serially or simultaneously. In the tutorial LCD Interfacing with Microcontrollers, I am going to use three different microcontrollers as the backbone of the project, i.e. Arduino, PIC microcontroller and 8051 microcontroller.These microcontrollers are shown in the figure below.
  • Jumper Wires are basically used for making the connections between microcontrollers and LCD in order to obtain the circuit in proper working condition. The jumpers wires are usually of for different types i.e. male-male, male-female, female-female and female-male. The jumper wires are shown in the figure below.
  • Soldering Iron is used to join the male pins with the LCD specifically in this case. Its a device or an electronic equipment used to make the permanent connections between two or more devices. Soldering Iron is shown in the figure below.
  • Soldering Gum and Stand are used for the purpose of clean soldering and supporting the solder respectively. The soldering gum along with the soldering stand is shown in the figure below.
 
  • Male Pins for LCD are used to make connect between LCD and microcontroller. These supporting pins are shown in the figure below.
  • Liquid Crystal Display (LCD) is used to display output messages and the desired results. LCD are available in the markets now a days, in different sizes. 16×2 and 20×4 are the most commonly used dimensions of the LCD. This type of LCD has 16 pins. Each pin is associated with the different function. The functions associated with each pin of the LCD are shown in the table below.
  • LCD can be operated in two different modes 4-bit mode and 8-bit mode, depending upon the selection of data pins. If we have selected four of its data pins (DB0-DB3) then LCD will be in 4-bit operating mode and if we have selected all of its data pins (DB0-DB8) the LCD will operate in 8-bit mode. 16×2 LCD is shown in the figure below.
  • Another most frequently used small LCD with 20×4 dimension is shown in the figure below.
  • For the proper working of LCD in 4-bit mode we need to use four of its data pins i.e. (DB4-DB7). In total we need to use 8 pins including RS, Enable, DB4, DB5, DB6, DB7, Voltage (5V) and Ground (0V). Data pins are used for the exchange of the data between microcontrollers and LCD.
  • RS is the pin 4 of the LCD and it selects data register when high and command register when low as described in the above table.
  • Enable is the pin 6 of the LCD. When it is high a low pulse is provided and it i used to send data to data pins (DB4-DB7) in this case.
  • So, that was the brief discussion of the components necessary for LCD Interfacing with Microcontrollers.
  • Now, I am going to combine all of my previous tutorials related to LCD interfacing with different microcontrollers here on a single platform.

New LCD Library for Proteus

In this tutorial, I have shared a new LCD library for Proteus which will help you in interfacing LCD with Arduino or any other microcontroller in Proteus ISIS. We have designed two new LCDs in Proteus. Proteus already has builtin libraries for LCD but they are not such good looking. So, I designed them which are good looking as compared to the builtin LCDs of the Proteus. I have provided two different libraries in this package. You just need to copy and paste them in libraries folder of your installed Proteus software. After restarting the Proteus software you will be able to search two different LCD's with excellent external look. Pick anyone of them from the search option and start interfacing it with the Arduino in Proteus and observe its working.
  • You can download these libraries here by clicking on the button below.
  • Download .rar file, extract it and enjoy these libraries.

Download LCD Library for Proteus

LCD Interfacing with Arduino

Here, in this section of the tutorial LCD Interfacing with Microcontrollers, I will combine my previous tutorials having detailed discussion about how to interface LCD with Arduino.
Scrolling Text on LCD with Arduino
Here, in the tutorial Scrolling text on LCD with Arduino, I have shared my knowledge with all of guys that how make an algorithm in Arduino software in order to generate a scrolling text on LCD. I have used a very basic 16×2 LCD in Proteus for this article. This tutorial will help you to learn how to interface 16×2 LCD with Arduino and how to display a scrolling text on it in Proteus. I have written a simple code to print the name of our website on LCD first, then I updated the same code for displaying the name with a movement in both left and right direction.
  • You can download the Arduio source for displaying scrolling text on LCD.
  • Download .rar file, extract it and enjoy the complete code.

Arduino Source Code

ADC Value on LCD using Arduino
In the tutorial ADC Value on LCD using Arduino, I have provided the detailed discussion about the circuit designing for LCD to interface it with Arduino. The design consists of two types of transformers named as current transformer and potential transformer. AC power is supplied to these transformers which is converted into 5V later. After designing the circuit properly I have designed an algorithm to display ADC values on LCD using Arduino. The second part of this section of the tutorial LCD Interfacing with Microcontrollers consists of the source code for displaying ADC values on LCD using Arduino in Proteus. The algorithm is very simple and is easy to understand. The function for displaying voltage is a bit complicated but not so difficult.
  • You can download the circuit designed in Proteus and the Arduino Hex file here by clicking on the button below.
  • Just download the .rar file, extract it and enjoy the complete package containing both Proteus design as well as Arduino Hex file.

Proteus Simulation & Arduino Hex File

LCD Interfacing with 8051 Microcontroller

In this section of the tutorial, LCD Interfacing with Microcontroller, I will explain you that how to interface an LCD with 8051 Microcontroller and the step by step procedure to design a simple program for 8051 microcontroller in order to display the messages on the LCD interfaced with it. In the tutorial, I have given a detailed discussion about both, the designing of the circuit in Proteus as well as the source code for printing the text on LCD using 8051 microcontroller. I have divided this tutorial in two different parts. The first part includes the designing of the circuit in Proteus whereas the second part contains the description about the embedded code for 8051 microcontroller. Source code is written using keil uvision3 compiler and 8051 microcontroller. I have used AT89C51.
  • You can download the complete Proteus design and the complete source code here by clicking on the button below.
  • Download .rar file, extract it and enjoy the complete package.

Proteus Simulation and Code

LCD Interfacing with PIC Microcontroller

Here, in this section of the article LCD Interfacing with Microcontrollers, I have shared a detailed discussion with all of you guys about designing a circuit for LCD interfaced with PIC microcontroller as well as about designing an algorithm to display ADC value on LCD using the same microcontroller i.e. PIC microcontroller.
Display ADC Value on LCD using PIC Microcontroller
In the tutorial Display ADC Value on LCD using PIC Microcontroller, I have elaborated the design of the circuit for LCD interfacing with PIC microcontroller and to display ADC values on LCD. Basically I have divided this task into two different parts. In the first part I have performed the task for Circuit Designing of LCD with PIC where as in the second part contains the code for displaying ADC values on LCD.
  • You can download the Proteus simulation here by clicking on the button below.
  • Download .rar file, extract it and enjoy the package.

Proteus Design

  • That was the combined version of my all of the previous tutorials related to LCD Interfacing with the three different types of microcontrollers.
So, that is all from the tutorial LCD Interfacing with Microcontrollers. I hope you enjoyed this tutorial. If you face any sort of problem regarding anything, you can ask me freely 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 different software e.g. Arduino, Keil uvision3, MATLAB, NI LabVIEW etc as well as the hardware based projects, in my later tutorials and will surely share them with all of guys as well. In my next tutorial I will explain about the different amazing tools of MATLAB e.g. command window, m.file, simulink and Graphical User Interface (GUI). So, till then, Take Care :)

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.
  1. clear all (used to clear the workspace window)
  2. 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 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 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 :)
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir