Flame Sensor Library for Proteus

Hello friends, I hope you all are fine and having fun with your lives. In today's tutorial, I am going to share a new Flame Sensor Library for Proteus. This Flame Sensor is not available in Proteus and its library is not yet developed anywhere. We are the first ones designing this new Flame Sensor Library for the first time. I am quite excited while sharing it as it's our team efforts that we are able to design new Proteus Libraries which are helpful for students.

We are planning to share more sensor libraries this week. I hope you guys are going to enjoy them and share them with your friends so that they can also know about them. Other bloggers are warmly welcome to share this library on their blogs but do mention our blog link in it as a favor. As this flame sensor is concerned, you can also interface it with any Microcontroller like Arduino, 8051 Microcontroller, PIC Microcontroller etc. It is also used in Embedded Systems Projects especially related to security.

If you have any questions, then ask in the comments. In this next tutorial, I will show you How to interface this Flame Sensor with Arduino in Proteus ISIS. So, now let's get started with this new Flame Sensor Library for Proteus.

Note: Other Proteus Libraries are as follows:

Flame Sensor Library for Proteus

  • First of all, download the Flame Sensor Library for Proteus by clicking the below button:
Flame Sensor Library for Proteus

  • Once you downloaded the file, extract it.
  • You will find three files in the zip file named as:
    • FlameSensorTEP.IDX
    • FlameSensorTEP.LIB
    • FlameSensorTEP.HEX
  • Now post the libraries files in the Library folder of your Proteus software.
Note:
  • Once you are done, restart your Proteus software and in the components, search for Flame Sensor, as shown in the below figure:
  • Now select this module and place it in your workspace and it will look something as shown in the below image:
  • The Flame sensor is shown in the above figure, it has four pins on it.
  • One of them is Vcc on which you need to give +5V.
  • The other one is GND which you need to ground.
  • The third one is the OUT pin, which will turn HIGH when this Flame sensor will sense the flame.
  • The fourth pin on the side is the TestPin, when it goes HIGH it means the sensor has sensed flame.
  • Because we can't actually bring flame in the Proteus software. :)
  • So, that's why we are using TestPin and when you make this pin HIGH, it will be like the sensor is sensing the Flame and it will give a HIGH signal on your output.
  • Now double-click your flame sensor and in the program file section, upload the FlameSensorTEP.HEX file which you downloaded in the above section and placed in the Library folder of your Proteus software as shown in below figure:
  • You should also have a look at these Arduino Projects for Beginners.
  • After uploading the Hex file now click OK and your sensor is ready to be used.
  • So, now design a simple circuit as shown in the below figure:
  • Now you can see I have applied +5V on Vcc and GND on GND.
  • I have attached a logic state on TestPin, now as the logic state is 0 means no flame was detected by the flame sensor, that's why the OUT pin is zero and the LED is off.
  • Now I am making the TestPin HIGH, and then you will see the OUT Pin will go HIGH and LED will go ON which means the Flame Sensor has detected the Flame, shown in the below figure:
  • Now you can see in the above figure that as I clicked the button the LED goes HIGH.
  • This example simulation is also given in the above file.
  • You should also interface it with different Microcontrollers like Arduino, 8051 Microcontroller, PIC Microcontroller etc.
  • I have also explained the same tutorial in the below video:

So, that's all for today. I hope you have enjoyed this Flame Sensor Library for Proteus. If you are new to Embedded Systems then you should first read this Arduino Tutorial for Beginners. Let me know your suggestions about this amazing Proteus Library. Thanks.

How to Configure NI MyRio on Wifi

Hello friends, hope you all are fine and having fun with your lives. In today's tutorial, I am gonna show you How to Configure NI MyRio on Wifi. In our previous tutorial, Getting Started with NI MyRio I have show you how to get started with NI MyRio and control LEDs of NI MyRio but you have seen that we have done that over USB. In simple words, we have controlled the LEDs and gyroscope of MyRio over USB but in today's tutorial, first of all, we are gonna configure NI MyRio on Wifi and then we are gonna control all those things over Wifi instead of USB.

If you have a project on MyRio then its my recommendation to use Wifi instead of USB for upload and testing your codes because Wifi is quite flexible in use and you no more restricted to use the USB wire. I was working on a robot project in which I have to controlled the motors using MyRio so when I was using the USB then it was really very difficult to design the algo because I have to connect my laptop to MyRio but when I shifted to Wifi then it was quite easy for me and I can easily upload the code and test it without connecting my laptop to MYRio. So, that's why before starting your project you should configure NI MyRio on Wifi. So, let's get started with How to configure NI MyRio on Wifi.

How to Configure NI MyRio on Wifi ???

  • First of all, connect your NI MyRio to your computer via USB and a window box will open up as shown in below figure:
  • Now click on the third button which says Configure NI myRIO.
  • When you click this button, a new link will open up in your default browser which in my case was Firefox.
  • In my case, this link doesn't open up and it may happen to you as well, so no need to be panic instead install the Microsoft Silverlight.
  • After installing the Microsoft Silverlight, it still doesn't open up in my browser :) and then I tried different browser and finally the Windows Explorer worked. :P
  • So, what you need to do is to paste this ip address in your Windows Explorer http://172.22.11.2/ and it will surely work. :)
  • When this ip address opens up it will show you a page as shown in below window:
  • Now, in this page click on the third button on your left side which says Network Configuration.
  • When you click it a new window will open up as shown in below figure.
  • Now in this window there will be two sections one is Ethernet and the second one is Wireless.
  • So, in the wireless section you have to fill the required boxes. First of all select the country which in my case is Pakistan.
  • Next select your Wireless network and then give your password as I have done in the below figure:
  • Once you are done then click on the Save button at the bottom and it will save your settings and will assign an IP adress to your NI MyRio.
  • This IP address will be used now instead of that previous one and you can easily upload your code in your NI MyRIO as its now configured with your laptop's Wifi.
  • You can see more details over this below video:
That's all for today. I hope I have conveyed some knowledge. In the coming lecture, we are gonna design our first program on NI MyRio and then will test it over Wifi. :) So take care and have fun !!! :)

Color Detection in MATLAB Live Video

Hello friends, I hope you all are fine and having fun with your lives. Today, I am going to show you Color Detection in MATLAB Live Video. In this project I am gonna take a live video feed from a camera and then will detect a specific color in that video feed. I have posted a project before in which I have done the same Color Detection in Images using MATLAB but that color detection was for images but in today's post I am gonna do the color detection in MATLAB for live video feed. I have designed this project in MATLAB 2009 and have also tested it on MATLAB 2015 and it works fine. So, I think it will work on any version of MATLAB. You must have the image processing toolbox in your MATLAB. If you got any questions then ask in comments and I will try to resolve them. So, let's get started with Color Detection in MATLAB Live Video: Few Image Processing Projects:

Color Detection in MATLAB Live Video

  • First of all, download the code from clicking the below button and open it in your MATLAB.

Download MATLAB Code

  • Now let me explain this code in detail.
  • One important thing, if you encountered some MATLAB project and you don't know how it works then the best way of testing is to paste commands one by one in your Command Window.
  • In this way you will understand the working of each command and will give you a better idea of how it works.
  • The complete MATLAB cofor Color Detection in MATLAB Live Video is as follows:
obj=videoinput('winvideo',1);
obj.ReturnedColorspace = 'rgb';
B=getsnapshot(obj);

framesAcquired = 0;
while (framesAcquired <= 10) 
    
      data = getsnapshot(obj); 
      framesAcquired = framesAcquired + 1;    
      
      diff_im = imsubtract(data(:,:,1), rgb2gray(data)); 
      diff_im = medfilt2(diff_im, [3 3]);             
      diff_im = im2bw(diff_im,0.18);                   
      %stats = regionprops(diff_im, 'BoundingBox', 'Centroid'); 
      
  
      % Remove all those pixels less than 300px
      diff_im = bwareaopen(diff_im,300);
    
    % Label all the connected components in the image.
     bw = bwlabel(diff_im, 8);
    
    % Here we do the image blob analysis.
    % We get a set of properties for each labeled region.
    stats = regionprops(bw, 'BoundingBox', 'Centroid');
    
    % Display the image
    imshow(data)
    
    hold on
    
    %This is a loop to bound the red objects in a rectangular box.
    for object = 1:length(stats)
        bb = stats(object).BoundingBox;
        bc = stats(object).Centroid;
        rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
        plot(bc(1),bc(2), '-m+')
        a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), '    Y: ', num2str(round(bc(2))), '    Color: Red'));
        set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'red');
    end  
 
    hold off
    
end

clear all
  • I have also added the comments in the code so that you can understand it in a better way.
  • But if you still got any problems then as k in comments and I will resolve them.
  • Now run your simulation and bring any red color object in front of your camera and you will see a bounding box will be formed around red color and it will also show the coordinated of that red color.
  • The results are shown in the below figure:
  • You can see in the above figure that I am holding a bottle cap which is of red color and our code is detecting that red color.
  • Moreover it has created a bounding box around that bottle cap and then showing the X and Y coordinates of that cap.
  • I have also mentioned the Color Red infront of it and the color of these coordinates is also RED.
  • You can change these colors as you want and can detect any color using this code.
  • Let me explain this code a little bit.
Code Explanation
  • First of all, I created an object for the video camera and then took images from that video using the below code.
  • In this code I have used 1 for video input. 1 is default for your webcams and if you have any external camera connected via usb then you have to use 2 instead of 1.
  • The code is as follows:
obj=videoinput('winvideo',1);
obj.ReturnedColorspace = 'rgb';
B=getsnapshot(obj);
  • After that I have created a while loop of 100 framesso it will keep on detecting the color for 100 frames and then it will stop you can increase or decrease it.
  • In this while loop, first of all I have subtracted the red color from each frame using the imsubtract command.
  • You can see the input of imsubtract is data( : , : , 1 ), where data is our image and 1 is used for red color subtraction, if you use 2 then it will subtract the green color so using these values you can subtract any color and infact you are detecting that color.
  • After that I have applied filter to remove the noise and have also removed the pixels less than 300px.
  • Then I have connected the dots of red color to create a single red object.
  • This code is as follows:
      data = getsnapshot(obj); 
      framesAcquired = framesAcquired + 1;    
      
      diff_im = imsubtract(data(:,:,1), rgb2gray(data)); 
      diff_im = medfilt2(diff_im, [3 3]);             
      diff_im = im2bw(diff_im,0.18);                   
      %stats = regionprops(diff_im, 'BoundingBox', 'Centroid'); 
      
  
      % Remove all those pixels less than 300px
      diff_im = bwareaopen(diff_im,300);
    
    % Label all the connected components in the image.
     bw = bwlabel(diff_im, 8);
    
    % Here we do the image blob analysis.
    % We get a set of properties for each labeled region.
    stats = regionprops(bw, 'BoundingBox', 'Centroid');
    
    % Display the image
    imshow(data)
  • Finally after the detection of this red color, I have created a bounding box around it and have also printed its coordinates.
  • The code is as follows:
