Using Ultrasonic Distance Sensor HC-SR04 with LCD Display and Arduino

Maker 101
Maker 101
293.5 هزار بار بازدید - 8 سال پیش - Display the results from the
Display the results from the HC-SR04 Ultrasonic Sensor on an LCD

Required Hardware:
Arduino Board :
https://goo.gl/UyGYeF (Banggood)
https://amzn.to/2LZr6t4 (Amazon)
Ultrasonic Sensor:
https://goo.gl/dRkWUg (Banggood)
https://amzn.to/3s4SbdT (Amazon)
LCD Display:
https://goo.gl/1ljUCs (Banggood)
https://amzn.to/3bbBgzu (Amazon)
10K Ohm Potentiometer :
https://goo.gl/c90Uix (Banggood)
https://amzn.to/3dlgYq1 (Amazon)
Breadboard:
https://goo.gl/yCa8hX (Banggood)
https://amzn.to/3qxLxwm (Amazon)
Jumper Wires: https://amzn.to/3doetmT (Amazon)

Recommended Items:                
Use Your Muscles in Project - https://amzn.to/3wdL45C
37 Sensor & Module Packages - https://amzn.to/3m66WeQ
Try this Robot Arm - https://amzn.to/3fq8DCl
Best Resin 3D Printer - https://amzn.to/39tY8KB
Arduino Compatible Kits - http://bit.ly/2J2AFF7
Banggood Spring Sale - https://bit.ly/3slMbOn

Connections:
The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the Arduino Board.

The HC-SR04 sensor attach to the Breadboard
The Sensor VCC connect to the Arduino Board +5V
The Sensor GND connect to the Arduino Board GND
The Sensor Trig connect to the Arduino Board Digital I/O 9
The Sensor Echo connect to the Arduino Board Digital I/O 10


Watch the basic tutorial about the HC-SR04:
Using Ultrasonic Sensor HC-SR04 with ...

LCD Display Connection:
Before wiring the LCD screen to your Arduino or Genuino board we suggest to solder a pin header strip to the 14 (or 16) pin count connector of the LCD screen.
To wire your LCD screen to your board, connect the following pins:

LCD VSS pin to Arduino GND
LCD VDD pin to Arduino 5V
LCD VO pin to 10k Potentiometer center pin
LCD RS pin to digital pin 1
LCD RW pin to Arduino GND
LCD Enable pin to digital pin 2
LCD D4 pin to digital pin 4
LCD D5 pin to digital pin 5
LCD D6 pin to digital pin 6
LCD D7 pin to digital pin 7
The 10k Potentiometer's other legs connect to +5V and GND
For the backlight of the display, pin 15 (A+) and 16 (K-) of the LCD connect to +5V and GND

If you want, can be use a 220 ohm resistor to power the backlight of the display.

Watch the basic tutorial about the LCD Display: Arduino LCD Display Control

About Source Code
The LiquidCrystal library allows you to control LCD displays that are compatible.

First you have to define the Trig and Echo pins. In this case they are the pins number 9 and 10 on the Arduino Board and they are named trigPin and echoPin. Then you need a Long variable, named “duration” for the travel time that you will get from the sensor and an integer variable for the distance.

In the setup you have to define the trigPin as an output and the echoPin as an Input and also start the serial communication for showing the results on the serial monitor. If the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward.  So in order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2.

Source Code:  https://create.arduino.cc/editor/mert...

Social Media:
Instagram: mertarduino
Facebook: mertarduino
8 سال پیش در تاریخ 1395/09/07 منتشر شده است.
293,584 بـار بازدید شده
... بیشتر