Project tutorial

Simple Ultrasonic distance measurer with LCD display © GPL3+

It measures the distance between you and the place where you point it to. Hope you'll enjoy it!

  • 2,758 views
  • 0 comments
  • 12 respects

Components and supplies

About this project

Honestly I always loved this sort of tracking device sorts of things, you know the tiny devices that work miracles in spy movies sort. Thought they were so cool all the time and always hoped that I could get my hands on one, or at least something similar.

Since they don't really sell that sort of stuff outside I got curious if I could actually manage to build one myself. The ultrasonic sensor that was included in my Arduino Starter Pack was pretty much the reason I got into this.

I was honestly thinking if I could make a radar sort of thing with a greater range, both figuratively as a range of uses, and literally, as you know, the measurement range. Although the grim reality hit me as soon as I realized that even lighting up a tiny led took me more than 20 minutes. That's when I knew that I'd have to postpone that dream of mine a bit more.

It was a few months after that when I thought: "Why the hell not?".

I started looking up for projects online, tried to get my coding skills decent enough to make this "dream-device" of mine. And in the end it was pretty much worth it. It's missing a lot of features maybe thanks to my inferior knowledge of software, but it was also pretty much a kickstarter for me to keep new projects following afterwards.

Hopefully this project will also be a kickstarter for anyone that's just got into this stuff, and hope you'll enjoy!

P.S: The text on the LCD isn't in English on the picture since I thought I'd make one using my mother tongue and couldn't get another quality pic since my phone's got some problems atm, but I altered the code so that all the text will be in English.

Schematics

Ultrasonic distance measurer with LCD display support
Tried to keep the Fritzing scheme as simple as possible
ultrasonic_distance_measurer_with_lcd_display_Vh4aUFir0a.fzz

Code

Ultrasonic distance measurer with LCD display Arduino
#include <LiquidCrystal.h> //Load Liquid Crystal Library
LiquidCrystal LCD(12, 11, 5, 4, 3, 2);  //Create Liquid Crystal Object called LCD
 
int trigPin=9; //Sensor Trip pin connected to Arduino pin 9
int echoPin=7;  //Sensor Echo pin connected to Arduino pin 7
int myCounter=0;  //declare your variable myCounter and set to 0
int servoControlPin=6; //Servo control line is connected to pin 6
float pingTime;  //time for ping to travel from the sensor to the target and return
float targetDistance; //Distance to Target in Centimeters
float speedOfSound=776.5; //Speed of sound in miles per hour
 
void setup() {
  
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
LCD.begin(16,2); //Tell Arduino to start your 16x2 LCD
LCD.setCursor(0,0);  //Set LCD cursor to upper left corner, column 0, row 0
LCD.print("Distance:");  //Print Message on First Row
}
 
void loop() {
  
  digitalWrite(trigPin, LOW); //Set trigger pin low
  delayMicroseconds(2000); //Let signal settle
  digitalWrite(trigPin, HIGH); //Set trigPin high
  delayMicroseconds(15); //Delay in high state
  digitalWrite(trigPin, LOW); //ping has now been sent
  delayMicroseconds(10); //Delay in high state
  
  pingTime = pulseIn(echoPin, HIGH);  //pingTime in microceconds
  pingTime=pingTime/1000000; //convert pingTime to seconds by dividing by 1000000 (microseconds in a second)
  pingTime=pingTime/3600; //convert pingtime to hours by dividing by 3600 (seconds in an hour)
  targetDistance= speedOfSound * pingTime;  //This will be in miles, since we declared the speed of sound as kilometers per hour; although we're going to convert it back to centimeters 
  targetDistance=targetDistance/2; //Remember ping travels to the target and back from the target, so you must divide by 2 for actual target distance.
  targetDistance= targetDistance*160934,4;    //Convert miles to centimeters by multipling by 160934,4 

 
  
  LCD.setCursor(0,1);  //Set the cursor to the first column of the second row
  LCD.print("                "); //Print blanks to clear the row
  LCD.setCursor(0,1);   //Set Cursor again to the first column of the second row
  LCD.print(targetDistance); //Print measured distance
  LCD.print(" centimeters");  //Print your units
  delay(250); //Pause to let things settle
  
}

Comments

Similar projects you might like

Magic Lamp

by Nekhil ravi

  • 878 views
  • 3 comments
  • 8 respects

Arduino MKR GSM 1400 and DTMF

by Arduino_Genuino

  • 3,605 views
  • 0 comments
  • 10 respects

Love You Pillow

Project tutorial by Arduino

  • 2,064 views
  • 0 comments
  • 4 respects

Infrared Replicator

Project tutorial by Gustavo Gonnet

  • 3,639 views
  • 6 comments
  • 26 respects

A Model Lighthouse Using an Adafruit NeoPixel Ring

Project tutorial by Jeremy Lindsay

  • 366 views
  • 0 comments
  • 4 respects

Rural Hack Kit

by Officine Innesto

  • 3,949 views
  • 0 comments
  • 7 respects
Add projectSign up / Login