for object = 1:length(stats)
        bb = stats(object).BoundingBox;
        bc = stats(object).Centroid;
        rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
        plot(bc(1),bc(2), '-m+')
        a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), '    Y: ', num2str(round(bc(2))), '    Color: Red'));
        set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'red');
    end
  • So, that's how I ma doing the color detection in MATLAB Live Video.
  • The below video will explain this Color Detection in MATLAN Live Video in more detail:
I hope you guys have enjoyed this Color Detection in MATLAB and are gonna use it your projects. That's all for today, will see you guys in the coming tutorials. Till then take care and have fun. :)

Motion Detection in MATLAB

Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a new project which is Motion Detection in MATLAB. In this project, I am gonna detect the motion in MATLAB. This project was designed for security purposes and the condition was to use MATLAB instead of PIR Sensor. We all know that PIR sensor is used for motion detection but for that we have to design a hardware but using this software we can easily detect any motion using MATLAB. In this project, I have used the webcam and then applied a simple image processing algorithm, designed in MATLAB. Using this algorithm I have detected the motion in the environment. That's a quite simple project and you are gonna like this one. The code and complete simulation is given below for download. So, let's get started with Motion Detection in MATLAB: You may also like:

Motion Detection in MATLAB

  • First of all download the Motion Detection in MATLAB simulation by clicking the below button:

Download the MATLAB Simulation

  • Once you downloaded the rar file, you will get two files in it, named as:
  • Comparison.m
  • Comparison.fig
  • Now open the Comparison.m file and run your simulation.
  • When you run the file a GUI will open up as shown in below figure:
  • Now you can see it has three buttons on it.
  • Press the first button which says Capture Image, so click this button and an image will be saved in the same directory and will also be shown in the first zone as shown in below figure:
  • Now, click on the Start Comparison button and the software will start and will start capturing from the webcam.
  • It will also show the captured image in the second zone and if there's no change then the text below will show No Change, as shown in below figure:
  • You can see as there's no motion in the room that's why it says No change in above figure.
  • Now, let's create some motion, so I am taking my hand in front of the cam and let's see what results we got in the below figure:
  • You can see in the above figure that as I placed my hand in the range of webcam, the below text changed to Change Detected. Btw it should be motion detected. :P
  • Once the software captures the motion it will indicate as well as stop and if there's no motion then it will keep on monitoring.
  • If you want to stop the comparison then simply click the Stop Comparison button and it will automatically stop.
  • Moreover, the software will also send character to the serial port, if you want you can receive it on any serial port.
  • Now let's discuss the codes behind these buttons.
MATLAB Codes
  • The code behind Capture Image button is as follows:
obj=videoinput('winvideo',1);
obj.ReturnedColorspace = 'rgb';

A=getsnapshot(obj);
axes(handles.axes1);
imshow(A);
imwrite(A,'A.jpg');
delete(obj);
  • In the above code, first of all, I created an object of the webcam and then took a screenshot from that webcam.
  • After that I saved that image in the project directory and named it as A.jpg.
  • If you check your project directory then you will find this image.
  • Now let's have a look at the code behind Start Comparison Button:
global go;
    go = true;
  while go

obj=videoinput('winvideo',1);
obj.ReturnedColorspace = 'rgb';
B=getsnapshot(obj);
axes(handles.axes2);
imshow(B);
imwrite(B,'B.jpg');
delete(obj);

global I1;
global I2;

I1 = imread('A.jpg');
I2 = imread('B.jpg');
%  convert images to type double (range from from 0 to 1 instead of from 0 to 255)
Imaged1 = im2double(I1);
Imaged2 = im2double(I2);

% reduce three channel [ RGB ]  to one channel [ grayscale ]
Imageg1 = rgb2gray(Imaged1); 
Imageg2 = rgb2gray(Imaged2);  

% Calculate the Normalized Histogram of Image 1 and Image 2
hn1 = imhist(Imageg1)./numel(Imageg1); 
hn2 = imhist(Imageg2)./numel(Imageg2); 

% Calculate the histogram error/ Difference
f1 = sum((hn1 - hn2).^2);  
%set(handles.text1,'String',f1)
serialOne=serial('COM1', 'BaudRate', 9600);
fopen(serialOne);
if f1 > 0.009
    fprintf(serialOne,'a');
    set(handles.text1,'String','Change Detected')
    go = false;
end
if f1 < 0.009
    fprintf(serialOne,'b');
    set(handles.text1,'String','No change')
   
end
fclose(serialOne);
  • This is the main code of this Motion detection in MATLAB project.
  • Here, again I am creating an object of the webcam and taking a screenshot.
  • After that I am saving this screenshot in the project's directory and I have renamed it as B.jpg.
  • So, now I have two images A and B.
  • After that I have converted both of these images to grey scale and calculated their histogram error and on the basis of this error I have detected the motion.
  • Finally I have created a Serial Port object, if you don't wanna use serial port then simply remove this code.
