Tr3v3n_Jaganath
Published © GPL3+

Proximity Sensor with LCD

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.

BeginnerFull instructions provided8,538
Proximity Sensor with LCD

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Arduino UNO
Arduino UNO
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×20
Resistor 221 ohm
Resistor 221 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Wiring

Code

Source Code

Arduino
#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);
    }
  
}

Credits

Electronics Hobbyists

Posted by Tr3v3n_Jaganath

Comments