Display the results from the HC-SR04 Ultrasonic Sensor on an LCD Display
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.
- Arduino Uno r3
- Ultrasonic Sensor HC-SR04
- 1602 LCD with IIC Module
Ultrasonic Sensor HC-SR04 Connections:
- 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
- The GND connect to the Arduino Board GND
- The SDA connect to the Arduino Board Board Analog I/O 5 (SDA)
Building the Code
For you to make this project work, you’ll need first to download the Arduino Software and install it in your computer. To do so, visit the Arduino Website and download the application.
#include <LiquidCrystal_I2C.h> // Using version 1.2.1
// The LCD constructor - address shown is 0x27 - may or may not be correct for yours // Also based on YWRobot LCM1602 IIC V1 LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
Connect your Arduino Board to your computer using the Power Cable.
Open up your Arduino software and write the following code:
Select the Board and Port you are using, in the Menu Bar select “Tools”. Select the corresponding board you are using and the designated port. Check this out on how to select board, Arduino Ultrasonic Kit.
Upload your code.
- LCM1602 IIC V1 LCD Pin Outs
- I2C Scanner
- Datasheet I2C 1602 Serial LCD Module
- Simple LCD with I2C module on Arduino