So, that's all for today, I hope you have enjoyed the motion detection in MATLAB. If you have any questions, then ask in comments and I will resolve them.

Hexapod Simulation in MATLAB

Hello fiends, hope you all are fine and having fun with your lives. In today's tutorial, I am going to share a new project designed in MATLAB and named as Hexapod Simulation in MATLAB. We all know about the Hexapod, its a special kind of robot which has six legs. Hexa is used for six so its quite obvious that hexapod has six legs on it.

I have designed this project on a client's request and today I thought to share it with you guys. Because this Hexapod simulation in MATLAB is designed after a lot of efforts by our TEP team that's why this simulation is not free to download but we have placed a small price on it so that engineering students can buy it easily. So, let's get started with Hexapod Simulation in MATLAB.

Hexapod Simulation in MATLAB

  • First of all, you need to buy this Hexapod Simulation in MATLAB by clicking the below button:

Buy This Simulation

  • When you buy this project, you will get three files in it which are named as:
  • Hexapod.m
  • RobotMotion.m
  • Robot Design.m
  • You need to open the first one named as Hexapod.m, this is the Main file for this Hexapod Simulation in MATLAB.
  • It has the below code in it:
clc;
clearvars;
close all;
imtool close all;
subplot(6,6,1:30)
xlabel('x'); ylabel('y'); zlabel('z'); 
axis([-150 200 -50 150 0 150])
grid on
hold on

Inc = 0;
firstLen = 50;
secondLen = 50;
stepSize = 20;
StepsTaken = 1;
y1 = 0;
y2 = 1;

RobotDesign(firstLen,secondLen)
subplot(6,6,31)
subplot(6,6,32)
subplot(6,6,33)
subplot(6,6,34)
subplot(6,6,35)
subplot(6,6,36)
OldInc = 0;
for b = 0:1:StepsTaken-1

subplot(6,6,1:30)
[Inc OldInc y1 y2]= RobotMotion(firstLen,secondLen,stepSize,Inc,OldInc, y1, y2);

end
  • As you can see in the above code, we can set different parameters like lengths of legs and the steps it can take etc.
  • Let me give a slight overview of Hexapod and how it works. So, have a look at below figure:
  • I have designed a small hexapod and I have colored its legs.
  • The red Color legs are called Gate 1 while the green color legs are called Gate 2.
  • Now, when a Hexapod moves its first three legs (Gate 1) which I have designed in Red Color are first moved in upward motion and after that the Gate 1 moves in the Forward Direction and then finally Gate 1 moves in downward direction.
  • After that the Gate 2 Legs are move in upward Direction and then Gate 2 Legs are moved in Forward Direction and finally Gate 2 moves in downward direction.
  • Now when all legs are moved in Forward direction then finally the Robot Body is moved in Forward Direction.
  • Let me summarize these steps:
  1. Gate 1 (Red Legs) moves in Upward Direction.
  2. Gate 1 (Red Legs) moves in Forward Direction.
  3. Gate 1 (Red Legs) moves in Downward Direction.
  4. Gate 2 (Green Legs) moves in Upward Direction.
  5. Gate 2 (Green Legs) moves in Forward Direction.
  6. Gate 2 (Green Legs) moves in Downward Direction.
  7. Robot Body moves in Forward Direction.
  • These are the 7 steps a hexapod takes to move a single step Forward.
  • Now in the above code, I have used some variables which are:
  1. firstLen = 50;
  2. secondLen = 50;
  3. stepSize = 20;
  4. StepsTaken = 1;
 
  • firstLen is the length of Gate 1 legs which I have set 50 rite now.
  • secondLen is the length of Gate 2 legs.
  • stepSize is how big the step should be.
  • StepsTaken is how much steps it should take.
  • Now when you run the simulation then the first thing you will get is shown in below figure:
  • AS I have given StepsTaken = 1 so it will just take one step, you can change it though and when it takes one step the final position of robot will be as shown in below figure:
  • Now, if you compare the above two figures then you can see the starting position of Hexapod in x direction was 0 but when it took first step then now its position is 20.
  • The below four graphs are showing the angles of your robot gates in radians.
  • The below video will explain this project in detail:
That's all for today. I hope you have liked this Hexapod simulation in MATLAB. Before buying this project you must watch this video so that you have a clear overview of this Hexapod simulation in MATLAB.

How to use C# ArrayList

Hello friends, I hope you all are fine and having fun with your lives. In today's post, we are gonna have a look at How to use C# ArrayList. I am gonna explain it in detail what is C# ArrayList and how to use C# ArrayList. But before going into the details of today's tutorial, you must first have a look at my previous tutorial which is How to use C# Array??? because C# ArrayList is quite similar to C# Array.

I am gonna use the same project which we have designed in our first lecture on C# named as Introduction to C# Windows Forms. So, you should also use the same project and as we know this project has one Button and one Text box. Just a recall that I have changed the Text of the button to Click Here and the name of the button to ClickHere. Similarly, I have changed the name of the text box to txtClick. Here's the image of that form:

So, let's continue with How to use C# ArrayList. :)

