Circuit Schematic:
Code:
// Distance Calculator (ultrasonic version)
// By, Umar Rao
// Circuit available on http://www.arduinocoder.blogspot.com
/*
Components Required:
(1) Liquid Crystal Display
(2) Ultrasonic Sensor (HC-SR04)
(3) 1 220 ohm resistor
(4) 1 potentiometer
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int trigPin = 7;
const int echoPin = 8;
void setup() {
lcd.begin(16, 2);
}
void loop() {
long duration, cm;
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
cm = microsecondsToCentimeters(duration);
lcd.print("Distance (cm):");
lcd.setCursor(0, 1);
lcd.print(cm);
delay(100);
lcd.clear();
}
long microsecondsToCentimeters(long microseconds){
return microseconds / 29 / 2;
}
Very good work this is from you. I have really enjoyed reading this today. The information was really helpful for me. This is amazing stuff from you! city distances USA
ReplyDeleteThank you so much! I really appreciate that.
Deletei love reading this article so beautiful!!great job! entfernungsrechner
ReplyDelete