// YWROBOT
// Compatible with the Arduino IDE
// Library version:1.1
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
// set the LCD address to 0x27 for a 16 chars and 2 line display
float cm;
float inches;
//long readUltrasonicDistance( 3, 2)
// Reads the echo pin, and returns
// the sound wave travel time in microseconds
// return pulseIn(echoPin, HIGH);
void setup()
{pinMode(3, OUTPUT);pinMode(2, INPUT);
Serial.begin(9600);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.print("--> Distance <--");
delay(3000);
lcd.clear();
}
void loop(){
digitalWrite(3, HIGH);
delayMicroseconds(10);
digitalWrite(3, LOW);
cm = 0.0344 *pulseIn(2,HIGH)/2;
inches = (cm / 2.54);
lcd.setCursor(0,0);
lcd.print("Inches");
lcd.setCursor(12,0);
lcd.print("cm");
lcd.setCursor(1,1);
lcd.print(inches, 1);
lcd.setCursor(11,1);
lcd.print(cm, 1);
delay(2000);
lcd.clear();
}