How to use C# ArrayList ???

Before going into the details of using C# ArrayList, let's first have a look at its definition i.e. what is C# ArrayList and why we have to use it.

What is C# ArrayList ?
  • C# Arraylist is like a bucket which is used to store data in it just like C# Arrays but there's a slight difference between the two. In C# ArrayList you can add or delete data at any time and the ArrayList adjusts itself automatically.
  • Addition or deletion of data in C# ArrayList is done by using indexes of those datas. So, when you add some data in it then the ArratList automatically got stretched and welcomed the incoming data in a new index. :) Similarly when you delete some data from the ArrayList then it shrinks and adjusts the data accordingly.
  • We are shortly gonna have a look at How to add or delete data in c# ArrayList and how it behaves.
  • Now you can see C# ArrayList is quite similar to Array with a slight difference.
  • C# ArrayList is used in old C# Programming but its kind of neglected in new C# Applications because in complex codes it becomes quite messy so the coders normally neglect it and use the alternative but if you have an encounter with any old C# Project then there's a big chance that you find C# Arraylist in it.
  • Now, let's have a look at how to initialize an ArrayList:
Initializing a C# ArrayList
  • In order to initialize a C# ArrayList, you have to use the below code:
// .... Initialization of C# ArrayList .....

     ArrayList TEP = new ArrayList();

// .... Ends Here ......
  • Now in the above code line you can see I have used the ArrayList as a datatype and then I have given my variable a name, which is TEP.
  • So, in simple words, I have created a ArrayList named TEP.
Note:
  • One important thing is you have to add using System.Collections; in the top section of your code otherwise system won't recognize the keyword ArrayList.
Adding Data to C# ArrayList
  • Now, let's add some data in our C# ArrayList, which we just created in the above section.
  • In order to add the data, we have to use the command TEP.Add(), where TEP is the name of our ArrayList while our data comes in the brackets.
  • So, let's add some data in our C# ArrayList by using the below code:
// .... Adding Data in ArrayList ....

     TEP.Add("The");
     TEP.Add("Engineering");
     TEP.Add("Projects");

// .... Data added in ArrayList ....
  • So, I have added three values in my TEP ArrayList.
  • Now, let's print them out.
  • So, in your Button Click function add the below code:
// ... Displaying values .....

     txtClick.Text = TEP[0].ToString();
     txtClick.Text += " , ";
     txtClick.Text += TEP[1].ToString();
     txtClick.Text += " , ";
     txtClick.Text += TEP[2].ToString();

// ... Values Displayed .....
  • In the above code, you can see I have called those values via their indexes.
  • Now your complete code will look something as shown in the below figure:
  • Now, in the above figure, you can see all the three steps i.e. initialization of C# ArrayList, then adding values in that ArrayList and finally displaying those values.
  • Now, when you click run your program and then click the button you will got your C# ArrayList in the text box as shown in below figure:
  • And you can see in the above figure that our TEP ArrayList elements are printed in the text box.
ArrayList Elements Count
  • Now, let's have a look at how to count the total number of elements in an ArrayList.
  • In order to do so, you have to add a small code in your button click function as given in below code:
// .... Display Values .....

      txtClick.Text = TEP[0].ToString();
      txtClick.Text += " , ";
      txtClick.Text += TEP[1].ToString();
      txtClick.Text += " , ";
      txtClick.Text += TEP[2].ToString();
      txtClick.Text += " , ";
      txtClick.Text += TEP.Count;

// ..... Values Displayed .....
  • You can see in the above code, I have added a small function to display the TEP Count and when you run it, it will show you the total values in your ArrayList as shown in below figure:
  • Now you can see the last figure is showing the total number of elements in that ArrayList.
Clearing a C# ArrayList
  • Now suppose you have created a C# ArrayList and now you wanna clear its values then you have to use a simple clear command as shown in below code:
      txtClick.Text = TEP[0].ToString();
      txtClick.Text += " , ";
      txtClick.Text += TEP[1].ToString();
      txtClick.Text += " , ";
      txtClick.Text += TEP[2].ToString();
      txtClick.Text += " , ";
      txtClick.Text += TEP.Count;
      TEP.Clear();
      txtClick.Text += " , ";
      txtClick.Text += TEP.Count;
  • In the above code, first of all, I have displayed the values of ArrayList and after that I have displayed the total elements in that ArrayList and then I cleared the ArrayList using TEP.Clear(); and then again displayed the total elements and because I have cleared the ArrayList that's why it will give you 0 this time because now there's no element in it as shown in below figure:

Now, I hope that you are well aware of ArrayList and can easily use it in your program if you have to. So, that's all for today, will see you guys in the next tutorial. Till then take care and have fun !!! :)

Speed Control of DC Motor using PIC Microcontroller

Hello friends, hope you all are fine and having fun with your lives. Today's tutorial is about speed control of DC Motor using PIC Microcontroller. I haven't written this tutorial by myself. Instead this tutorial is written by one of my very good friend Salah Dahouathi. We had an interaction through his awesome Facebook group Let's Think Binary and I would suggest you guys to join it as well, because he posted many projects in his group. So, after having a look at his work, I asked him to write for our blog which he gladly accepted and here's his first post. :) I hope you guys are gonna enjoy this one and will get knowledge out of it. So let's get started with this speed control of DC Motor using PIC Microcontroller tutorial.

