ULTRASONIC RANGE FINDER USING ARDUINO

Ultrasonic distance measurement 
using HC-SR04 sensor


The project using to measure distance from 
the HC-SR04 Ultrasonic sensor 


PARTS NEEDED 

Arduino uno
LCD 16x2

HC-SR04 Ultrasonic sensor 
Bread board 
jumper wires

and a computer only for programming 

CONNECTING OF LCD TO THE ARDUINO 

* LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * ends to +5V and ground(A,K) for the lcd backlight 
 * wiper to LCD VO pin (pin 3) or connect the lcd 3rd pin to ground through 1K 

resistor 


CONNECTING OF HC-SR04 TO ARDUINO 


*VCC to +5v
*GND to ground 
*trigpin to digital pin 9
*echopin to digial pin 10


THE PROGRAM CODE


/*Ultrasonic Sensor HC-SR04 and Arduino project
*/
#include <LiquidCrystal.h> // includes the LiquidCrystal Library

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Creates an LCD object. Parameters: (RS, enable, D4,D5,D6,D7)

const int trigPin = 9;
const int echoPin = 10;
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);
}
//and just upload the code and see the magic of arduino  !

Comments