Project Summary
The Proximity Sensor with LCD project is a practical tool for building digital measuring tapes, obstacle detection systems, or parking aids. It combines high-accuracy ultrasonic ranging with a real-time visual output on a character liquid crystal display (LCD).
Technical Principles
- Ultrasonic Ranging (HC-SR04): The sensor works like sonar in nature, emitting a 40kHz sonic burst and then measuring the time it takes for that burst to bounce off an object and return to the receiver (Echo pin).
- Distance Calculation: Using the speed of sound (approx. 343 m/s), the Arduino calculates the total travel time. Since the sound must travel to the object AND back, the formula is:
Distance (cm) = (Time * 0.0343) / 2
- Display Output: A 16x2 LCD is used to show the distance in centimeters or inches. The Arduino uses the
LiquidCrystallibrary to format this data for the user.
Hardware Wiring
- HC-SR04 Module:
- VCC to 5V
- GND to Ground
- Trig to Digital Pin 9 (Trigger burst)
- Echo to Digital Pin 10 (Receive pulse)
- 16x2 LCD Module (Standard Parallel):
- RS to Pin 12
- Enable to Pin 11
- Data Pins (D4-D7) to Pins 5, 4, 3, 2
- Contrast Potentiometer for clear text visibility.
Software Execution
The code is structured into two main parts:
- Pulse Generation: The code pulls the Trig pin
HIGHfor exactly 10 microseconds to start the sonic burst. - Pulse Measurement: The
pulseIn()function measures the length of the Echo pulse, providing the time in microseconds. - Data Refresh: The LCD is cleared and updated every few hundred milliseconds to provide a smooth, continuous measurement.
Use Cases
- Digital Ruler: Accurate measurements for hardware and crafting.
- Smart Trash Bin: Detects when your hand or an object is close to automatically open the lid.
- Water Level Monitor: Placing the sensor at the top of a tank can detect how much water is remaining based on the distance to the surface.