Many applications in industry such us robotics controls, swing machines, electronic bikes, winding machines, Spinning and Weaving machines and many others applications need a variable speed of DC motor. The best method for speed control of DC motor is the use of Pulse Width Modulation technique. This is a method to control the output voltage with the of constant frequency switching and by adjusting on duration of switching and in other words by changing duty cycle of switching.

Speed Control of DC Motor using PIC Microcontroller

  • You can download the complete Proteus Simulation along with the Programming Code in MikroC Pro for PIC Compiler for Speed Control of DC Motor by clicking the below button:
Download Proteus Simulation

  • The scheme of the project is given in the circuit below :
  • Where :
    • CONTROL STAGE : The microcontroller is PIC16F877A
    • POWER STAGE : BUCK structure : L, C, D, MOSFET
    • INTERFACE STAGE : IR2110
  • Now in the above project, I have used IR2110 using which I have controlled the speed of DC Motor.
  • You can see the PWM pin of PIC Microcontroller is coming to IR2110.
  • Mr. Salah has designed the code in MikroC Pro for PIC compiler and the code is given below:
unsigned short current_duty1, current_duty2,dt;

void main()
{
  ADCON1 |= 6;                    // all ports as digital
  CMCON  |= 7;                  // comparators off
  TRISD = 0X03;
  PORTD=0;

 PWM1_Init(5000);                     // Initialize PWM module at 5KHz
 PWM1_Start();                       // start PWM1

 while (1) {                         // endless loop

    if (RD0_bit==1 && RD1_bit == 0)           // button on RD0 pressed
      {
      Delay_ms(40);
      //current_duty1=127;                 // Set duty ratio to 50%
      current_duty1=64;                 // Set duty ratio to 25%
                                         //   duty ratio can be calculated as (Percent*255)/100
      PWM1_Set_Duty(current_duty1);
      }
    else if (RD1_bit==1 && RD0_bit == 0 )     // button on RD1 pressed
      {
      Delay_ms(40);
      //current_duty1=192;                 // Set duty ratio to 75%
      current_duty2=216;                   // Set duty ratio to 85%
                                          //   duty ratio can be calculated as (Percent*255)/100
      PWM1_Set_Duty(current_duty2);
      }
     else
      {
       Delay_ms(40);
      dt=0;
      PWM1_Set_Duty(dt);

      }
     Delay_ms(10);                      // slow down change pace a little
   }
 }
  • In the above code, you can see he has used the PWM to do the speed control the DC Motor.
  • Few of important commands used in above code are given below:
    • PWM1_Init(constant long frequency) : This function initializes the PWM module with duty ratio 0. Frequency parameter is the desired frequency in Hz. It should be a numeric constant, should not be a variable.
    • PWM1_Set_Duty(unsigned short duty_ratio) : This function is used to set the duty cycle of the PWM. The parameter duty_ratio takes values from 0 to 255, ie 0 means 0% , 127 means 50% and 255 means 100% duty cycle. The PWM1_Init() routine must be called before using this.
    • PWM1_Start() : This function starts the PWM output. PWM1_Init() must be called before calling this routine,
    • PWM1_Stop() : This function stops the PWM output. PWM1_Init() must be called before calling this routine. PWM1_Start() should be called before calling this function otherwise calling this function will not have any effect as PWM module is not running.
  • When you run your simulation then in High speed it will look something as shown in below figure:
  • As you can see in the above figure that the voltage across DC Motor is around 18V and if you are running the simulation then you will see the motor will be moving quite fast.
  • Now let's move our motor in slow speed, in order to do that you have to turn ON Low speed switch as shown in below figure:
  • Now if you check the voltage across DC Motor then you can see its 6V and the Dc Motor will now move at slow speed.
  • Here's the video for the above project which will give you better idea of How it works:

That's all for today, thanks for reading Speed Control of DC Motor using PIC Microcontroller. I hope you have enjoyed this tutorial. In the end, I again wanna thanks to my dear friend Salah Dahouathi who has spend time in designing this great simulation, programming code and tutorial. You should also like his Facebook Group where he keeps on posting such Arduino related projects, name of his Facebook group is Let's Think Binary. So, will see you guys in next tutorial, till then take care and have fun !!! :)

Getting Started with myRio

Hello friends, I hope you all are fine and having fun with your lives. Today, I am going to share a tutorial on new board and as you can see in the title, this new board is named as Myrio. So, today, we are gonna have a look at getting started with Myrio. NI myRIO is a combination of dual-core ARM Cortex™-A9 real-time processing and Xilinx FPGA customizable I/O. It is specially designed for engineering students by National Instruments and is a cheap as well as an awesome piece for building your dream projects.

Recently I got a chance to work on this NI Myrio board and I really enjoyed while working on them as they not only awesome but also easy in programming. Moreover, because of its awesome speed you can ask it to do any kind of embedded work. You can read more about myRio on the Official Site of National Instruments. Today, I am not gonna design any project on this NI myRio board, instead I am gonna give you a quick overview of getting started with myRio. So, what's the delay :P Let's have a look at getting started with myRio board.

