Project tutorial
Proximity Sensor with LCD

Proximity Sensor with LCD © GPL3+

A sound wave is sent out. The time it takes to return is used to calculate the distance of the object in front of the sensor.

  • 379 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

The project consists of a HR-SR04 which is used to measure the distance of an object in front of it, by sending out a sound wave & measuring the time it takes to come back.

The distance is then calculated and displayed on a 16x2 LCD.

Code

Source CodeArduino
#include <LiquidCrystal.h>

LiquidCrystal lcd(9,8,4,5,6,7);//(rs,e,d4,d5,d6,d7)

const int trigPin = 3, echoPin = 2;
long duration;
int distanceCM, distanceINCH;

void setup() {
  lcd.begin(16,2);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

}

void loop() {lcd.clear();delay(10);
  digitalWrite(trigPin, LOW); delayMicroseconds(2);
  digitalWrite(trigPin, HIGH); delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);//determine duration to calculate distance 
  distanceCM = duration*0.034/2;
  distanceINCH = duration*0.0133/2;

  lcd.setCursor(0,0);
  lcd.print("Distance: ");
  lcd.print(distanceCM); lcd.print(" cm");delay(10);
  
  lcd.setCursor(0,1);
  lcd.print("Distance: ");
  lcd.print(distanceINCH); lcd.print("inch");delay(100);
  
  if(distanceINCH>99){//for displaying purposes
      lcd.clear(); delay(10);
    }
  
}

Schematics

Wiring
Proximitysensor h0zhqbuadm

Comments

Similar projects you might like

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 5,177 views
  • 7 comments
  • 19 respects

Ultrasonic Sensor with LCD Display Using 433MHz

Project tutorial by mcharrison500

  • 3,486 views
  • 0 comments
  • 17 respects

Displaying Sensor Values on LCD

by Wimpie van den Berg

  • 43,589 views
  • 4 comments
  • 36 respects

Soil Moisture Sensor With LCD Display

Project tutorial by Patel Darshil

  • 20,786 views
  • 5 comments
  • 39 respects

AI LCD friend!

Project tutorial by aip06

  • 3,297 views
  • 8 comments
  • 7 respects

Portable Arduino Temp/Humidity Sensor with LCD

Project tutorial by ThothLoki

  • 153,300 views
  • 115 comments
  • 185 respects
Add projectSign up / Login