Skip to main content

Measuring Distance Using UltraSonic Sensor with Arduino

Measuring Distance

    Using Arduino, UltraSonic Sensor & OLED Display


            In this Arduino Tutorial , I will show you How to Measure a Distance of an Object Using Arduino , UltraSonic Sensor & OLED Display . You can watch this Video or Read the following Blogs for More Details.

Working Principle :

            The Major Component Used in this Project was UltraSonic Sensor. UltraSonic Sensor emits a High-Frequency Sound Pulse and Calculates the Distance depending upon the time taken by the echo signal to travel back after reflecting from the Target. 

Components Required :

Construction:

  • By using Breadboard, mount UltraSonic Sensor and OLED Display on it . 
  • Now power both sensor and display using Arduino Uno Board with the help of Jumpers. 
  • Now Connect Trigger & Echo pin of UltraSonic Sensor to the 6th & 7th pin of the Arduino Uno Board . 
  • Then Connect SCL & SDA of OLED Display to the A6 & A5 pins of the Arduino Uno  Board. 
  • Then setup for the Hardware Portion is done. 
  • Let's move on to the Software Portion,Open Your Arduino IDE and Select Measuring_distance_using_UltraSonic_Sensor file.
  • Download Required Libraries .
  •  And Select Board & Port , Click Upload. 
  • That's Solve Guys .!

Circuit Diagram :

            

Arduino Code :

//DISTANCE MEASUREMENT USING ULTRASONIC SENSOR
//10 JULY 2020
//BY PRADEEP RAJ (M.P.R)
//          ------THIS CODE IS OPEN SOURCE FOR OUR SUBSCRIBERS------
//                         ------ THE FAUCETER ------
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,&Wire,OLED_RESET);
int trig = 6 ;
int echo = 7 ;
int distanceCm ;
int distanceInch ;
void setup() {
  pinMode(trig, OUTPUT) ; 
  pinMode(echo, INPUT) ;
  Serial.begin(9600) ; 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
}
void loop() {
   digitalWrite(trig,LOW) ;
   delay(2);
   digitalWrite(trig,HIGH) ;
   delay(10);
   digitalWrite(trig,LOW);
   int duration = pulseIn(echo,HIGH);
   distanceCm = duration*0.034/2 ;
   distanceInch = duration*0.0133/2;
   Serial.print("Object at a Distance(in Cm) of : ");
   Serial.println(distanceCm);
   Serial.print("Object at a Distance(in Inch) of : ");
   Serial.println(distanceInch);
   oledcm();
   oledinch();
  
}
void oledcm(void) {
 display.clearDisplay();
  
  display.setTextSize(2);          
  display.setTextColor(SSD1306_WHITE);        
  display.setCursor(0,2);             
  display.println(" Distance   in Cm   ");
  display.setTextSize(3);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(35,40);
  display.println(distanceCm);
  
  
  display.display();
  delay(1000); 
}
void oledinch(void) {
 display.clearDisplay();
  
  display.setTextSize(2);          
  display.setTextColor(SSD1306_WHITE);        
  display.setCursor(0,2);             
  display.println(" Distance   in Inch   ");
  display.setTextSize(3);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(35,40);
  display.println(distanceInch);
  
  
  display.display();
  delay(1000); 
}
// ------------------------ THE FAUCETER --------------------
            

Click Here to Download 

Comments

Popular posts from this blog

Arduino Line Following Car

Line Follower      In this Arduino Tutorial I will Show you How to Make a Line Following Car Using Arduino Uno Board and Some Electronic Components . You can Watch this Video or Read the following blog for more details.. Working Principle :          Line Follower has a basic and necessary Component   IR Sensor which act as Vision. It works on the principle of Black Surface Absorbs all  Wavelengths of Light Rays. Then the IR Sensors mounted infront of the car detects black line and makes a movement based on your code.

Arduino Smart Car

Smart Car          In this Arduino Tutorial I will show You How to make a Smart Car using Arduino Uno Board and other some Electronic Components. You can Watch this Video or Read the Following Blog for more details.

NodeMCU WiFi Car

 WiFi Car    In this Tutorial I will Show you How to Make a WiFi Car Using NodeMCU ESP8266 Board and Some Electronic Components . You can Watch this Video or Read the following blog for more details..

N95 Respirator Mask

N95

Arduino Object Following Robot

Object Following Robot     Watch the entire DIY Video of making (J.A.O.F) Arduino Object Following Robot...

NodeMCU WiFi Switch

 Wi-Fi Switch          In this Tutorial , I will Show you How to Control your Home Appliances by Using Smartphone Over WiFi Connection with NodeMCU ESP8266 Board and Relay(Electric Switch). You can watch this Video or read the following Blog for more Details...