Getting Started with myRio

  • I ordered my myRio board about a month ago and I got it delivered within 10 days.
  • Below are the items which I have received in the myRio box:
    • myRio board itself.
    • USB Cable to plug myRio board with computer.
    • Three CDs which contains the software.
    • A manual having the instructions for myRio use.
  • If you have also ordered the myRio board then you must have also received the same things in the box.
  • Now first of all, what you need to do is to arrange a 12V adapter for power up your Myrio board.
  • The one I have used is of 12V and 1.5A.
Note:
  • There are different models of myRio available online and the one I received is myRio 1900, which has the Wifi functionality in it.
  • There's also another myRio board called myRio 1950 which doesn't has the WiFi functionality in it so if you got that one then there's no need to be worried as both boards works exactly the same so if you have any other model then still you can follow today's tutorial as its valid for all myRio boards.
  • Now I assume that you have arranged a 12V adapter and ready to plug it in your myRio board. :P
  • So, why are you waiting ??? :P Simply plug you adapter in the myRio board and two lights on it will get on as shown in the below figure:
  • So, you can see in the above figure that when I plugged the adapter in my myrio, the Power LED and the Status LED turned ON.
  • After some time the status LED will turned OFF.
  • Now next thing you need to do is to connect your USB cable with your computer from one side and with myRio from the other side.
  • As soon as you connect the USB cable, the myRio will start installing the driver on your computer. It will take some time.
  • Once the driver is installed, then a pop up window will open up as shown in below figure:
  • Now, if you got this pop up window then it means your myRio driver has installed successfully.
  • This window is giving you some information about your myRio board like mine is NI myRio 1900, yours could be 1950.
  • Now next thing you need to do is to click the first button which says "Launch the Getting Started Wizard".
  • Now when you click it, a new window will open up as shown in below figure:
  • Now in the above window, it is showing the connected NI myRio device, if you can't see your device then click on the Refresh button.
  • If your device is listed as mine then you need to press the Next Button.
  • When you press the Next button a new window will pop up as shown in below figure:
  • In the above window, you can change the name of your myRio board, if you want but I have left it as it is and clicked the Next button and below window opened up:
  • Now finally we have reached the control window, from this window we are gonna control all the four LEDs labelled as LED0, LE1, LED2 and LED 3 and also gonna get notification for the button pressed and will also get values for X, Y and Z axis.
  • IF your check your myRio board, rite now then you will see that LED2 and LED3 are ON now and you can see in above figure that LED2 and LED3 are green.
  • Now you can click these buttons to turn your respective LED ON or OFF.
  • Similarly when you press the button on your myRio board then this black small circle will go green.
  • Moreover, if you change the orientation of your myRio board then its axes values will also change as it has built in gyroscope.
  • You can check more detail on this below video:

So, that's all about getting started with Myrio. Today, we have seen how to get started with your new NI myRio board and also how to control the built in LEDs, button and gyroscope of myRio board. I hope now you can play a little with your myRio board. That's all for today. In the coming post, I am gonna discuss How to Configure NI myRIO on Wifi. So, till then take care and have fun !!! :)

How to use C# array

Hello everyone, hope you all are fine and having fun with your lives. In today's tutorial, we are gonna have a look at How to use C# Array. C# array is quite a simple concept but students normally got confused while using C# array that's why I am gonna explain it in a detail. C# array is used to store similar data in a single variable. Let me explain this with an example. Suppose you have 10 integer variables then what you need to do is to save all of these 10 variables in separate C# Int variables which will not only increase the size of your code but will also make it quite complex. So, instead of creating 10 separate C# Int variables you can simply create a single C# array and can add all of them in it.

Let's take an example for C# arrays from normal life. You can consider a classroom of a school as an array and its elements will be all the students in that class. :) So, if there's a 9th class then all the students in 9th class are the members of that 9th class array but the students of 10th class will not be members of 9th class array, instead they will be members of 10th class array. :P Now, a question arises that how to call a single member of any array then in that case for class arrays we have roll numbers. so you can call any member of 9th class by calling his roll number. Similarly, in C# array we have indexes for each member of an array and we can call individual members using these indexes, we will have a look at it below. The members of any arrary are normally called the Elements of that array. So, let's get started with C# arrays.

You may also like:

How to use C# Array ???

  • As I explained earlier, C# Array is used to store similar variables in it. So, instead of using individual variables, we can simply add all those similar variables in a single array.
  • So, an array is something as shown in below figure:

FirstArray[3] = {Element1, Element2, Element3};

  • Now the above array has a name FirstArray and it can has maximum three members in it which is shown in these [ ] brackets.
  • After that we have inserted the three members in it separated by commas.
  • Now, if I want to access the individual members of this C# Array then I have to call them by their indexes.
  • C# Array assigns an index to each of its elements and these indexes start from 0.
  • So, the first element of each C# Array is always 0.
  • So, if I call the 0th member of C# array then it will give me the first element of that array.
  • Let's see how to call each of them:
  • FirstArray[0] = Element1;
  • FirstArray[1] = Element2;
  • FirstArray[2] = Element3;
  • So, that's how we can call any of the C# Arrays elements.
  • Now let's design a simple projects and check it out in real example.
  • So, create a simple C# project as we did in Introduction to C# Windows Forms.
  • Now in this C# projects add some controls as we did in How to add C# Control in Windows Form.
  • I have added two controls in it which are Button and a Text Box.
  • The simple GUI is shown in below figure:
  • So, now let's add an array in this GUI and then display its elements in the text box on button click.
  • I am gonna add a C# string array so first of all, what I need to do is to declare the String C# array.
  • In order to do so use the below code:
