Project showcase
How to Make an Ultrasonic Ruler with Arduino UNO and HC-SR04

How to Make an Ultrasonic Ruler with Arduino UNO and HC-SR04

This is my first project, so please like the project and comment down below.

  • 3,985 views
  • 4 comments
  • 8 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
12002 04
Breadboard (generic)
**Optional**
×1
51gzz5eu9pl. sx425
Ultrasonic Sensor - HC-SR04 (Generic)
Any ultrasonic sensor would work.
×1
11026 02
Jumper wires (generic)
Four would be enough
×4
Adafruit industries ada62 image 75px
USB-A to B Cable
This will help you to connect the laptop with Arduino
×1
Laptop or computer
×1

Apps and online services

Ide web
Arduino IDE
To program and upload to your arduino

About this project

Well I was sitting at home wondering how to measure how far away things are without getting up of my couch. So I took a look at some projects. They were pretty lit but they didn't have inches and millimetres.

Code

Ultrasonic ruler with inches, centimetres, and millimetresArduino
This the code. Just copy it and paste it on your Arduino IDE. Comment down below how I can make this code better.
const int trigPin = 2;
const int echoPin = 4;
void setup() { 
Serial.begin(9600);} 
void loop()
{
long duration, inches, cm, mm;
pinMode(trigPin, OUTPUT); 
digitalWrite(trigPin, LOW); 
delayMicroseconds(2000); 
digitalWrite(trigPin, HIGH); 
delayMicroseconds(1000); 
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT); 
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration); 
cm = microsecondsToCentimeters(duration);
mm = microsecondsToMillimeters(duration);
Serial.print(inches); 
Serial.print("in, "); 
Serial.print(cm);
Serial.print("cm, ");
Serial.print(mm);
Serial.print(" mm");
Serial.println(); 
delay(1000);
}
long microsecondsToInches(long microseconds)
{return microseconds / 74 / 2;}
long microsecondsToCentimeters(long microseconds)
{return microseconds / 29 / 2;}
long microsecondsToMillimeters(long microseconds)
{return microseconds / 2.9 / 2;}

Schematics

Ultrasonic Ruler
The Ultrasonic ruler helps you to measure things with Ultrasonic sounds.
ultrasonic_ruler_757P6Dm0hK.fzz
Ultrasonic Ruler
Just wire the:

VCC of Ultrasonic sensor ---> 5V in Arduino
Trig of Ultrasonic sensor ---> Pin 2 in Arduino
Echo of Ultrasonic sensor ---> Pin 4 in Arduino
GND of Ultrasonic sensor ---> To GND in Arduino


And then just copy and paste the code above in your Arduino IDE. To see the distance just go to Tools -> Serial Monitor or just put Ctrl+Shift+M or for mac just Command+Shift+M.
Screen shot 2018 02 16 at 4 masvqzlcmm

Comments

Similar projects you might like

Simple Ultrasonic Distance Measurer With LCD Display

Project showcase by onatto22

  • 5,704 views
  • 4 comments
  • 19 respects

Arduino Obstacle Avoidance Robot with Ultrasonic HC-SR04

Project showcase by Jorge Rancé

  • 11,827 views
  • 7 comments
  • 28 respects

Ultrasonic Security System

Project tutorial by Ivan

  • 17,282 views
  • 18 comments
  • 50 respects

IOT - Smart Jar Using ESP8266, Arduino and Ultrasonic Sensor

Project tutorial by Team Smazee

  • 6,212 views
  • 4 comments
  • 12 respects
Add projectSign up / Login