DETAILED EXPLAINATION ON HOW TO MAKE A DISTANCE MEASURING METER USING | ARDUINO | ULTRASONIC SENSOR HC-SR04 | OLED DISPLAY SCREEN

in #hive-1635213 years ago

Accurate measurement of distance is a very essential aspect in lots of professions. I'm @techlhab and today I would be sharing with us how to make is DIY Smart Distance Measuring Meter using Arduino Nano microcontroller, Ultrasonic Sensor, and OLED Display Screen as the major hardware components. While the software components are; the Arduino IDE, Embedded C/C++ programming language, and fritzing for circuit design and simulation.

distancemeter.png

source


HARDWARE COMPONENTS


  • Arduino Nano
  • Ultrasonic Sensor (HC-SR04)
  • OLED Display Screen

SOFTWARE COMPONENTS


  • Arduino IDE (Integrated Development Environment)
  • Embedded C/C++
  • Fritzing

The Arduino Nano



arduino nano.png

Arduino Nano is a microcontroller which works almost exactly as the Arduino Uno or Arduino Mega but has lesser memory and appears to be very much smaller in size compared to Arduino Uno and Arduino Mega.

It is used in this project as the brain where all other components attached to it receives and send instruction from and to it respectively. And it is where the codes written to control the device is been uploaded to.


The Ultrasonic Sensor


The ultrasonic sensor is a sensor used in measuring distance or proximity. It transmits and receives sound waves and then converts the reflected sound wave over a distance from an object into electrical signals.

It has 4 pins which are:

  • Vcc
  • Gnd
  • Trig
  • Echo

In this tutorial, the HC-SR04 ultrasonic sensor is used and it is been used to sense the proximity or distance of an object obstructing the sound waves transmitted by the ultrasonic sensor. It then sends the value of the distance covered between the device and the obstructing object to the Arduino Nano for other decision makings.


UL.png


The OLED Display Screen


The OLED display screen helps in displaying relevant information to the users for interactions. And also serve a major purpose of displaying measurements, that is the distance been measured in centimeters and inches.

It also has 4 pins which are:

  • Vcc
  • Gnd
  • SDA
  • SCL


OLED.png


THE HARDWARE CONNECTIONS


  • Conneting the ultrasonic sensor to the Arduino Nano
Arduino UnoUltrasonic Sensor
15vVcc
2GndGnd
3D4Trig
4D3Echo
  • Conneting the OLED Display Screen to the Arduino Nano
Arduino UnoOLED Display Screen
15vVcc
2GndGnd
3A4SDA
4A5SCL

THE CIRCUIT DIAGRAM


distancemeter_circuitdiagram.png


THE WIRING DIAGRAM


distancemeter_wiringdiagram.png


CODE


//Distance Meter OLED Display


#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define trigPin 9
#define echoPin 8

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
display.clearDisplay();

}

void loop() {
float duration;
float distance_cm;
float distance_in;

digitalWrite(trigPin, LOW); //PULSE ___|---|___
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance_cm = (duration/2) / 29.1;
distance_in = (duration/2) / 73.914;

display.setCursor(25,0); //oled display
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Distance Meter");

display.setCursor(10,20); //oled display
display.setTextSize(2);
display.setTextColor(WHITE);
display.println(distance_cm);
display.setCursor(90,20);
display.setTextSize(2);
display.println("cm");

display.setCursor(10,45); //oled display
display.setTextSize(2);
display.setTextColor(WHITE);
display.println(distance_in);
display.setCursor(90,45);
display.setTextSize(2);
display.println("in");
display.display();

delay(500);
display.clearDisplay();

Serial.println(distance_cm);
Serial.println(distance_in);
}


Thanks for reading and visiting my blog 🤝. Kindly support this post by reblogging, upvoting, and commenting, it would be highly appreciated.

Images used in this post were all designed by me using frizting, a circuit design and simulation software.

Posted with STEMGeeks

Sort:  

PIZZA!

PIZZA Holders sent $PIZZA tips in this post's comments:
@lipe100dedos(1/5) tipped @techlhab (x1)

Join us in Discord!

Congratulations @techlhab! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You distributed more than 900 upvotes.
Your next target is to reach 1000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Hive Power Up Month - Feedback from April day 6
Support the HiveBuzz project. Vote for our proposal!

great post! I'd like to vote for Oneup, but we can't vote when there's a tag that doesn't fit... The ctp tag is for use in finance and marketing matters. Hope to be able to vote for the next ones! the Content is excellent congratulations!
!PIZZA

Thanks @lipe100dedos for the nice comments 😊. I highly appreciate 🤝.
Regarding the tag's points said are now well noted ✍️ by me and I would ensure I add it to my subsequent posts.

Ultrasonic sensor makes use of the principle of sound in air and more importantly the echo theory thought in elementary physics to determine the distance between the sensor and the next obstacle.

Sonic simply speed of sound in air which is within the range of 336m/s to 346m/s. This is a very interesting lesson in my fluid mechanics class.There is a dimensionless number called mach number I'm sure you much have heard ma 1 , 2 etc. Mach number is ratio of the speed of air object to the speed of sound in air. If this ratio is less than 1 we will say is a SUBSONIC , that is the object is running at a speed less than the speed of sound and this simply means that you will hear the sound of such object before the object gets to you. We have supersonic if mach is greater than 1 and this means the object must have passed before you will passive it sound. Quite interesting ? Fear anything supersonic please. Ultrasonic very high speed. I will write a post on complete working principle of ultrasonic sensor later this is getting too much for just a comment

Thanks @sisapower for the detailed comments as I was able to pick some beneficial points out of it. I have used ultrasonic sensor in lots of my projects and its just such a nice and highly useful sensor due to its capabilities.

I love the way you interact with my post and I highly appreciate it.