// C# Array Initializing

String[] students = new String[5];

// Initializing Complete
  • So, you can see in the above code that I have initialized the C# array and in order to do so first of all, I have given the datatype of C# Array, which is String in the above case.
  • After that, I have given the name of the C# Array which is students and the I have used new word to create the new instance of C# array.
  • We will cover this new word concept in later tutorials but rite now its necessary to use it while initializing the C# array.
  • Finally I have given the length of array which is 5 in our case, so you can add maximum 5 elements in this C# array.
  • You can also make the length variable by simply removing this 5 as shown in below code:
// C# Array Initializing

String[] students = new String[];

// Initializing Complete
  • Now this C# String Array is of variable length means you can add any kind of members in it.
  • Now we have initialized our C# String Array, next thing we need to do is to add the values in it.
  • One way of adding values to the C# array is as follows:
// Adding values to C# Array.

students[0] = "Zain";
students[1] = "Nasir";
students[2] = "Kamraan";
students[3] = "John";
students[4] = "Jack";

// Values added.
  • Now you can see I have added five students in our C# Array and I have also assigned the index to each of them.
  • "Zain" is saved at index 0 of students array so it will be the first element of C# array.
  • That's one way of assigning values to C# array, here's another way:
// Adding values to C# Array.

String[] students = new String[5] {"Zain", "Nasir", "Kamraan", "John", "Jack"};

// Values added.
  • In the above code, I have added the values in the initialization, both ways are correct.
  • Now let's get the elements from this array and display them in the Text Box.
  • In order to do so, use the below code:
txtClick.Text = students[0];
txtClick.Text += " , ";
txtClick.Text += students[1];
txtClick.Text += " , ";
txtClick.Text += students[2];
txtClick.Text += " , ";
txtClick.Text += students[3];
txtClick.Text += " , ";
txtClick.Text += students[4];
  • One thing, I forgot to mention that I have changed the Name of the Button to ClickHere and Text of Button to Click Here. Moreover, I have changed the Name of Text Box to txtClick.
  • Now your complete code will look something as shown in below figure:
  • Now run your project and click the button and if everything goes fine then you will get results as shown in below figure:
  • So, you can see all the elements of our C# Array are now displayed in the Text box.
So, that's all about the C# Arrays, I hope you guys have got something out of it. That's all for today, will meet you guys in the next tutorial. Till then take care and have fun !!! :)

How to use C# Comments ???

Hello everyone, I hope you all are fine and having fun. Today's tutorial is a quick one and is about how to use C# Comments. Comment is an important part of any programming language, although its not a directly part but they indirectly help a lot especially in complex projects.

I have also shared a tutorial on How to use comments in c++, you should read that post as well because I have explained few basic concepts in it. You guys are also welcome to give us feedback about this new C# tutorial series. If you have any suggestions about it then do let us know in comments.

How to use C# Comments ???

  • Comments are simple documented text lines, completely ignored by the compiler and are used to explain or provide any additional information about coding.
  • There are 3 types of comments available in C#, which are:
    • Single Line Comments. ( Symbol used: // )
    • Multi-Line Comments. ( Initial Symbol: /* Closing Symbol */ )
    • XML Documentation Comments. ( /// )
  • Now, let's have have look at each one of them in detail:

Single Line Comments

  • Single Line Comments are used to comment any text in a single line, we have to place two forward slashes ( // ) and everything after that will be ignored by the compiler.
  • Let's have a look at How to use Single Line Comments, in below figure:
  • You can see in above figure, that I have used green comments above each block to explain my code i.e. mentioning 2D & 3D arrays, accessing array elements etc.
  • Moreover, I have also used comments in front of the line i.e. displaying data at location 0, 0 etc. In this case, I am just explaining a single line.

Multi-Line Comments in C#

  • We can also comment out multiple lines by using /* */ these symbols.
  • Let's say, you don't want to execute some part of your code i.e. 100 lines, then it would be too difficult to place // these symbols in front of each line.
  • In such cases, there's a need for Multi-Line Comments, here's an example:
  • At the top of above code, you can see I have used Multi-Line Comments to give a simple introduction, here you can also add description of your project/code.
  • Moreover, I have also commented out Console code, I just want output using For Loop and I have used Multi-Line Comments for that.

XML Documentation Comments

  • In Microsoft Visual Studio, when you hover your cursor on any object then it pops up an info box.
  • If you want to add any information in this pop up box then you need to use XML Documentation Comments, as shown in below figure:
  • In the above code, I have created a new class named TEPClass, we will discuss classes later in detail, but for now just focus on XML comment above that class.
  • In Program class, I have called TEPClass and now when I hover my cursor over it, you can see a pop up box appeared and it has that XML comment in it.
  • I have placed a red arrow in front of it, here we can place a short description of our class.

Why we need to use C# comments ???

  • Let's say you have to use some old code which you have designed a year ago.
  • Now when you read your own code after a year, it will be difficult to understand.
  • But if you have placed some check note (comments) for each command then you can easily understand it.
That's all for C# comments. I hope you guys have understood how & why we need to use C# Comments. In next tutorial, we will have a look at How to use If Loop in C#.
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