Access Linux Server of Arduino YUN with Putty

In today's post we are gonna see how to connect Arduino YUN with Putty and access the files on Linux OS in Arduino YUN. In my last post Getting Started With Arduino YUN, I have explained in detail about basics of Arduino YUN. I am recall few important things here. Arduino YUN is a very powerful board with two processors on it. One is Arduino microcontroller used to control the output / input pins. The other processor is named as Atheros and it has Linus operating system on it, so one can easily run python scripts on it and can do any server or client side coding in it.

So, today we are gonna see ow to access this Linux operating system of Arduino YUN using Putty software in Windows. Putty is a third party software used for accessing serial terminal, perform telnet or SSH communication etc. So using this software we can easily access the Linux OS on Arduino YUN. So let's have a look how we are gonna do this.

Access Linux Server of Arduino YUN with Putty

  • First of all, download the putty software.  Its a free software and you can download it quite easily using google.
  • After downloading the software, open it and you will have a screen similar to below image:
  • Now first of all select the SSH, which is shown in above figure by # 2, then give the IP address of your arduino YUN and Port will remain 22. If you don't know how to get the IP address of Arduino YUN then read Getting Started With Arduino YUN.
  • After adding this information, click on the Open button and for the first time, it will show a window similar to below image, simply click on YES.
  • This above Window will appear only when you are using putty for the first time, it won't appear afterwards.
  • After clicking YES, the below Window will open up asking for Login as:
  • When it asks for login, give log in as "root" and the default password is "arduino".
Note:
  • If you have changed the password in first tutorial Getting Started With Arduino YUN, then give that password now.
  • When you will be typing the password, nothing will appear on putty that's common so you just simply type the password and hit ENTER.
  • Now once you entered the password, it will get connected and you will get the below window.
  • Now you are in the root folder of your Arduino YUN Linux operating system, now its just like a command prompt or Linux Command Line.
  • Let's write some commands and test it out. Check out the below image:
  • In the above figure, you can see the first command sent is "cd .." to go into previous folder.
  • After that I send the command "cd mnt/sda1" to access the sd card, its the default folder for sd card.
  • Next command I sent is "ls", it will show all the files or folder present in the sd card. Currently I have just one folder in my sd card named as Shell.
  • After that I updated the opkg package by giving command "opkg update".
  • As I am connected with internet on my Arduino YUN sield, so its automatically downloaded and updated and finally I got "Signature check passed".
  • Next I installed a new package named as nano. In order to install it I used the command "opkg install nano". Nano is kind of notepad in Linux.
  • Now we are gonna write a python script, so I typed "nano TEP.py", and after entering this command the below window will open up.
  • In this window, you can write your python script and press Cntrl+X to Exit and it will ask for the save. Hit Y to save and N to No, and when you press Y then it will be saved.
  • Let's check it out whether its saved or not, and in order to do so we have to again send the same command "ls" and it will give us the folders and files as shown below:
  • You can see now we have TEP.py as well along with Shell folder.
  • So, today we have seen how to connect Arduino YUN with putty and access the Linux side of YUN. Afterwards we tested few commands and also check how to write a python code in YUN.
That's all for today, in the coming post of Arduino YUN I will show you how to connect Arduino YUN automatically with Wifi using python scripts. Till then take care and have fun. :)

PIC Microcontroller Projects

Hello everyone, hope you are fine and having fun with you life.Here I am gonna post all the PIC Microcontroller Projects links, which I have posted on my blog. I am gonna make it as guide, in which I will start from very beginning and slowly will move into the pro projects. First of all, I am gonna post about basics of PIC Microcontroller, how it works? how you can write program in it? What are the software used for PIC Microcontroller Programming? Which compilers are available for PIC Microcontroller Programming? etc. So, if you are new to PIC Microcontroller and you wanna design PIC Microcontroller Projects, then here's the guide for you. Follow all these tutorials from beginning and if you feel any problem then ask in comments and I will try my best to resolve your issues.

One more thing, don't just read the posts here, instead make them practically run on your boards. Its the best way of learning because just reading the posts won't help you in understanding the problems occurred while designing PIC Microcontroller Projects. So, the best way of learning about PIC Microtroller is by reading and then implementing. Another thing electronic projects and particularly PIC Microcontroller Projects never work perfectly in the first run, and it will happen that you will thought you are doing everything perfectly fine but still not getting the required output, which is quite common. So be patient while implementing your PIC Microcontroller Projects and if you are not getting the required output then just test and test again because you must be making some slightest mistake and not realizing it. :)

