Distance Measurement Box
Hi everybody, I just received an item via Amazon and the delivery box was still good to reuse , that's why I have tried to made something useful with it... in this instractable we are gonna see how can we make a practical distance measurement box using arduino uno a 16X2 LCD and an HC-SR04. generally it can be used to measure distance from obstacles, as a fluid level detector and much more...
What Are You Going to Need?
Well, first of all don't throw your small box from the last delivery because you are going to use it here, get your arduino uno or compatible in hand. The HC-RS04 or the ultrasonic sensor is needed too. Your 9V battery to supply the project and finally if you have any male to male jumper that will be great too. Oh I forget the most important part your LCD 2 x 16 it will show you how much you still have before hitting your head with the obstacle so keep an eye on it
Prepare Your Box
Drill holes in your box to fit both the LCD screen and the ultrasonic sensor as shown in the pictures. Try to have precise measurements for better results. Your HC-RS04 need to be stable inside the box also you need to have enough space for all your components.
Programing the Arduino
The code below configure the Arduino to control the sensor detector and the LCD, you just need to past it in your Arduino software and then transfer it to the ship.
// include the library code:
#include
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
int maximumRange = 300; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("La distance (cm): ");
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)
}
void loop() {
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
lcd.setCursor(0, 1);
lcd.print(distance);
delay(500); /* wait 500 for the next cycle*/
lcd.setCursor(0, 1);
lcd.print(" ");
}
// include the library code:
#include
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
int maximumRange = 300; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("La distance (cm): ");
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)
}
void loop() {
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
lcd.setCursor(0, 1);
lcd.print(distance);
delay(500); /* wait 500 for the next cycle*/
lcd.setCursor(0, 1);
lcd.print(" ");
}
Wire your components as shown in the pictures above.
Get Things Into Order!!!
Once your wiring and configuration has been done, place all your components carefully inside the box and rearrange them to be stable inside the box. I have used some tape to fix them...