Interfacing PIR sensor with Arduino
Hello friends, i hope you all are fine and enjoying. Today i am going to share a new project tutorial which is Interfacing PIR sensor with Arduino. First of all lets, have a little introduction about the basics and working of the PIR sensor. PIR sensors are in fact a Passive Infrared Sensor. PIR sensors are actually electronic sensors and they are used for motion detection. They are also used to detect the Infrared waves emitting from a particular object. You should also have a look at PIR Sensor Library for Proteus, using this library now you can easily simulate your PIR Sensor in Proteus software.
PIR sensors are widely used in motion detection projects now a days. Since my today's tutorial is about interfacing of PIR sensor with Arduino micro controller. Before going to that it is necessary that we should first understand the construction and working principle of PIR sensor. So i am going to divide my tutorial into different blocks and i will describe PIR sensor from its construction to practical applications. So first of all, lets see the construction and operating principle of PIR sensor.
Construction of PIR sensor
The construction of PIR sensor is very simple and easy to understand. In the bottom or you can say in the core of the PIR sensor we have a set of sensors which are made of pyro-electric materials. The properties of this material is that when this material is exposed to heat then, it generates energy. Different methods are used to to measure this energy generated by PIR sensor. On the top of the PIR sensor and above the internal sensors we have a small screen through which infrared radiations enters into sensor. When these radiations falls on the pyro-electric material then it generates energy. Generally the size of this sensor is very small and it is available in the form of thin film in market. Many other materials are also used in collaboration with pyro-electric material like galliam nitrite and cesium nitrate and all these materials take the form of an small integrated circuit.
Operating Principle of PIR sensor
The modern studies in the field of quantum physics tells us the fact each and every object when it is placed at a temperature above absolute zero, emits some energy in the form of heat and this heat energy is in fact the form of infrared radiations. So an other question comes into mind that why our eyes can't see these waves? It is because that these waves have infrared wavelengths and his wavelength is invisible to human eyes. if you want to detect these waves then, you have to design a proper electronic circuit.
If you see closely the name of PIR sensor which is Passive Infrared Sensor. Passive elements are those elements that don't generate their own voltages or energy. They just only measures things. So we can say that this sensor is a passive infrared sensor and it doesn't generate anything by itself. It is only capable to measure the rediations emitted by other objects around it. It measures those raditions and do some desired calculations on them.
Interfacing of PIR Sensor with Arduino
PIR sensor have total 3 pins. The configuration of each pin is shown in the image given below:
- Pin#1 is of supply pin and it is used to connect +5 DC voltages.
- Pin#2 is of output pin and this pin is used to collect the output signal which is collected by PIR sensor.
- Pin#3 is marked as GND pin. This pin is used to provide ground to internal circuit of PIR sensor.
This whole configuration is also shown in the image given below:
The pin configuration of a PIR sensor is shown in the image given above. Since we have to interface the PIR sensor with Arduino micro controller. The image showing the interfacing of PIR sensor with Arduino is shown below as:
Interfacing Code
The code for interfacing Arduino micro controller with PIR sensor is given below as:
#define pirPin 2
int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;
void setup()
{
Serial.begin(9600);
pinMode(pirPin, INPUT);
}
void loop()
{
PIRSensor();
}
void PIRSensor()
{
if(digitalRead(pirPin) == HIGH)
{
if(lockLow)
{
PIRValue = 1;
lockLow = false;
Serial.println("Motion detected.");
delay(50);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW)
{
if(takeLowTime){lowIn = millis();takeLowTime = false;}
if(!lockLow && millis() - lowIn > pause)
{
PIRValue = 0;
lockLow = true;
Serial.println("Motion ended.");
delay(50);
}
}
}
Applications of PIR sensor
PIR sensors possess a no of applications and due to their low cost and much advanced features they are the main focus of different projects being made now a days. Some of their features and practical applications are listed below as:
- They are able to sense the detection of people and other objects.
- PIR sensors are also used in automatic lightening systems. In these type of systems, when a person comes in the vicinity of the sensor then, the lights are automatically turned ON.
- They are used in outdoor lightening systems and also in some lift lobbies. You may have observed that when a person comes in front of the lift and if the doors are being closed then, the doors are opened again. This is all due to PIR sensors.
- They are widely used in underground car parking system. At every parking position a PIR sensor is installed and when that position is vacant then, a green light glows over that place which means you can park here. And if that position has been occupied then, a red light will glow, representing that this position is already occupied.
- PIR sensor is much compatible sensor and it has the ability to detect a particular motion and the output of this system is very sensitive and doesn't have any kind of noise in it.
Alright friends, that was all from today's post. If you have any questions, fell free to ask. Till next tutorial Take Care!!! :)
Getting Started with Arduino Software
Hello friends, i hope you all are fine and enjoying in life. On a friends request, today i am going to share a new tutorial which is 'Getting Started with Arduino Software'. Previously i have uploaded a large no of project tutorials made on 555 timers and some MATLAB based Simulations. Now we are going to touch the next level and from now on we will work on mostly projects containing Arduino microcontroller.
To get started with Arduino microcontroller, we first need to learn the operating software of Arduino microcontroller. This tutorial is very informative and i will be using Arduino software 1.0.5. It is a very basic level software and very easy to learn. IF you have already worked on Arduino software then you don't need to go through it. This tutorial is only for begineers who have just bought the Arduino board and don't know wht to do with it. :)
This software is very user friendly. There are two versions of Arduino software available on theArduino official site. One isexe file which you need to install in your computer. While the second version is a simple rar file and you don't have to install the 'exe' file in your computer. You only copy the software at a particular folder and when you double click on it, it automatically starts to run. I will be explaining this tutorial in various parts. We will see all the options available in main menu and their functioning. Now i think we should move towards the actual working of the software and see how it woks and what are its control parameters.
Getting Started with Arduino Software
- First of all copy the Arduino software folder where you can easily access it. For example, copy the folder on desktop of your computer.
- Double click the folder and the next window will show all the sub-folders, which contains the libraries, hardware tools, references and all other things.
Note:
- If you haven't bought your Arduino UNO yet, then you can buy it from this reliable source:
- That window is also shown in the image given below:
- The above image is showing all the sub-folders and and the Ardunio running application.
- The above folder is showing the examples, drives, hardware, libraries, references, tools of the Arduino software.
- When you will double click on the icon named as 'ardunio' then arduino software will start to run.
- The next window which will open is shown in the image given below:
- A very important thing to note is that when we write code in Arduino software window then, it is called a sketch.
- This software automatically gives the name to the code, which you are going to write.
- For example i have open the command window of Arduino software, then it saves every sketch with that particular date on which you are gonna write that sketch.
- Since today is May 13, 2015 and this software has automatically saved the sketch with today's date.
- Now coming towards menu bar, we have 5 options. I will explain all of them one by one.
File Menu Description
- When you will single click the 'File' button then, a new window will open which is shown in the image given below:
- This list is showing all the components which are encoded in 'File' button.
- First option is 'new' and it will open a new window or new sketch. Next is 'open' and it will open the file or sketch which you will select and will try to open in Arduino software.
- Next options are 'sketch book' and 'examples'. When you will click the examples button then it will open the Arduino libraries.
- The Arduino libraries are shown in the inage given below:
- This option will give all of the Arduino libraries. Arduino libraries are very useful in learning the basic code of Arduino.
- For starters, you can go to the first option which is, '01. Basics' and it will give you some libraries of that projects which are very easy to understand.
- You can simply click on any option and the code will automatically load into Arduino software.
- Next options are 'close', 'save' , 'save as'. These options are very simple and every user is aware of these options.
- Next option is 'upload'. It is very important option and it will load the particular code into Arduino sketch file.
- Next option is of 'upload using programmer'. This option uploads the code into Arduino sketch which is written in some other software.
- Next option is of 'page setup'. It gives you the options about alignment of the page and what size of sketch you want to keep.
- Then comes the 'print' option and 'preferences'. When you will click on 'Preference' option then a new window will open and this window is shown in the image given below:
- This window will open and it will be showing sketckbook location. where you wish to save all your sketches. We will give it location only once and afterwards it will automatically save the file at that particular location.
- You can also select the language, in which Arduino sketch will be written and the font size can also be selected.
- This option also gives the check flag. For example either you want to update or Arduino software version or you tends to use the existing software and many other options.
- The last option in file menu is 'Quit'. By clicking on this option, Arduino software will close and the sketch which is running at that particular time will stop.
Edit Menu Description
- After file menu then comes the 'Edit' menu. When you will single click on that icon then, a new window will open, containing all the options which are ancoded in 'Edit' menu.
- That new window is shown in the image given below:
- The first 2 options in Edit menu are 'Undo' and 'Redo'. If accidentally something goes wrong then, you will press undo button and problem will be eliminated.
- Redo is the opposite of Undo option.
- Next options are 'cut' and 'copy'. Nearly all users are aware of their functions.
- The next option is 'copy from forum'. It will copy the sketch from a particular forum and will automatically save it into sketch window of Arduino software.
- The very option is 'copy as HTML'. This option is used at that place where, you want to upload your sketch or code.
- After writing you sketch, you just single click on this button and it will automatically convert the sketch language into HTML language and then you can easily upload it.
- Next option is of 'paste'. You copy the sketch from some other folder and you can 'paste' it in this sketch menu. and you can easily compile it.
- Next to paste option we have 'select all' option. Once you click on this option and the whole sketch will be selected. It's upto you either you want to copy it or whatever you want to do with the sketch.
- The next option is very important which is 'comment/un-comment'. For those people who have done the coding before and are aware of the basics it is a simple options.
- You bring the curser to any particular line and when you will first click on this button then, it will be commented. Which means physically this line is written in the code but logically it has no importance anymore.
- to avail this particular line, you will again click on that particular line and then it will be 'un-comment'.
- After un-commenting the line, now you can use it in code.
- Next option is 'increase indent', by single clicking on this option you will observe that the width of blinking curser has been increased.
- This is also very interesting feature in looking and also very beneficial for those people who have a little weak eye-side.
- And if you are not comfortable with this feature then, don't worry we also have a secondary feature for it.
- Then you will click on the next option named as 'Decrease indent' and it will automatically decrease the width of the curser and it will start to look like as before.
- The next option is very interesting and it is to find anything within your sketch.
- When you will click on that option, a new window will open which is shown in the image given below:
- In this window you can see that we have no of options. First bar is of find.
- Write in the first bar whats actually you want to find.
- And if you think something has gone wrong and you want to make changes in your code, you just simply write that things in 'replace with' menu and the whole code will be changed accordingly.
- Next options in the edit menu are 'find next' and 'find previous'. When you write something in find menu and the software finds it for you.
- Now if you want to find what's written next to those lines, you just simply click on that options and it will show whats next to that thing in sketch.
- Similarly you can also find whats written previous to that thing in our sketch.
Sketch Menu Description
- After edit menu we have 'Sketch Menu' in the list. When you will click on that option then, a new window will open which is shown in the image given below:
- In sketch menu we have total 4 options.
- The first option is 'verify/compile'. If you have written a code and when you will click on this option, it will verify the whole code and it will compile it and if there is no error then, the sketch will start running.
- Next option is of show sketch folder. By clicking on that icon, we will access that particular folder in which sketch has been saved.
- Next option is of 'Add file' and if you want to add any particular file in your sketch, you just simply click on that option and that file will be added in your sketch.
- The last option in sketch menu is very very important and it will enables you to 'import library' into your sketch.
- When you will click on that button then, a new window will open which is shown in the image given below:
- As you can see in the above shown image that in this software there are a large no of built in libraries and if you need to import any library in your sketch then, you can easily import it.
Tools Menu Description
- The next option in the main menu is 'Tools'. In order to explore it you just simply click on it and a new window will open, which is shown in the image given below:
- The very first option in 'sketch menu' is auto format and it will automatically give format to the sketch.
- Next are Archive Sketch, Fix encoding and reload.
- The most important option in tools menu is 'select board'. By clicking on this option a new window will open which is shown in the image given below:
- You can see that we have a large no of options available here .
- Its your choice to choose that Arduino board which you are going to use in your project.
- Next option is of programmer and when you will click on this button then a new window will open, which is shown in the image given below:
- You can see from here we can select that which type of programmer we are going to use in our project.
- The default setting for this version is AVRISP, as shown in the above image.
- The last option in tools menu is Burn Boothloader and the beauty of Arduino software is that it is capable to burn the code into its micro controller itself and no external burner is required for this purpose.
Help Menu Description
- This is the last option in menu and when you will click on it then a new window will open which is shown in the image given below:
- The help menu of Arduino software is very user friendly and it gives you ease to learn the software and to do something new.
- You can see that the very first option is 'getting started' and when you will click this option it will guide you about the features of the Arduino software. How we are going to use it and what are its basics?
- Other options are also related to help and are much informative, if you are writing a particular sketch and at any stage if you don't know what to do the next then, don't worry, Help will guide at every step.
- Now coming towards next menu, which is below the main menu, it has 5 major icons, which are shown in the image given below:
- In the above image you can see that, we have 5 major icons.
- The icon numbered a '1' is of 'verify'. After writing the whole code, you just simply click on that icon and it will verify the whole sketch and if there is any error then it will also generate error.
- The icon numbered as '2' is to upload the sketch into your micro controller.
- The icon numbered as '3' is of 'New'. By clicking on that icon a new menu will open and it will allow you to write a new sketch in it.
- The icon numbered as '4' is of 'open'. When you wish to open a existing file in your present code, you just simply click on that.
- The icon numbered as '5' is of 'save'. When you have written a particular sketch, you simply click on that and that sketch will be saved automatically.
- The last icon which is numbered s '6' is of serial monitor and after writing the whole code you just simply click on that and it will monitors the whole sketch thoroughly step by step.
- if any error will present at any stage then it will generate error.
Alright friends, that was all from today's post. Today's tutorial was very informative so i conclude that you hve learned something new today. Till next tutorial Take Care !!! :)
Display ADC value on LCD using Arduino
Hello friends, hope you all are fine and having good life. In today's project, we will see how to display ADC value on LCD using Arduino in Proteus ISIS. Its quite a simple project in which we are gonna measure the voltage of ADC pins and then will display them over to LCD. The microcontroller I am using in this project is Arduino. The simulation is designed in Proteus ISIS. IF you are working on PIC Microcontroller then you should have a look at How to Display ADC value on LCD using PIC Microcontroller in Proteus ISIS.
Arduino has 10 bit ADC pins so whenever you apply voltage on these pins it will give you a value ranging from 0 to 1023 depending on the voltage provided. One can easily get this value using a simple function in Arduino analogRead(); but the real problem is to convert this analog value into the actual voltage present on the pin. Suppose you are using A0 pin of arduino and you are providing 3.3V over to this pin, now when you use this analoagRead() function then it will give you some value say 543, but you wanna know what's the actual voltage at this pin which is 3.3V so now converting this 543 to 3.3 is a bit tricky part. It's not difficult but involves a little calculations, which I am gonna cover today in detail. Before going any further, make sure you have already installed the Arduino Library For Proteus, if not then first do it because without this library you won't be able to use Arduino board in Proteus. So, let's get started with How to Display ADC value on LCD using Arduino.
Display ADC value on LCD using Arduino in Proteus ISIS
I have divided this tutorial on How to Display ADC value on LCD using Arduino in few steps, follow these steps carefully and if you get into some trouble then ask in comments and I will try my best to resolve them, all the materials are provided at the end of step 1 for download but I suggest that you design your own so that you do mistakes and learn from them. Moreover, you should also have a look at these Arduino Projects for Beginners. Anyways, let get started:
Step1: Circuit Designing in Proteus
- First of all, I have designed a circuit in Proteus for Displaying ADC value on LCD using Arduino.
- In this circuit, I have used two transformers which I have named as Potential Transformer and Current Transformer. I am supplying 220V to these transformers which is then converted into 5V.
- I have set the turn ratio of these transformers such that they give maximum 5V at the output.
- Now,rest of the circuit is simple, I have just connected the LCD with Arduino so that we could display these ADC value over to LCD.
Note:
- Here's the circuit diagram of displaying ADC value on LCD using Arduino in Proteus ISIS:
- You can download the Proteus Simulation and the Arduino hex file for Displaying ADC value on LCD using Arduino by clicking on below button:
Download Proteus Simulation and Arduino Hex File
- It's quite simple and self explanatory. After designing the circuit diagram, now let's move to second step, which is code designing for Displaying ADC value on LCD using Arduino.
Step 2: Arduino Code Designing
- Now copy the below code and paste it into Arduino software. Compile your code and get the Arduino hex file.
- If you dont know How to get the hex file from Arduino then read Arduino Library for Proteus, I have explained it in detail there.
#include <LiquidCrystal.h>
#define NUM_SAMPLES 10
int sum = 0;
unsigned char sample_count = 0;
float voltage = 0.0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int PT = A0;
const int CT = A1;
float Cur;
float Vol;
float Power;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.setCursor(6,1);
lcd.print("Welcome To");
lcd.setCursor(5,2);
lcd.print("Energy Meter");
//delay(5000);
lcd.clear();
Constants();
}
void loop() {
lcd.setCursor(0, 2);
ShowVoltage(9, 0, PT);
Vol = voltage;
ShowVoltage(9, 1, CT);
Cur = voltage;
Power = Vol * Cur;
lcd.setCursor(7,2);
lcd.print(Power);
}
void Constants()
{
lcd.setCursor(0,0);
lcd.print("Voltage: ");
lcd.setCursor(0,1);
lcd.print("Current: ");
lcd.setCursor(0,2);
lcd.print("Power: ");
lcd.setCursor(14,0);
lcd.print("V");
lcd.setCursor(14,1);
lcd.print("A");
lcd.setCursor(12,2);
lcd.print("W");
}
void ShowVoltage (int x,int y, unsigned int value)
{
while (sample_count < NUM_SAMPLES)
{
sum += analogRead(value);
sample_count++;
delay(10);
}
voltage = ((float)sum / (float)NUM_SAMPLES * 5.015) / 1024.0;
lcd.setCursor(x, y);
lcd.print(voltage);
sample_count = 0;
sum = 0;
}
- The code is quite simple and self explanatory, the only difficulty is in ShowVoltage function. In this function, I have first taken an average of 10 ADC values and after that I have applied a simple formula over it and then it will start start giving the voltage value which I have simply displayed over the LCD.
- Now everything's done, so Get your Hex File from Arduino Software and let's check the results whether it displayed ADC value on LCD using Arduino or not
Step 3: Result
- We have designed the electronic circuit in Proteus and have also designed our code and uploaded the hex file in Arduino.
- Now press start button and you will see something like this:
- Now if you compare the voltages in voltmeter and on LCD, you can see they are exactly the same. You can check the value of variable resistor and the values in LCD will also change as the voltage in voltmeter change.
That's all for today, hope I have conveyed some knowledge today and now you can easily
Display ADC value on LCD using Arduino. In the next post we will explore more Arduino features. Till then take care and have fun !!! :)
Installation of Arduino driver in Windows
In today's tutorial, we are going to see how to install Arduino driver in Windows. In the previous post, we have seen what is Arduino? and why is it so popular and whats its use? Now, afer getting the basic knowledge of Arduino, the next step you need to do is to install Arduino driver in your computer so that it got recognized by your computer as Arduino. If you don't install the Arduino driver in Wndows then you won't be able to program Arduino using Arduino software.
tis tutorial is quite basic and is for the newcomers, who wants to start working on the Arduino software, if you have already run some codes on your Arduino then its not for you. You can skip it. Anyways, It's quite easy and it won't take much time. So let's get started with it.
Installation of Arduino driver in Windows
- First of all, download the Arduino software from Arduino official website. Download the most reent version of Arduino software, which is 1.6.3 while writing this post.
- After downloading the software, now plug your Arduino USB into computer.
- You will hear a small beep and Windows will try to intall the driver itself, but finally a yellow box will appear on the taskbar saying driver can't be installed.
Note:
- If you haven't bought your Arduino UNO yet, then you can buy it from this reliable source:
- So, now right click on your My Computer, open properties, then click on Device Manager and you will get a Window as shown in below figure:
- Now click on Other devices which is encircled in the above figure and you will get a new element named as Unknown device. This Unknown device is actually our Arduino UNO on which we are going to install the driver.
- Right click this Unknown device and then click on the Update Driver Software.
- As you click on it, it will give you two options so click on the below one which says Browse My Computer For Driver Software.
- On clicking it, you will get a Browse option, so now Browse in the Arduino software folder which you downloaded from the Arduino website and then open the drivers folder as shownin below figure and then hit NEXT button.
- After clicking the Next button, it will start installing the driver as shown in below figure:
- After the successful installation, it will show a window as shown below:
- So, now we have succesfully installed the Arduino driver for Windows and if you check it has also assigned the Com Port to Arduino, which is COM16 in my case, as shown in above figure.
- It will also be updated in the Device Manager as shown in below figure:
- That's it, Arduino driver in Windows is succesfully installed and now you can use it and can upload the programming code in it, which we will see in the next post.
Hope it helped you in some way. Let's meet in the next post. Take care and have fun.
What is Arduino ?
Hello friends, today I am posting a very basic tutorial on what is Arduino ??? In this tutorial I am gonna explain the basics of Arduino for the beginners. I am writing this tutorial because I got a lot of requests from the engineers in which they ask questions like what is Arduino ? What's the difference between Arduino and PIC? How to use Arduino? etc etc. So I thought of writing this topic. It's a very basic tutorial so if you are already familiar with this board and know the answer of this simple question
What is Arduino ??? then you can skip this tutorial but again you must read it once, may be you get something out of it. :)
I have posted a tutorial on Arduino Projects, in which I gave all the links of Arduino projects and tutorials posted on my blog, that's another reason for posting this tutorial. I am treating that Arduino Projects page as an ebook on Arduino so I am gonna post everything about Arduino as much as I can. And an ebook must have an intro chapter, which will be this one. So, let's get started.
What is Arduino ???
- Arduino is nothing but a simple microcontroller board which is normally used in engineering projects where there's a need to automate something.
- You can interface sensors with this board, can drive motors with this board, can plug switches in it etc.
- In old ages ( not old enough :P ), people used simple switches for turning ON a bulb so like you click the switch and the bulb is ON, it was quite a simple circuit, after that relays are invented and then engineers used 555 timer circuits in order to turn ON lights on some specific time. But the 555 timer circuits are quite big in size, so finally engineers discovered Microcontrollers in which there are simple OUTPUT and INPUT pins, so now if you want to turn on light at some certain time then you just simply plug the blub on output pin of microcontroller and then do some programming and add a timer to automatically turn on the bulb.
- So, the benefit of microcontroller is the circuit is quite simple and small in size.Moreover, its flexible, suppose you want to change the time of turning ON bulb then what you need to do is simply change the coding and it will be changed, but in 555 timer circuits you need to change the components in order to do so.
- Now, we know the use of microcontroller and also their benefit but thing is what is Arduino ??? In microcontrollers like PIC or Atmel, there's a small drawback.
- Suppose you want to work on PIC then you have to first design its basic circuit also need to design a power circuit to supply power to it and after that in order to upload the code in it, you have to buy a programmer/ burner as well. So, first of all you need to write the code for PIC Microcontroller and after that you need to upload code in it using a programmer and then plce PIC microcontroller back into the circuit and test, which is quite lengthy plus also got hectic when you are working on some project because you have to test code again and again.
- By the way, now advance programmers like PICkit2 and PICkit3 can be plugged on board but still you have to design the basic circuit so coming to bottom line, in order to do project with PIC or Atmel microcontroller you have to do soldering etc.
- But that's not the case with Arduino Board, Arduino has built in programmer and the basic circuit in it. So what you need to do is simply plug in Arduino with your computer via usb cable, get its software and start uploading code and also start testing.
- So, you don't need to plug unplug or do anything, simply upload the code and test. Moreover, it also has some very efficient tools using which you can test your output as well quite easily. Arduino board also has the pins on which you can simply plug your devices and can turn them ON or OFF. So, hats off to Arduino team for providing us a simple board which has everything on it.
- Another advantage of Arduino is that, because of its popularity all the electronic components also have the Arduino libraries which are free and using them you can operate that electronic component quite easily with Arduino. Its open source and hence its developing day by day.
Types of Arduino Boards
- There's a long range of Arduino boards available online, the basic Arduino board is named as Arduino UNO which is most widely used in projects.
- Arduino UNO has total 13 digital pins and 6 analog pins which are used for connecting sensors with them.
- Suppose you have a project in which you want to interface 30 sensors, then what you need to do ?? Now you need to buy another Arduino board named as Arduino Mega 2560. This board has around 70 pins on it which can be used as output or input and hence you can plug your sensors quite easily.
- Moreover, Arduino have also developed different shields like Arduino Ethernet shield. Using this shield you can provide internet access via Ethernet to your project.
- Then they have Arduino Wifi shield which is used for providing Wifi access to your project.
- They have also developed Arduino GSM shield for GSM or GPRS purposes, in short there's a wide range of Arduino boards available online.
- So which Arduino board you need to buy depends on the requirements of your project.
How to use Arduino ??
- Now I think you have got the basic idea of what is Arduino ? and why is it so popular ? So now lets have a look at how to use Arduino.
- When you order for your Arduino board, you will get a package similar to the image below:
- Along with this box, you will also have the USB cable, now take your Arduino board out of this box and plug the cable in it, connect the Arduino with your computer and you are ready to start working on it.
- In order to connect Arduino with your computer you have to install the Arduino drivers in Windows.
That's all for today, hope I have conveyed some knowledge and you now know the basics of Arduino i.e. what is Arduino ? and why to use Arduino.
Interfacing of Seven Segment with Arduino in Proteus
Hello friends, today we are gonna have a look on how to interface Seven Segment with Arduino in Proteus. In my last post, I have posted an Arduino Library for Seven Segment Display, which is designed by our team and is quite basic in functionality. So, if you haven't checked that post then first of all check that one and download the Arduino Library for Seven Segment Display as I am gonna use that library in today's post. Moreover, in order to run this library you are also gonna need to download Arduino Library for Proteus, using this library you will be able to use Arduino board in Proteus so also read that post and download this library and install it in your Proteus.
Again I am mentioning that its the first library designed by our team so its in basic stages, it has few functions and will only display the numeric on the seven segment display which is normally required. I am planning on adding more examples in the library for future use, which will increase the functionality. Anyways that's a future talk, let's start today's post.
What is Seven Segment Display?
Let's first have a look at what is Seven Segment Display. Seven Segment display is nothing but an electronic device used for displaying the numeric data. It's a complex form of LED matrix and is normally used in clocks, LCD displays, calculators etc where there's a need to display the numeric data. It has total seven leds in it which you can also count from above image and by turning these LEDs ON or OFF we can display any numeric on it. For example, have a look at the below image. In this image I have shown numeric 0 on seven segment. Now in order to do so, I just simply turn OFF the centered LED and turn ON all the corner LEDs and it becomes 0.
How does Seven Segment Work?
Now, let's have look at how it works. So, we have seen that Seven Segment is named seven segment because it has total seven LEDs on it so now what we need to do is to control these seven LEDs, also named as segments, and then we can display any character on it. There are two types of seven segments available in the market and named as:
- Common Cathode
- Common Anode
They both work exactly the same and has only a slight difference. They both has total seven pins and each pin is used to control each led and they have an extra pin which is named as Common Pin. In Common Cathode you have to GND this Common Pin, while in common Anode, you have to give +5V to this Common Pin. Have a look at this below image, we have labelled leds with respect to the pins.
Interfacing of Seven Segment with Arduino in Proteus
- Now we know all about Seven Segment Display and know how it works so let's interface Seven Segment with Arduino in Proteus.
- Now, I am assuming that you have installed the Arduino Library for Proteus and have also installed the Arduino Library for Seven Segment display.
- So, now open your Arduino Software and go to File>Examples>SevenSegment>Counting.
- Open this example, in this example I have added a counter which will start counting from 0 to 9 and once it reached 9 then it will start counting again.
- If you can't find this example then you must be making some mistake in installing the library, anyways the code is shown below.
Note:
- In order to run this example you will need two libraries, the inks are given below to download:
/*
Counting
This Arduino example is for Seven Segent display.
It will start the counter from 0 and will end up at 9
and will start again from 0.
This example code is in the public domain.
Created by Syed Zain Nasir at 14 March 2015.
You can get the explanation and latest version of this library at:
http://www.TheEngineeringProjects.com/
*/
#include "SevenSegment.h"
SevenSegment tep = SevenSegment(0,1,2,3,4,5,6);
char arr [10] = {'0','1','2','3','4','5','6','7','8','9'};
int index;
void setup(){
index = 0;
}
void loop(){
tep.display(arr[index++]);
delay(1000);
if(index == 11)
index = 0;
}
- Now open you Proteus Software and design the circuit in it as shown in below figure, I have also attached the file for download at the end.
- Now compile the code and gt the hex file and upload it in your Arduino Properties.
- Now Run the Proteus software, and you will see the seven segment display will start counting, a glimpse of it is shown in the below figure:
- Below is attached the Proteus file and the hex file for the counting example which you simply start and run but again I suggest that you should design it by yourself so that you get something out of it.
Download Proteus Simulation of Seven Segment with Arduino
- One last thing, any kind of contribution to this library from the readers is highly appreciated, design your projects and share codes with us and we will post them on our blog for other readers to get knowledge as knowledge is all about sharing.
That's all for today, hope it will help you in some way. Take care and have fun. :)
Arduino Library for Seven Segment Display
In today's post, I am gonna share a new Arduino Library for Seven Segment Display. In my recent project, I got a chance to work on seven segment displays, I have worked on them using PIC microcontroller but haven't got a chance to use them with Arduino. So, now as usual when I started working on them, I started searching for Arduino Library but I kind of got disappointed after getting quite heavy libraries for seven segments, and after a lot of search I thought of designing my own Arduino library for seven segment display, which I am gonna share in this post. :)
It's not very advanced library as we know seven segment displays are not too complex, so its quite simple and using it you can quite easily display any numerical digit on the seven segment display. Moreover, I have also included an example with the library which will start the counter from zero on seven segment display and keep on incrementing till 9 and after that it will start again from zero. Moreover, I have also posted the example about Interfacing of Seven Segment Display with Arduino in Proteus using this library, it will help you in better understanding of How this library works. You can download the working Proteus Simulation as well as hex file from that post.
Download Arduino Library for Seven Segment Display
- As I stated earlier, its a very simple Arduino Library for Seven Segment Display and it will only print the numeric on seven segment display, but I will work on it in future and will update it by adding more features in it.
- So, first of all click the below button to download the Arduino library for seven segment display.
Download Arduino Library for Seven Segment Display
- After downloading the library, place it in the libraries folder of your Arduino software.
- Now close your Arduino software and open it again.
- Go to File and then Examples and you will find SevenSegment in it and it will have an example which is named as Counting.
Functions in Arduino Library for Seven Segment Display
- I have added quite few function in it which are very basic and are very easy to use.
- The first function I have used is:
SevenSegment(int a,int b,int c,int d,int e,int f,int g);
- In this function, you need to give the pins of Arduino with which you are attaching your seven segment display. It will called as shown below:
SevenSegment tep = SevenSegment(0,1,2,3,4,5,6);
- Now tep is our seven segment object and we are gonna use it in rest of the example.
- The next function used in this arduino library for seven segment display is:
display(char c);
- This function will display the numeric on seven segment display which you will provide it.
- Moreover, it will automatically clear the screen before displaying any new character on the seven segment.
- It is called in the example as shown below:
tep.display('1');
That's all for today, in this next post you can download the example of how to
Interface Seven Segment Display Using Arduino in Proteus, it will help you in understanding of this library in detail.
Temperature Sensor 18B20 with Arduino
Hello everyone, in today's post we are gonna have a look at how to interface temperature sensor Dallas 18B20 with Arduino. There are many temperature sensors available in market like LM35, DHT11 etc but personally I like Dallas18B20 most of all, as it gives the most accurate result up to four decimal points. It operates on single wire and sends all data through this wire. Another advantage of this wire is you can interface multiple sensors with a single data line. You should also have a look at How to use 18B20 in Proteus ISIS.
In today's post, we are gonna get value from this sensor and then print it over the Serial Terminal as well as LCD. We will get the values in degree centigrade. Its not much difficult to interface 18B20 with arduino and also an Arduino library is also availble, using which you can quite easily interface 18B20 with Arduino. Let's get started with interfacing of 18B20 with Arduino.
Note:
Interfacing of Temperature Sensor 18B20 with Arduino
- As I explained earlier, it works on single wire and hence we are gonna need 1-wire library for Arduino along with 18B20 arduino library.
- Download both of these libraries by clicking on the below buttons:
Download One Wire Library Download Dallas Temperature Library
- After downloading the library, place it in the libraries folder of your Arduino Software.
- Now restart your Arduino software and you will find the Arduino folder in the Examples section.
- Next we need to interface our sensor 18B20 with Arduino so design your circuit as shown in below figure:
- So, connect the sensor 18B20 with Arduino as shown in the above figure, connections are quite simple and are as follows:
- Pin # 1 of 18B20 with GND
- Pin # 2 of 18B20 with Pin # 2 of Arduino.
- Pin # 3 of 18B20 with GND of Arduino.
- Add a pull up resistor of 4.7k ohm at pin # 2 of 18B20.
- Here's the images of hardware, we designed for this project, its a 20 x 4 lcd we have used:
- Below image shows the small 18B20 sensor, used in this project, it looks small but very efficient.
- Here's the image showing the complete project:
- Now, copy below code and upload it in your Arduino board and open your serial terminal.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
void setup(void)
{
Serial.begin(9600);
Serial.println("Welcome to TEP !!!");
Serial.println("www.TheEngineeringProjects.com");
Serial.println();
sensors.begin();
lcd.begin(20, 4);
lcd.setCursor(5,0);
lcd.print("Welcome to:");
lcd.setCursor(1,2);
lcd.print("www.TheEngineering");
lcd.setCursor(4,3);
lcd.print("Projects.com");
delay(5000);
}
void loop(void)
{
sensors.requestTemperatures();
Serial.print("Temperature : ");
Serial.println(sensors.getTempCByIndex(0));
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temperature: ");
lcd.print(sensors.getTempCByIndex(0));
lcd.print("C");
delay(1000);
}
- After uploading the code, when I start the project, it started showing the temperature values as shown below:
- As you can see, its giving the temperature of my room which is 23.56 degree centigrade.
- I have also designed a video for more demonstration which is given below:
- It's quite a simple code and is self explanatory but still if you need help ask in comments and I will help you out.
Interfacing of Multiple Ultrasonic Sensor With Arduino
Hello friends, hope you are having fun and enjoying life. Today, I am gonna post about interfacing of multiple Ultrasonic sensor with Arduino. In the previous post, we have seen Interfacing of Ultrasonic Sensor With Arduino and in this post I have interfaced single ultrasonic sensor but in projects especially related to robotics, we have to interface multiple ultrasonic sensors. For example you have an obstacle detection robot, now in order to detect obstacle in front of robot you have to place once sensor on the front side but now you can't detect any object present on left or right side of your robot, so you have to place two sensors one on the left side of robot and one on the right side so in this project you need to use total three ultrasonic sensors, one on the front, one on left and one on right side of robot. Similarly, in another project I have to move the robot in a maze having walls on the side of robots, and my task was to move the robot straight within these walls without hitting the walls. In that case, I also used two ultrasonic sensors on both sides of robot and then applied PID algorithm in order to avoid hitting the walls. So, in short its a common practice to use multiple ultrasonic sensor with Arduino and today we are gonna have a look at how to do it.
I have posted about the basics of Ultrasonic sensor and how it works in my previous post so I am not gonna go into that detail. If you haven't read it then I recommend that you should first read Interfacing of Ultrasonic sensor with Arduino. Now, let's get started with Interfacing of multiple ultrasonic sensor with arduino, which isn't that difficult. :)
Note:
- Other Proteus Libraries are as follows:
- I have also posted more examples on Ultrasonic Sensor Simulation in Proteus, have a look at them and you will get complete understanding of this sensor.
- Moreover, for hardware implementation of Ultrasonic Sensor with Arduino, check below posts:
Interfacing of Multiple Ultrasonic Sensor With Arduino
- Let me first summarize the working of ultrasonic sensor again. With ultrasonic sensor, what we need to do is to generate a trigger signal on its trigger pin for around 10 microsecond.
- As soon as the ultrasonic sensor gets this trigger signal, it sends out an ultrasonic signal.
- This ultrasonic signal then hits something and bounced back.
- Now, in order to check this bouncing signal, we have to read the Echo pin and check for how long it remains HIGH, and on the basis of this duration we calculate our distance with the object.
- This is the process for single ultrasonic sensor and when we are using multiple ultrasonic sensors, what we need to do is simply repeat the whole procedure for all the sensors one by one.
- First of all, we will generate the trigger pulse for first sensor and the read its echo pin and get the distance, then we generate the trigger pulse for second sensor and read its echo pin and so on for the third.
- So, here I am gonna use three ultrasonic sensor and the circuit diagram is shown below:
- I have tried my best while designing this image to make it simple but as there are too much wires so it has become a little complex.
- I am pointing out the pin configuration here so it will be easy for you to interface your sensors with arduino. The pin configuration is as follows:
- Vcc of all sensors will go into +5V of Arduino.
- GND of all sensors will go into GND of Arduino.
- Trig Pin of first sensor into Pin # 3 of Arduino.
- Echho Pin of first sensor into Pin # 2 of Arduino.
- Trig Pin of second sensor into Pin # 4 of Arduino.
- Echo pin of second sensor into Pin # 5 of Arduino.
- Trig Pin of third sensor into Pin # 7 of Arduino.
- Echo pin of third sensor into Pin # 8 of Arduino.
- After connecting the pins as discussed above, now copy the below code and upload it in your arduino board.
- After uploading the code in your arduino, open the Serial Terminal of Arduino software and you will start receiving the distances for all the three sensors.
#define trigPin1 3
#define echoPin1 2
#define trigPin2 4
#define echoPin2 5
#define trigPin3 7
#define echoPin3 8
long duration, distance, RightSensor,BackSensor,FrontSensor,LeftSensor;
void setup()
{
Serial.begin (9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
}
void loop() {
SonarSensor(trigPin1, echoPin1);
RightSensor = distance;
SonarSensor(trigPin2, echoPin2);
LeftSensor = distance;
SonarSensor(trigPin3, echoPin3);
FrontSensor = distance;
Serial.print(LeftSensor);
Serial.print(" - ");
Serial.print(FrontSensor);
Serial.print(" - ");
Serial.println(RightSensor);
}
void SonarSensor(int trigPin,int echoPin)
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
}
- The code is quite similar to the one we used while interfacing single ultrasonic sensor with arduino, the only thing we changed here is the repetition.
- Before, we were using the same function SonarSensor() but calling it only once for our single sensor interfaced with arduino but now we are calling it three times for all the three sensors.
- Its kind of a generic code, you can interface more sensors with it if you want and what you need to do is only calling this function for the next interfaced sensor.
That's all for today, I think we have posted a lot on the ultrasonic sensor so I am not gonna post any more tutorial on this sensor and now I will start writing on some other sensor. You should also have a look at
Arduino Projects for Beginners. Thanks for reading and share it with your friends and help us grow. :)
Interfacing of Ultrasonic Sensor With Arduino
Today, we are gonna have a look on How to Interface Ultrasonic Sensor with Arduino. Few days ago, I have posted a complete tutorial on How to Use Ultrasonic Sensor Library in Proteus and later I have posted different examples on How to Simulate Ultrasonic Sensor in Proteus. Those posts were about Proteus Simulations and weren't about hardware interfacing, so I thought today let's interface it in hardware.
Simulation is a good starting point for projects but they are really far away from real world. It happened to me a lot of times that my simulations are working perfectly fine but when I design the same circuit in hardware then it says no I am not gonna work. :) So, the bottom line is never trust simulations, unless you properly test it on hardware. So, today I am gonna interface an Ultrasonic sensor with arduino and will check its output on the Arduino Serial Terminal.
1. Introduction to Ultrasonic Sensor
- "Ultrasonic Sensor HC-SR04 is a simple sensor which emits Ultrasonic Radiations from its transmitter and is used for measuring the distance between sensor itself and any obstacle in front of it. The sensor has a transmitter and a receiver on it."
- This sensor consists of four pins, which are:
- Vcc (+5V) : You need to provide +5V at this Ultrasonic Sensor HC-SR04 Pin.
- Trig (Trigger) : It's a trigger Pin where we need to provide a trigger after which this sensor emits ultrasonic waves.
- Echo : When Ultrasonic waves emitted y the transmitter, hit some object then they are bounced back and are received by the receiver and at that moment this echo Pin goes HIGH.
- GND : We need to provide ground to this PIN of HC-SR04 Ultrasonic Sensor.
Note:
- If you haven't bought your components yet for this project, then you can buy them from these reliable sources:
[ultimate_spacer height="13"]
|
[ultimate_spacer height="13"]
|
- Trigger pin is an output pin while the Echo pin is an input pin, we will discuss them in Working section in detail.
- Moreover, it requires +5V to start operating.
- It is normally used to detect objects in front of it or to measure the distance between different objects.
2. Working of Ultrasonic Sensor
- Its working is quite simple, as discussed above, it has a trigger and an echo pin.
- A signal of +5V is sent over to Trigger pin for around 10 microseconds in order to trigger the sensor.
- When ultrasonic sensor gets a trigger signal on its trigger pin then it emits an ultrasonic signal from the transmitter.
- This ultrasonic senor, then goes out and reflected back after hitting some object in front.
- This reflected ultrasonic signal is then captured by the receiver of ultrasonic sensor.
- As the sensor gets this reflected signal, it automatically make the Echo pin high.
- The time for which the Echo pin will remain HIGH, depends on the reflected signal.
- What we need to do is, we need to read this time for which the echo pin is high, which we are gonna do in our next section.
- So, let's have a look at Ultrasonic Sensor Arduino Interfacing.
3. Interfacing of Ultrasonic Sensor With Arduino
- Now we have seen the working of Ultrasonic sensor, so we have some idea what we need to do in order to get the values from it. Let's now have a look at Ultrasonic Sensor Arduino Interfacing.
- First of all, we need to generate a signal of 10 microsecond and then send it over to trigger pin.
- After sending the trigger pin we then need to read the echo pin and wait for it to get HIGH.
- Once it got HIGH then we need to count the time for how long it remained HIGH.
- On the basis of this time, we are gonna calculate the distance of the object from the ultrasonic sensor.
- So, first of all, interface your ultrasonic sensor with arduino as shown in below figure:
- Now, use the below code and upload it your arduino board. After uploading the code, open your serial terminal of Arduino software and you will start receiving the values.
#define trigPin1 8
#define echoPin1 7
long duration, distance, UltraSensor;
void setup()
{
Serial.begin (9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
}
void loop() {
SonarSensor(trigPin1, echoPin1);
UltraSensor = distance;
Serial.println(UltraSensor);
}
void SonarSensor(int trigPin,int echoPin)
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
delay(100);
}
- Now if you check in the SonarSensor() function, we are generating a pulse of 10 microsecond and sending it to trigPin, which is the trigger pin of our ultrasonic sensor.
- After sending this pulse weare using a funcion pulseIn() , its a builtin arduinofunction and is used to check for how long the echoPin remains HIGH.
- This value is further saved in the duration value and after that we have divided this duration by 2 because the pulse is first sent and then received so in actual it covers double distance, so we need to divide it by 2 in order to get distance between object and the sensor.
- Furthermore, it is again divided by 29.1, which is basically the speed of ultrasonic sound and finally we saved it in a variable named distance which is now in centimeters.
- After uploading the sketch in Arduino, you need to open the Serial Terminal and you will start receiving the values of distance.
That's all for today. I hope you have enjoyed this Interfacing of Ultrasonic Sensor with Arduino. It wasn't that difficult, in our coming post we are gonna
Interface Multiple ultrasonic sensors with Arduino and will get their values on the serial terminal. Till then Take care and have fun !!! :)