All the tutorial links below are completely designed by TEP team and thus TEP owns all the rights for these projects. They are for educational purposes and if you wanna share it then do mention us, that will be a great favor. And I am mentioning again that when you got into some trouble then do ask in comments and I will surely help you out.Moreover, you can also share your PIC Microcontroller projects with us and we will post them on our blog for the others to learn. So, now let's started.

Basics of PIC Microcontroller - Must Read

Below tutorials are the basic tutorials for PIC Microcontroller, which are must learn for the engineer who are planning to work on PIC Microcontroller. Just read and understand them as they will go you the basic information about PIC Microcontrollers. If you already know the basics then you can skip this section but still I recommend you to read them once at least.

  • Getting Started With Microcontrollers ? In this tutorial, I have given an overview of Microcontrollers. Its a very basic tutorial so if you are already familiar with the concept of microcontrollers then you don't need to read this article but its always good to have a taste of basics. :)
  • Getting Started With PIC Microcontrollers ? After covering the basics of Microcontrollers, next thing I have covered is the basics of PIC Microcontroller, because we are dealing with PIC Microcontroller Projects here. So, first we will have the basic intro of PIC Microcontroller and then we will move forward.
  • Functions available in PIC 18F452 Microcontroller ? In this tutorial, I have discussed the basic functions available in PIC18F452 Microcontroller. I have used this PIC Microcontroller in most of my tutorials so that's why I have first highlighted its main features.
  • Top 3 PIC C Compilers ? Now, we have decided which Microcontroller we are gonna use so now let's discuss the C Compilers for PIC Microcontroller. So, I have discussed top 3 PIC C Compilers in this post and have a given kind of a comparison here. Its a must read post.

Compiler Installation guide for PIC Microcontroller - MPLAB

These tutorials are about compiler installation for PIC Microcontroller, Compilers are used to design the programming code for PIC Microcontroller. There are numerous Compilers available in market. The most commonly used compilers are :

  • MPLAB
  • MikroC Pro For PIC
  • CCS Compiler For PIC

MPLAB is official compiler from Microchip and thus is free to use while the other compilers are paid but they have trial versions for testing. Personally I like MPLAB compiler as it gives the complete control over PIC Microcontrollers. After MPLAB, I work on MikroC Pro For PIC Compiler, as it has many built in functions and libraries which reduces the codes and thus efforts quite a lot.

  • How to Install MPLAB Software in Windows ? MPLAB is official compiler of PIC Microcontroller so in this post, I have discussed in detail how to install this MPLAB software in Windows. Using this software you can only design assembly language code for PIC Microcontroller.
  • How to Install MPLAB C18 Compiler in Windows ? Now that you have installed the MPLAB software so now its time to install its C18 Compiler so that we can write our codes for PIC Microcontroller Projects in C Language instead of Assembly Language.
  • Getting Started With MPLAB ? Now that we are done with the installation of compilers so now its time to get started with MPLAB software so that's why I have given an overview of how to get started with MPLAB compiler.

PIC Microcontroller Projects

Below are different projects designed on PIC Microcontroller, I have posted them in sequence from basics to pro. The list is quite short rite now because I haven't posted much on PIC Microcontroller yet but it will keep on increasing, whenever I am gonna post any new project on PIC Microcontroller, I will add the link below.

How to use LDR Sensor in Proteus

In today's post, I am gonna share how to use LDR sensor in Proteus. Proteus, as we all know, is a very handy software and is used for circuit and PCB designing. It is also used for circuit and programming testing. It is normally used by engineers in their projects and contains a vast list of built-in components. I have posted a lot of tutorials on Proteus and I have got quite a positive feedback from the reader about these tutorials. So, I thought to share another component in Proteus which is quite hidden and I haven't seen much posts on it available online.

So, in today's post, first I am gonna explain what is LDR sensor? and we will see where it is used and how it is used. After that I will design a simple circuit in Proteus in which I will turn control a LED using LDR sensor andwill make it ON and OFF. So, as usual let's start from the beginning so that the newcomers could also get benefit from it.

What is LDR Sensor?

  • LDR is an abbreviation of Light dependent resistor. It is also known as photoresistor or photocell.
  • Its symbol is shown in the below figure:
 
  • LDR Sensor is used for the detection of light, internally it has a resistance which is sensitive to light as shown in the symbol.
  • Whenever light falls on the LDR sensor, its resistance start decreasing and when it comes to dark then its resistance start increasing. Using the value of resistance one can easily detect whether there's light or not.
  • It is normally used in light activated switches.For instance, you have seen the automatic street lights, which go ON when its night and automatically go OFF when its day time. In those street lights, LDR sensors are used.

