Introduction: Distance Meter

This meter was developed using Arduino Uno, HC-SR04 sensor and a 16X2 LCD display for displaying each measurement.

Step 1: Bill of Materials

1 Arduino Uno

1 HC-SR04 ultrasonic sensor

1 16x2 LCD Display

1 Arduino Uno Proto Shield

1 Headers

1 10k Ohm Square Cermet Potentiometer

1 USB 2.0 Cable

1 Enclosure for Arduino Boards

Step 2: Schematic

This is your diagram so that you follow step by step the project in its essence.

Step 3: Assembling the Project

I installed the 16X2 LCD display into the Arduino PCB using the headers and also installed the HC-SR04 sensor. I used red and black heat shrink tube for connecting to +5V and GND respectively in this sensor while connecting trigPin to arduino pin 12 and echoPin to Arduino pin 13 for completing this operation.

Step 4: Joining the Parts

Mount what you completed in the previous step on your Arduino Uno.

Step 5: Upload the Code

//Code

#include <LiquidCrystal.h>

LiquidCrystal lcd(11, 9, 5, 4, 3, 2);

#define trigPin 12

#define echoPin 13

int duration, Distance;

void setup() {

Serial.begin(9600);

pinMode(trigPin,OUTPUT);

pinMode(echoPin,INPUT);

lcd.begin(16,2);

lcd.setCursor(0,0);

lcd.print( "Distance:" );

}

void loop() {

digitalWrite(trigPin, HIGH);

delayMicroseconds(1000);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

Distance = (duration/2) / 29.1;

Serial.print(Distance);

Serial.println(" cm");

lcd.setCursor(0,1);

lcd.print(" ");

lcd.setCursor(0,1);

lcd.print(Distance);

lcd.print(" cm");

delay(500);

}

Step 6: Code Uploaded

For uploading the code, you should copy and paste the code in the previous step.

Step 7: Enjoy Your Project

Enjoy your project by measuring distances with this amazing meter.

Comments

author
anooooos (author)2017-01-01

Hi

author
turbiny (author)2016-12-28

How accurate is it?

author

https://www.sparkfun.com/products/13959

Description: This is the HC-SR04 ultrasonic ranging sensor. This economical sensor provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm. Each HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit.

author
braulio777 (author)turbiny2016-12-29

For responding your question, here is the following code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(11, 9, 5, 4, 3, 2);

#define trigPin 12

#define echoPin 13

double duration, Distance;

void setup()

{

Serial.begin(9600);

pinMode(trigPin,OUTPUT);

pinMode(echoPin,INPUT);

lcd.begin(16,2);

}

void loop()

{

digitalWrite(trigPin, HIGH);

delayMicroseconds(2000);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

Distance = (duration/2) / 29.1;

Serial.print(Distance);

Serial.println(" cm");

lcd.setCursor(0,0);

lcd.print( "Distance = " );

lcd.setCursor(0,1);

lcd.print(" ");

lcd.setCursor(0,1);

lcd.print(Distance,3);

lcd.print(" cm ");

delay(250);

}

author
chipup (author)2016-12-28

Hi braulio777,

I'm very interested in working on this project, however since I am still new to arduino I would like to ask whether it is possible to make the reading of the sensor more accurate i.e. displaying 12.52 cm and what is the maximum effective range of the sensor?

author
braulio777 (author)chipup2016-12-29

You can upload the following code:

//Code

#include <LiquidCrystal.h>

LiquidCrystal lcd(11, 9, 5, 4, 3, 2);

#define trigPin 12

#define echoPin 13

double duration, Distance;

void setup()

{

Serial.begin(9600);

pinMode(trigPin,OUTPUT);

pinMode(echoPin,INPUT);

lcd.begin(16,2);

}

void loop()

{

digitalWrite(trigPin, HIGH);

delayMicroseconds(2000);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

Distance = (duration/2) / 29.1;

Serial.print(Distance);

Serial.println(" cm");

lcd.setCursor(0,0);

lcd.print( "Distance = " );

lcd.setCursor(0,1);

lcd.print(" ");

lcd.setCursor(0,1);

lcd.print(Distance,3);

lcd.print(" cm ");

delay(250);

}

author
funkiwi75 (author)2016-12-28

will this code work for the mini pro?

author
braulio777 (author)funkiwi752016-12-28

I think so.

About This Instructable

3,327views

80favorites

License:

More by braulio777:RGB Electronic DieElectronic DieArduino Nano Multiplication/Division Signs
Add instructable to: