Arduino UNO Distance Measurement Project with Ultrasonic Sensor and LCD Display

Опубликовано: 01 Апрель 2024
на канале: Preethi J
979
like

This project explains how to code in Arduino software for measuring the distance using ultrasonic sensor and LCD display.

Arduino Code

Distance measurement

HC-SR04 Ultrasonic Sensor with LCD display
HC-SR04 Ultrasonic Sensor
VCC to Arduino 5V
GND to Arduino GND
Echo to Arduino pin 12
Trig to Arduino pin 13

LCD Display (I used JHD162A)
VSS to Arduino GND
VCC to Arduino 5V
VEE to Arduino GND
RS to Arduino pin 11
R/W to Arduino pin 10
E to Arduino pin 9
DB4 to Arduino pin 2
DB5 to Arduino pin 3
DB6 to Arduino pin 4
DB7 to Arduino pin 5
LED+ to Arduino 5V
LED- to Arduino GND


#include "LiquidCrystal.h" //Load Liquid Crystal Library
LiquidCrystal LCD(11,10,9,2,3,4,5); //Create Liquid Crystal Object called LCD
#define trigPin 13 //Sensor Echo pin connected to Arduino pin 13
#define echoPin 12 //Sensor Trip pin connected to Arduino pin 12

//Simple program just for testing the HC-SR04 Ultrasonic Sensor with LCD display
//URL:
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

LCD.begin(16,2); //Tell Arduino to start your 16 column 2 row LCD
LCD.setCursor(0,0); //Set LCD cursor to upper left corner, column 0, row 0
LCD.print("Target Distance:"); //Print Message on First Row
}

void loop()
{
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;

LCD.setCursor(0,1); //Set cursor to first column of second row
LCD.print(" "); //Print blanks to clear the row
LCD.setCursor(0,1); //Set Cursor again to first column of second row
LCD.print(distance); //Print measured distance
LCD.print(" cm"); //Print your units.
delay(250); //pause to let things settle
}


Смотрите видео Arduino UNO Distance Measurement Project with Ultrasonic Sensor and LCD Display онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Preethi J 01 Апрель 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 97 раз и оно понравилось lik людям.