Working of LDR Sensor

  • As I explained above, it has an internaal resistance which is very sensitive to light intensity and varies according to it.
  • So, one thing is quite clear that LDR sensor is an analog sensor. It gives us different values depending on the light intensity falling on it.
  • Let's have a look on the simplest circuit of LDR sensor, which is shown in the below figure:
  • Now if you check the above image you can see we have placed a resistor in series with the LDR sensor and have applied a voltage source across them.
  • Now when the light will fall on the LDR sensor, its resistance will go LOW and in return the voltage across the LDR will also go LOW and as the LDR will come in dark, the resistance will go HIGH and in return the voltage will also go HIGH.
  • Its the simplest working phenomena of LDR sensor. Now if you are using the LDR sensor with some microcontroller then what you need to do is simply give this intermediate connection of resistor and LDR to microcontroller.

Circuit Designing of LDR Sensor in Proteus

  • Now we know the basics of LDR sensor and have also seen how it works so now let's design its circuit in Proteus.
  • There are two types of LDR sensors available in Proteus which are exactly the same in functioning but are different in operating. Both are shown in the below figure:
  • The first one has a digital display along with it on which the voltage value is displayed while the second one a bit more animated and has a torch with it, so when you press the up arrow the torch will come closer and in other words the light is falling on the LDR and when you press the down arrow the the torch will go away and your LDR is in dark now.
  • Both of these states are shown in below figure:
  • Now you can see both the states quite clearly, in the first state torch is away so LDR is in dark while in second state, torch is close so LDR is ON.
  • So, now let's design their circuit to control a LED with LDR Sensor in Proteus. In order to do so, design this simple circuit in Proteus as shown in below figure:
Note:
  • I have also designed this circuit on hardware and tested, it works perfectly as shown in the simulation.
  • Its a very simple circuit in which I am using a comparator and then giving output to LED. When the LDR is in dark then the LED will remain OFF and when the LDR will go into light then the LED will turn ON.
  • Both of these states are shown in below figure:
  • Now you can see when the voltage on the digital display of LDR were LOW then the LED was OFF and when Iincreased the voltage then the LED went ON.
  • Now let's check both of these states with the second LDR sensor in Proteus, which are shown in the below figure:
  • Again quite obvious, when the torch was away then LDR was in dark and the LED was OFF but in second state when I moved the torch close the LED went ON.
  • Here's the Proteus Simulation of LDR sensor attached below, download and play with it. :)

Download LDR Sensor in Proteus Simulation

