jehankandt
Published © Apache-2.0

Arduino 16x2 LCD Display with Distance Sensor

Print distance on Arduino LCD Display using I2c

AdvancedFull instructions provided10,890
Arduino 16x2 LCD Display with Distance Sensor

Things used in this project

Story

Read more

Schematics

Arduino 16x2 Display I2C Distance Sensor

Arduino 16x2 Display I2C Distance Sensor

Code

Arduino 16x2 Display I2C Distance Sensor

C/C++
Arduino 16x2 Display I2C Distance Sensor
//...............JehanKandy........................
//...........www.jehankandy.com....................
//........www.github.com/JehanKandy................

//..............LCD Display........................
//..............I2C Module.........................



//include liquidCrystal_I2C.h and install 
//Tools -> Manage Libraries and type liquidCrystal_I2C then install

#include <LiquidCrystal_I2C.h>

//define I2C address......
LiquidCrystal_I2C lcd(0x27,16,2);


//create veriables
int trig = 2;
int echo = 3;
long duretion, distance;

void setup() {
  pinMode(trig,OUTPUT);
  pinMode(echo,INPUT);
    
  lcd.init();
  lcd.clear();
  lcd.backlight();

  lcd.setCursor(2,0);
  lcd.print("Distance");

  lcd.setCursor(1,1);
  lcd.print("UltraSonic");
  delay(2000);
  
  lcd.clear();
}

void loop() {
  digitalWrite(trig,HIGH);
  delayMicroseconds(2);
  digitalWrite(trig,LOW);
  delayMicroseconds(10);
  digitalWrite(trig,HIGH);

  duretion = pulseIn(echo,HIGH);
  distance = (duretion/2)*0.0346;

  lcd.setCursor(3,0);
  lcd.print(distance);

  lcd.setCursor(6,0);
  lcd.print("cm");
}

//.........coded by : JehanKandy....
//...........Thank You..............

Credits

jehankandt

jehankandt

21 projects • 8 followers

Comments