Saturday, November 14, 2015

ULTRASONIC DISTANCE SENSOR WITH ARDUINO

Introduction

Arduino is an open source development board which is very good research and learning platform for technical and non technical person. It is very easy and comfortable to use in most of the situation from school project to the professional job. So it gives us knowledge about electronics and help develop idea of all age students. Learning arduino is awesome with enough hardware 
WANT TO LEARN ABOUT ARDUINO AND ARDUINO BASED PROJECT,CLICK HERE..
Ultrasonic sensor is a very useful electronics sensor by using it we can measure distance and also we can find whether there is block or not in front of the ultrasonic sensor. So it is used in both electronics and robotics field. In robot it is used as block finder or avoiding sensor. 


Ultrasonic sensor has one transmitter and another receiver by which it sends ultrasonic sensor and receives it when it is reflected back. It measures the time of reflection of ultrasonic sounds and we know that velocity of sound is 330m/s . So by using motion equation it measures the distance of object in front of it. 

Procedure of library file installation

  1.        download the following ultrasonic sensor library 
     2.          copy the folder to your arduino installed folder in c. 

                   to do this please goto C drive, open programfile(*86), open arduino and open library
     3.        paste the folder inside the folder named as library . 
     4.          open arduino IDE and click file>>example>>NewPing>>NewPingExample.

Procedure of hardware assembly

  1. connect the circuit as shown in the figure

  1.  Vcc pin to 5v of arduino 
  2. Gnd pin to Gnd pin of arduino
  3. Trig pin to pin 12 of arduino
  4. Echo pin to pin 11 of arduino




Hardware setup images

 

Program code


// ---------------------------------------------------------------------------
// Example NewPing library sketch that does a ping about 20 times per second.
// ---------------------------------------------------------------------------

#include <NewPing.h>

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters).                                                           Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins                                                                                                                 and maximum distance.

void setup() {
  Serial.begin(9800); // Open serial monitor at 9800 baud to see ping results.
}

void loop() {
  delay(500);                      // Wait 500ms between pings (about 20 pings/sec). 29ms should                                            be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  Serial.print("Ping: ");
  Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print                                                                               result (0 = outside set distance range)
  Serial.println("cm");
}
    

  • Upload the following code to your arduino. Then place the scale linearly in front of ultrasonic sensor and place an object about 10cm in front of ultrasonic sensor above scale. 
  • Open Serial Monitor in your Arduino and check the shown distance 


Your check is complete. Now you can make various project by modifying this code like obstacle avoiding robot, automatic sumo robot, mechanical projects, automatic car parking collision alert project etc. Best of luck and keep visiting my blog and if your project work or wont work please comment below.
  



No comments:

Post a Comment