That's all for today, if you have any problem ask in comments and I will reply them. Take care and have fun !!! :)

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:
/* 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.

Send data to Serial Port in MATLAB

Hello friends, hope you all are having fun and enjoying life. In today's post we are gonna see how to send data to serial port in MATLAB. Its a requested tutorial, asked by a follower and after giving him the code, I thought to share it on our blog so that others could also get benefit from it. We have discussed serial port many times and have seen how to communicate with it using different software but we haven't yet discussed how to send data to serial port in MATLAB. So, in today's post I am gonna share the complete code for sending data to serial port in MATLAB.

Serial port is most common way of communication, we can send or receive data using serial port. Normally, in engineering projects there's a need to send or receive data from microcontrollers to computer and in such projects, we used serial communication as its easy and quite quick in communication.

Send data to Serial Port in MATLAB

  • Its a quite simple project in which I am gonna send character over the serial port in MATLAB.
  • In order to do so first of all, I am gonna create an object and assign it to serial port object in MATLAB.
  • After that I am gonna set the properties of that serial port object.
  • After setting the properties, what we need to do is simple start our serial port object.
  • Once its started, now you can send any character via that serial port object.
  • After sending your desired characters, now what you need to do is simply close the serial port.
  • Closing the serial port is very essential in MATLAB because if its left open then you can't open it again in MATLAB and you need to restart your computer so be careful.
  • Here's the simplest code for sending the data:
  • Code 1:
tep=serial('COM1', 'BaudRate', 9600); fopen(tep); fprintf(tep,'a'); fclose(tep);
  • Now you can see, its too simple, we just set the com port with which we want to communicate and after that we gave the bud rate.
  • In the next line, we open our serial port object.
  • Now as our serial port is open, we can send any character to it. In this code, I am sending 'a' to serial port in MATLAB.
  • And finally I closed the serial port, which is very necessary as otherwise when you run this code again, it will start giving error.
  • Here's a bit explanatory code and much more flexible as you can change any property of Serial Port in MATLAB, you want to change.
  • Here's the code:
  • Code 2:
clc clear all close all disp(' Welcome to TEP!!!'); disp(' '); disp(' www.TheEngineeringProjects.com'); disp(' '); tep=serial('COM1'); % assign serial port object set(tep, 'BaudRate', 9600); % set BaudRate to 9600 set(tep, 'Parity', 'none'); % set Parity Bit to None set(tep, 'DataBits', 8); % set DataBits to 8 set(tep, 'StopBit', 1); % set StopBit to 1 %display the properties of serial port object in MATLAB Window disp(get(tep,{'Type','Name','Port','BaudRate','Parity','DataBits','StopBits'})); fopen(tep); % Open Serial Port Object fprintf(tep,'a'); %Print character 'a' to the serial port disp('Charater sent to Serial Port is "a".'); fclose(tep); %Close Serial Port Object
  • The code is quite self explanatory plus I have also added the comments in the code which will help you in understanding the code but still if you have any problem, then ask in comments.
  • Here's a screen shot of the above code:
  • Wen you run this code, you will get a below response in your MATLAB window:
  • Till now, we have seen how to send a single character defined in the m file of MATLAB, now let's make it a bit complex and send user defined data.
  • Now before sending the data, we will first ask the user to enter the data, he wants to send to serial port. Tis data could be a single character or could also be a combination of characters.
  • In order to do so, we are gonna use Input command in MATLAB and code is as follows:
  • Code 3:
clc clear all close all disp(' Welcome to TEP!!!'); disp(' '); disp(' www.TheEngineeringProjects.com'); disp(' '); tep=serial('COM1'); % assign serial port object set(tep, 'BaudRate', 9600); % set BaudRate to 9600 set(tep, 'Parity', 'none'); % set Parity Bit to None set(tep, 'DataBits', 8); % set DataBits to 8 set(tep, 'StopBit', 1); % set StopBit to 1 %display the properties of serial port object in MATLAB Window disp(get(tep,{'Type','Name','Port','BaudRate','Parity','DataBits','StopBits'})); fopen(tep); % Open Serial Port Object data = input('Enter character: ', 's'); %Ask user to Enter character fprintf(tep,data); %Print character 'a' to the serial port disp('Charater sent to Serial Port is:'); disp(data); fclose(tep); %Close Serial Port Object
  • The screenshot of code is as follows: (I am adding the screen shot of code because its colored and thus helps better in understanding the code)
  • Now when you run this m file, you will get results as shown in below figure and now you can see I have sent my blog url via serial port in Matlab.
  • I think we have played enough with sending data via serial port in MATLAB, now you can send any data via serial port in MATLAB, for example you can also create an infinite loop and keep on sending data to serial port.
  • That's all for today, in the coming post I will show how to receive data via serial terminal in MATLAB, so stay tuned and also subscribe us via email to get these exciting tutorials straight in your mailbox. Take care. :)

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:

  • In today's post,we will show the values of temperature sensor over the LCD, the complete code is given below but I am not adding the circuit diagram of LCD I have already explain it in detail which you can check at Circuit Designing of LCD with Arduino in Proteus ISIS.

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:

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

Receive SMS with AT Commands using Sim900 and Arduino

Update: I have updated the code and removed the bug. Thanks for informing. Now this code will work perfectly.

Buy This Project

Hello friends, hope you all are fine and having good health. Today, as the name suggests, I am gonna post on how to Receive SMS with AT Commands using Sim900 and Arduino. I have already posted a tutorial on How to Send SMS with Arduino UNO and Sim900, so now we are gonna check the opposite. Sending SMS is quite easy, you just need to write some AT commands and write the message you wanna send and hit the Cntrl + Z and it will be sent. But receiving a text message on your SIM900 shield is a bit difficult because now you need to place a check when user will send a message. So, ideally whenever anyone send a message to your SIM900 module, you should get notified. Today, we are gonna cover this how to receive SMS with AT Commands in detail.

Now, after you get notified, there's a need to read the message as well and also who has sent this message. So, we are also gonna cover it today. So, first of all we will place a check that whenever someone sends a message to our SIM900 module, we get notified and after that we will extract the message and the mobile number of sender. We have designed this code after a lot of effort that's why this code isn't free but we haven't placed a very small amount of $20 so that engineering students can also buy it easily. We can also interface our GSM board with other microcontrollers like PIC Microcontroller as well as 8051 Microcontroller. I have also posted tutorial on How to Receive SMS with SIM900 & PIC Microcontroller and How to Send SMS with PIC Microcontroller so if you are working on PIC Microcontroller then you must give it a look. So, let's get started with How to receive SMS with AT Commands using SIM900 and Arduino.

You must also check GSM Library for Proteus, using this library you can easily simulate your GSM module in Proteus ISIS. Moreover, also have a look at Send SMS with Sim900D in Proteus ISIS in which I have designed a simulation of sms sending in Proteus ISIS.

Receive SMS with AT Commands using Sim900 and Arduino

  • There are many GSM modules available in the market so it doesn't matter which one you are using unless its having SIM900 module in it.
  • I have explained in my previous post that all GSM modules work on AT commands, so here first of all we are gonna have a look on AT commands we are gonna use for receiving the SMS.
  1. ATE0 - IT is used to turn off the Echo of GSM shield.
  2. AT - Just to check that your GSM module is working fine.
  3. AT + CMGF = 1 - This command will convert the message style to text. In other words we are telling our shield that we are expecting a text message.
  4. AT+CNMI=1,2,0,0,0 - This command will alert our GSM shield and now whenever it will receive message, it will automatically send an alert on the serial port.
  • We are gonna use these four commands in our code and we will be able to receive text message on the GSM shield.
  • Remember we have to put Enter after each of the above AT commands in order to execute it.
  • Below is the first phase of the code and as you can see in this code we are simply sending these four commands serially from arduino to GSM shield.
  • These are two functions I have shown below, the first function is Config() which is simply sending the commands via serially and then the Response() function which is called after every AT command and is receiving the response of that AT command.
  • So, here's the partial code for How to Receive SMS with AT Commands using Sim900 and Arduino.
void Config()
{
delay(1000);
Serial.print("ATE0r");
Response();
Serial.print("ATr");
Response();
Serial.print("AT+CMGF=1r");
Response();
Serial.print("AT+CNMI=1,2,0,0,0r");
Response();
}

void Response()
{
int count = 0;
Serial.println();
while(1)
{
if(Serial.available())
{
char data =Serial.read();
if(data == 'K'){Serial.println("OK");break;}
if(data == 'R'){Serial.println("GSM Not Working");break;}
}
count++;
delay(10);
if(count == 1000){Serial.println("GSM not Found");break;}

}
}
  • The response of these commands is shown below on the Serial Monitor of Arduino.
  • For each AT command, we get a response "OK" from the GSM shield.
  • Now, I know that I have sent all these four AT commands and my GSM shield is ready to receive the text messages and will inform me.
  • So, when you send a message to your GSM shield, it will give a notification as shown in the below figure:
  • Each message received by SIM900 module is start with "+CMT" and after that it has the mobile number of the sender and at the end lies the body of the message, which in our message is "www.TheEngineeringProjects.com"
  • So now let's extract this mobile number and the text body from this CMT string.

Getting the SMS Text & Sender Mobile Number

  • Till now we have learnt How to Receive SMS with AT Commands using Sim900 and Arduino and send you notification over the serial monitor.
  • Now we have to place some checks in our code so that we could be able to get the required data out of this string.
  • In order to do so, I am gonna first save this CMT string into an array, which I named as RcvdMsg[index].
  • But before saving the data into this string, first I need to make sure that I am actually getting the requried string, that's aso possible that I am receving some garbage values.
  • So, I placed a check first, which is checking for these four characters "+CMT", and when I got these character on my serial terminal I got sure that I have the string ready so I made the index = 0 and starting receving the string.
  • Next thing I need to do is make sure that I have got the complete string, that was really a tricky part as there's no end character in the string.
  • So, I used "n" null character for that. If you check the string then you can see that we are getting two null characters in complete string.
  • I placed this check that when I get 2 null characters means I have got the complete string so I stopped receving the string.
  • After that I simply count the charaters, in my string the sender mobile number is at posting 4 to 16 so I made a loop and save it in another array. and similarly did for the message text.
  • Now when I send message after uploading this final code into my Arduino board, I get the below result on my Serial Monitor.
  • Isn't it cool :) So, now we have separated the complete text as well as the sender's mobile number from our GSM string and we can use it anywhere we want.
  • We can use this mobile number in the previous post code and can reply some text back and can also give a missed call to the user, anything we want. I am gonna post on How to send a call using SIM900 in the next post.
  • You can buy the codefor How to Receive SMS with AT Commands using Sim900 and Arduino from our shop by clicking the below button:
Buy This Project
  • I have highlighted all the functions in the code.
  • As I always say, understand it first and then write on your own and do mistakes so that you learn.
That's all for today. I hope you have enjoyed this project named Receive SMS with AT Commands using Sim900 and Arduino. I will meet you guys in the next post. Till then 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