Distance Meter

4,381

83

8

Introduction: Distance Meter

About: I'm engineer, I like to design programming things with Arduino hardware and pure electronics too.

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.

Arduino Contest 2016

Participated in the
Arduino Contest 2016

Epilog Contest 8

Participated in the
Epilog Contest 8

Be the First to Share

    Recommendations

    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • "Can't Touch This" Family Contest

      "Can't Touch This" Family Contest
    • CNC Contest 2020

      CNC Contest 2020

    8 Discussions

    0
    turbiny
    turbiny

    3 years ago

    How accurate is it?

    0
    The Soldering Station
    The Soldering Station

    Reply 3 years ago

    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.

    0
    braulio777
    braulio777

    Reply 3 years ago

    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);

    }

    0
    chipup
    chipup

    3 years ago

    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?

    0
    braulio777
    braulio777

    Reply 3 years ago

    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);

    }

    0
    funkiwi75
    funkiwi75

    3 years ago

    will this code work for the mini pro?

    0
    braulio777
    braulio777

    Reply 3 years ago

    I think so.