Project tutorial
Measuring Distance using Ultrasonic sensor

Measuring Distance using Ultrasonic sensor © MPL-2.0

Using ultrasonic sensor to find the distance between the sensor and the object placed.

  • 30,209 views
  • 3 comments
  • 10 respects

Components and supplies

Apps and online services

About this project

This a very simple project to find the distance between .While going through the internet i got an idea to make something using ultrasonic sensor& arduino uno.

In this project i will use SR04 ultrasonic sensor.

And you will also need ping.h library.You can find it on the internet.

Wiring...

Connect the SR04 VCC pin to the Arduino 5v

Connect the SR04 GND pin to the Arduino GND

Connect the SR04 TRG pin to the Arduino Digital pin 12

Connect the SR04 ECHO pin to the Arduino Digital pin 11

Code for making this...

#include <NewPing.h>
 
#define TRIGGER_PIN  12  
#define ECHO_PIN     11  
#define MAX_DISTANCE 200 
 
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); 
 
void setup() {
  Serial.begin(115200); 
}
 
void loop() {
  delay(50);                     
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm());
  Serial.println("cm");
}
Distance measuring using a SR-04 Ultrasonic Sensor and Arduino UN0

Code

Ultrasonic.inoC/C++
#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(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");
}

Schematics

Distance using Ultrasonic Sensor
Ultrasonic%20Distance.fzz

Comments

Similar projects you might like

IOT - Smart Jar Using ESP8266, Arduino and Ultrasonic Sensor

Project tutorial by Team Smazee

  • 6,212 views
  • 4 comments
  • 12 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 4,725 views
  • 7 comments
  • 19 respects

Parking Sensor with Arduino

Project showcase by Team VINICIUS LOPES

  • 9,934 views
  • 4 comments
  • 17 respects

Measuring Distance with Sound

by Giannis Arvanitakis

  • 5,588 views
  • 1 comment
  • 31 respects

Simple Ultrasonic Distance Measurer With LCD Display

Project showcase by onatto22

  • 5,698 views
  • 4 comments
  • 19 respects
Add projectSign up / Login