Vibration Sensor Library for Proteus

Update: We have created a new version of this library, which you can check here: Vibration Sensor Library for Proteus V2.0.

Hello friends, I hope you all are fine and having fun with your lives. Today, I am going to share a new Proteus Library named Vibration Sensor Library for Proteus. This Library is designed by our team on TEP and it's not yet published anywhere. We are the first creator of this Vibration Sensor Library for Proteus. This Library contains just one Vibration Sensor named SW-420. I will post a tutorial soon on interfacing this SW-420 Vibration Sensor with Arduino. This library is compatible with all the microcontrollers like Arduino, PIC Microcontroller or 8051 Microcontroller etc. You should also have a look at Analog Vibration Sensor Library for Proteus.

Using this Library you can now easily Simulate your Vibration Sensor in Proteus ISIS software. As we can't produce real vibration in the Proteus environment so that's why I have placed a TestPin in this Vibration sensor. If you send 0 at this TestPin then it means no vibration and if you sent 1 then it means we have some vibration. The Library is given below for download along with a simple simulation of this vibration sensor. So, let's get started with Vibration Sensor Library for Proteus:

Note: Other Proteus Libraries are as follows:

Vibration Sensor Library for Proteus

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

  • When you download the file then it will contain three files named as:
    • VibrationSensorTEP.IDX
    • VibrationSensorTEP.LIB
    • VibrationSensorTEP.HEX
  • Place all these three files in the Library folder of Proteus software.
Note:
  • Now restart your Proteus software if it's already open.
  • In the components search box, you have to search for Vibration Sensor, and you will get Vibration Sensor SW-420.
  • Now place it on your Proteus workspace and it will look something as shown in the below figure:
  • You can see in the above figure that our sensor has four pins, which are:
    • The first one is Vcc so apply +5V here.
    • The second Pin is GND so apply ground here.
    • The third Pin is OUT, it's the output pin from where you get whether there's vibration or not.
    • The fourth Pin is TestPin and if it's HIGH then it means you have vibration and the OUT PIn will go HIGH and if it's LOW then it means there's no vibration and OUT Pin will also be LOW.
  • Now the last thing you need to do is to double click this sensor to open its Properties.
  • In the properties, you will find a Program File, in this section browse to your file VibrationSensorTEP.HEX which we just downloaded and placed in the Library folder of Proteus software.
  • Once uploaded now you can use your Vibration Sensor in Proteus, the hex file is adding the functionality in this Vibration Sensor.
  • Now let's design a simple example to get an idea of how this sensor works.
  • So, in order to do that, design a simple circuit as shown in the below figure:
  • Now run your simulation, when you make TestPIN LOW, the sensor won't give any output and when you make TestPIn HIGH, the sensor will give an output, which means vibration is detected as shown in the below figure:
  • The above image is quite self-explanatory. :P
  • The below video will give you a better idea of how it works:

That's all for today. I hope you will enjoy this Vibration Sensor Library for Proteus. I have just added one module right now but I am gonna add more soon. You should also have a look at these New Proteus Libraries for Embedded Systems Projects. Take care !!! :)

Home Automation Project using XBee & Arduino

Hello friends, I hope you all are fine and having fun with your lives. Today, I am going to share a new Home Automation Project using XBee & Arduino. Home Automation Project is a most commonly designed project by the engineering students. So, that's why I have thought to create a complete Home Automation Project so that engineering students can get benefit out of it.

We all know about automation which is originated from automate or automatic. In automation the task is done automatically and you don't need to control it. In normal Home automation project, there are few sensors which are displayed wirelessly to user and there are few controls like user can ON or OFF Lights, Fans etc via remote or mobile App.

In this Project, I have used Arduino UNO board and I have designed its complete working simulation in Proteus software, so that users got sure that its working perfectly. Because we have to work a lot in designing this complete working simulation of home Automation Project that's why its not free but you can buy it for a small price of $50. In this price, you will get the compelte Arduino code along with the working Proteus Simulation. But before buying this project, must have a look at the details below so that you are sure what you are buying. So, let's get started with Home Automation Project using XBee & Arduino.

