0% found this document useful (0 votes)
6 views

Step 2:: The Code To Get The Hex Address Can Be Found From The Link Given Here

This document provides code to connect an ultrasonic sensor to an LCD display to measure and display distance readings. It includes the code to get the I2C address of the LCD display from an online tutorial. The code then defines the pin connections for the ultrasonic sensor and LCD, sets up the LCD display and backlight, and includes the main loop code to trigger ultrasonic pings, measure distance, and display readings on the LCD screen.

Uploaded by

amitkray
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Step 2:: The Code To Get The Hex Address Can Be Found From The Link Given Here

This document provides code to connect an ultrasonic sensor to an LCD display to measure and display distance readings. It includes the code to get the I2C address of the LCD display from an online tutorial. The code then defines the pin connections for the ultrasonic sensor and LCD, sets up the LCD display and backlight, and includes the main loop code to trigger ultrasonic pings, measure distance, and display readings on the LCD screen.

Uploaded by

amitkray
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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

You might also like