Distansometer
Distance measuring device
It is a device used to measure the distance between two objects or walls without practically touching them. Just place the device anywhere between the objects and the LCD screen displays distance measured.
Model :
Youtube: video
Prototype 01
Circuit:
Components:
Code:
#include <Adafruit_LiquidCrystal.h>
Adafruit_LiquidCrystal lcd_1(0);
int echo1 = 9;
int trig1 = 8;
int echo2 = 6;
int trig2 = 7;
float duration1, distance1;
float duration2, distance2;
int d = 10; //d is Distance between two HC-SR04
int totalDistance = 0;
void setup()
{
lcd_1.begin(16, 2);
lcd_1.print("Distance:");
pinMode(trig1, OUTPUT);
pinMode(echo1, INPUT);
pinMode(trig2, OUTPUT);
pinMode(echo2, INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trig1, LOW);
delayMicroseconds(2);
digitalWrite(trig1, HIGH);
delayMicroseconds(10);
digitalWrite(trig1, LOW);
duration1 = pulseIn(echo1, HIGH);
distance1 = (duration1*0.0343)/2;
Serial.println(distance1);
digitalWrite(trig2, LOW);
delayMicroseconds(2);
digitalWrite(trig2, HIGH);
delayMicroseconds(10);
digitalWrite(trig2, LOW);
duration2 = pulseIn(echo2, HIGH);
distance2 = (duration2*0.0343)/2;
Serial.println(distance2);
delay(10);
totalDistance = distance1+distance2+d;
Serial.print("Distance: ");
Serial.println(totalDistance);
lcd_1.setCursor(0, 1);
lcd_1.print(totalDistance);
lcd_1.print("cm");
delay(10);
}
Comments
Post a Comment