Home Automation Project using XBee & Arduino

  • You can buy the complete working Proteus Simulation along with the Arduino Programming Code by clicking the below button.
  • You can pay via Paypal and the download link will be instantly available to you and if you don't have the PayPal account then use our Contact Us Form and we will find some other way for you.

Buy This Project

1: Overview
  • First of all, let's have an overview of this Home Automation Project.
  • In this Project, I have designed two simulations, one simulation is for Remote using which we are gonna control our appliances and the second simulation is for the controlling of these appliances.
  • So, when you press buttons from your remote section, a wireless command will be sent to the control board and it will turn ON or OFF the respective load.
  • Moreover, there's an LCD on the Remote on which you will also check the values of the sensors.
  • So, in simple words, the remote will be in your hand and using this remote you can easily turn ON or OFF your appliances and can also check the status of your different sensors wirelessly.
  • Let's first have a look at the remote section:
Remote Control:
  • In Remote Control Section, I have used the below main modules:
    • Arduino UNO: Microcontroller Board.
    • KeyPad: Commands will be sent by clicking this Keypad's buttons.
    • LCD (20 x 4): For Displaying Sensor's Data & Commands.
    • XBee Module: It's an RF Module used for sending wireless commands.
  • Now when you click any button on your Keypad, a command is sent from Arduino to XBee Module and the XBee module then forwards that command to other XBee on the Control Unit.
  • Moreover, when the Control Unit sends the Sensors' data on xbee then Arduino receives that data and then displayed that data on LCD.
  • Here's the block diagram of Remote control section which will give you a better idea of its working:
  • Here's the Proteus Diagram of our Remote Section:
  • In the above Proteus Simulation of Remote Control, you can see that we have Arduino UNO board which is connected with LCD, KeyPad and XBee Module.
  • Working of this Remote section will be discussed in the later section.
  • Now let's have a look at the Control Unit Side of Home Automation Project.
Note:You must also have a look at below tutorials because I have interfaced these modules separately with Arduino as well: Control Unit:
  • In the previous section, we had an overview of the Remote section, now let's have a look at the Control Unit.
  • The Control Unit is the Unit which is being controlled by the Remote Control.
  • The Main components of Control Unit are:
    • Arduino UNO: Microcontroller Board.
    • Relays: Used to control the appliances. I have added eight relays so you can control eight appliances.
    • Lamps: Indicating the Bulbs.
    • DC Motors: Indicating the Fans.
    • Smoke Sensor: Used to detect the Smoke.
    • Flame Sensor: Used for Fire detection.
    • DS18B20: Used to measure atmospheric temperature.
Note:
  • On this Control unit, the Arduino UNO is getting the data from the smoke sensors and then sending this data via XBee to Remote Control.
  • We have seen in the previous section that this data is then displayed over LCD.
  • Moreover, when any button is pressed from the Remote Control, the command is received by this Arduino via XBee.
  • On receiving this command, Arduino UNO then turns ON or OFF the respective relay which in turn ON or OFF the respective appliance.
  • Here's the block diagram of this control unit:
  • You can see in the above block diagram that I have connected three sensors with Arduino and Arduino is receving their values and then sending these values to the remote control via XBee.
  • Moreover Relays are also connected to Arduino and then loads are further connected to these Relays.
  • So, Arduino is controlling these Relays which in turn are controlling the loads.
  • I have used eight relays and hence eight loads.
  • The Loads I have used are all DC loads because Proteus doesn't have AC active loads in it but you can place AC loads as well.
  • Here's the Proteus Simulation of Control Unit:
  • You can see all the modules are present in it.
  • Eight relays are present on the right side and their outputs are going into the loads.
  • I have used four lamps and four DC Motors.
  • Now let's have a look at their operation.
Note:You should also have a look at below tutorials in which I have interfaced these sensors separately with Arduino:
2: Operation
  • I have already mentioned their operation in above section so I am not gonna discuss it in detail.
  • But let's have a little talk about their operation.
  • First I am gonna discuss the operation of Remote Control:
