For fast transaction call 0916.457.0748
Ultrasonic Sensor HC-SR04 with 1602 LCD with IIC  Display   -- Tutorial

Ultrasonic Sensor HC-SR04 with 1602 LCD with IIC Display -- Tutorial

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.

 

Hardware Required:

- Arduino Uno r3
- Ultrasonic Sensor HC-SR04
- 1602 LCD with IIC Module
-Connecting Wires

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

1602 LCD Display with IIC– Arduino:
- The  VCC connect to the Arduino Board +5V
- The GND connect to the Arduino Board GND
- The  SCL connect to the Arduino Arduino Board Analog I/O 4 (SCL)
- 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.

Libraries:

 #include <Wire.h>

#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);

 

const int trigPin = 2;
const int echoPin = 3;
long duration;
int distanceCm, distanceInch;

void setup() {
  
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

}

void loop() {
  
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;

lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance" on the LCD
lcd.print(distanceCm); // Prints the distance value from the sensor
lcd.print("  cm");
delay(10);
lcd.setCursor(0,1);
lcd.print("Distance: ");
lcd.print(distanceInch);
lcd.print("inch");
delay(10);
}

 

 

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.

Documents:

 

Happy Coding!


        Payment Methods

        Facebook Rewards Program