How to make Distance Meter using Ultrasonic Sensor || Made with Arduino || Ultrasonic Sensor || Hindi

How to make Distance Meter using Ultrasonic Sensor || Made with Arduino || Ultrasonic Sensor


Learn how you can make your own Distance meter using Arduino and Ultrasonic sensor

Material Needed:-

  • Arduino UNO
  • Ultrasonic Sensor
  • LCD with i2c interfearnce
  • Jumper Wire

Wiring:-

Wiring of Ultrasonic Sensor -----> Arduino
  • Vcc      ----------->   5v
  • GND    -----------> GND
  • TRIG   ----------->   D7
  • ECHO ----------->   D8
Wiring of LCD with i2c -----> Arduino
  • Vcc      ----------->   5v
  • GND    -----------> GND
  • SDA     ----------->   A4
  • SCL     ----------->   A5

Coding:-

/*
 * Distance Meter Using Ultrasonic Sensor
 * for more visit
 * http://bit.ly/diyareebyoutube
 */

//libraries for LCD
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display


int pingPin = 7; //Pin diclaration for Trig of Ultrasonic sensor
int inPin = 8; //Pin diclaration for ECHO of Ultrasonic sensor



long duration, inches, cm;
int indec, cmdec;
int inchconv = 147;
int cmconv = 59;


String s1, s2;

void setup()
{

lcd.init(); // Initializes the interface to the LCD screen
lcd.backlight();//Turn Backlight on
Serial.begin(9600);//Serial Communication

pinMode(pingPin, OUTPUT);//Trig pin as Output
pinMode(inPin, INPUT);//Echo pin as Input
}

void loop()

{
  
//Send Ultrasonic Sound
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);


//record the duration of ultrasonic sound
duration = pulseIn(inPin, HIGH);


//Change microsecond to Inches
inches = microsecondsToInches(duration);

//Accurate inches in decimal
indec = (duration - inches * inchconv) * 10 / inchconv;


//Change microsecond to centimeter
cm = microsecondsToCentimeters(duration);
//Accurate Centimeter in decimal
cmdec = (duration - cm * cmconv) * 10 / cmconv;


//s1 is the String for INCH
s1 = "Inch:-" + String(inches) + "." + String(indec) + "in" + " ";


//s2 is the String for CENTIMETER
s2 = "Centimeter:-" + String(cm) + "." + String(cmdec) + "cm" + " ";


//Print Distance on Serial Monitor
Serial.print(s1);//Print INCH
Serial.print("\t");//Space
Serial.println(s2);//Print CM

//Print Distance on LCD
lcd.setCursor(0,0);
lcd.print(s1);
lcd.setCursor(0,1);
lcd.print(s2);

delay(600);
}

long microsecondsToInches(long microseconds)

{

return microseconds / inchconv;

}

long microsecondsToCentimeters(long microseconds)

{

return microseconds / cmconv;

}

Watch Video to Know More:-


Comments

Popular posts from this blog

How to use TV as Arduino display || Arduino TVout Library || Hindi

Making food is easy now || Supercook.com

Arduino Keypad