Remote Control:
  • The remote Control has an XBee module which is used for wireless communication.
  • The Keypad has buttons on it so now when you press button "1" on the keypad then the Signal is sent via XBee to Control Unit.
  • The control unit will automatically turn on the first load when it will receive the command from button "1" of Remote Control.
  • When you press "1" for the first time then the first load will turn ON but when you press button "1" again then the first load will go off.
  • So, its like if you want to turn it ON then press it and if you want to turn it OFF then press again. (Quite simple :P)
  • As there are eigth loads, so button "1" to "8" are working for loads "1" to "8" respectively.
  • Moreover, when sensor's data come from control unit then it is updated in the LCD of Remote Control.
  • Now let's have a look at the operation of Control Unit:
Control Unit:
  • As the Control Unit is concerned, it keeps on waiting for the command from remote and whenever a command is received from the Remote Control, it turns ON or OFF the respective load.
  • Moreover, it also sends the data of sensors continuously to the Remote Control.
  • For this wireless communication, XBee is used here.
3: Working
  • This is the last section of this project where will will have a look at the working of the project.
  • I haven't divided this section in parts instead I have create a video which will explain the working in detail.
  • Here's the First look of Remote section image while working:
  • Now when the Sensor's data come from the remote Section then it will be displayed in the LCD as shown in below figure:
  • You can see in the above figure that both sensors are detecting and the temperature is also displayed in the LCD.
  • Now the complete working of this project is shown in the below video which will give you complete idea of this project:
Note:
  • If you buy this project and you are unable to run it properly then we will provide you free service and will make it work on your laptop perfectly. :)
So, that's all for today. I hope you have liked this Home Automation Project and are gonna buy this one. But again before buying it must read this tutorial and also watch the video so that you get complete understanding of this project.

Interfacing of Flame Sensor with Arduino

Hello friends, I hope you all are fine and having fun with your lives. Today, I am going to share a new tutorial which is Interfacing of Flame Sensor with Arduino. I have recently posted a tutorial in which I have shared the Flame Sensor Library for Proteus. Now in this tutorial, I am gonna use that Flame Sensor Library and will interface this Flame Sensor with Arduino. So, if you haven't downloaded this file then I suggest you to download this Flame Sensor Library so that you can easily simulate this flame Sensor in Proteus.

I am sharing interfacing of this Flame Sensor with Arduino today, but soon I will also post a tutorial on Interfacing of Flame Sensor with PIC Microcontroller. If you guys have any questions then ask in comments. I have also given the Simulation file and the Programming code below to download. But I would recommend you to design this proejct on your own so that you make mistakes and then learn from them. So, let's get started with Interfacing of Flame Sensor with Arduino:

Interfacing of Flame Sensor with Arduino

  • You can download the complete Proteus Simulation along with Arduino programming code from the below button:

Download the Simulation

  • Now design a small Arduino code as given below:
#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

int Flame = 7;

void setup() {
  Serial.begin(9600);
  pinMode(Flame, INPUT_PULLUP);
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print("Flame : ");
  lcd.setCursor(1,2);
  lcd.print("www.TheEngineering");
  lcd.setCursor(4,3);
  lcd.print("Projects.com");
}

void loop() {
  if(digitalRead(Flame) == HIGH){lcd.setCursor(8,0);lcd.print("Detected    ");}
  if(digitalRead(Flame) == LOW ){lcd.setCursor(8,0);lcd.print("Not Detected");}
  
}
  • Add this code in your Arduino software and compile it to get the Hex File from Arduino Software.
  • Upload this hex file in your simulation and then run your simulation and if everything goes fine then you will get something as shown in below figure:
  • In the above figure, you can see the sensor is off that's why in the LCD its written that no smoke detected.
  • Now, let's bring some Flame by clicking the Logic State on Flame Sensor and you will see the below results:
  • Now you can see in the above figure that when the Flame is detected then the LCD indicated that Flame has detected.
  • That's how we can easily simulate the Flame Sensor with Arduino.
  • I have explained this project in detail in the below video:
That's all for today. I hope you have enjoyed this project and now you can easily interface your Flame Sensor with Arduino in Proteus ISIS.

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 !!! :)

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