Techinc1510
Published © LGPL

HC-SRO4 (Distance Measurer) with LCD 1602

This project takes a simple HC-S0R4 and adds an LCD.

IntermediateShowcase (no instructions)8,462
HC-SRO4 (Distance Measurer) with LCD 1602

Things used in this project

Schematics

Schematic

Code

Code

Arduino
#include <LiquidCrystal.h>

LiquidCrystal lcd(6 , 7, 5, 4, 3, 2);
const int trigPin = 11;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;

void setup() {
  
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

}

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

duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;

lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance" on the LCD
lcd.print(distanceCm); // Prints the distance value from the sensor
lcd.print("  cm");
delay(10);
lcd.setCursor(0,1);
lcd.print("Distance: ");
lcd.print(distanceInch);
lcd.print("inch");
delay(10);

}

Credits

Techinc1510

Techinc1510

2 projects • 10 followers

Comments