Step 2:
The code to get the Hex Address can be found from the link given here
https://brainy-bits.com/tutorials/connect-a-charac...
After that we need to use that code in the main code here
#include <Wire.h><br>#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <NewPing.h>
#define I2C_ADDR 0x27 // Add your address here.
#define Rs_pin 0
#define Rw_pin 1
#define En_pin 2
#define BACKLIGHT_PIN 3
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic
sensor.
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic
sensor.
#define MAX_DISTANCE 500 // Maximum distance we want to ping for (in
centimeters). Maximum sensor distance is rated at 400500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of
pins and maximum distance.<br>LiquidCrystal_I2C
lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup()
{
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
lcd.begin (16,2); // <<-- our LCD is a 20x4, change for your LCD if needed
// LCD Backlight ON
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home on LCD
lcd.print("Range Finder");
}
void loop()
{
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(1000);
digitalWrite(TRIGGER_PIN,LOW);
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds
(uS).
unsigned int dist = sonar.convert_cm(uS); // Convert into centimeters