Ultrasonic Range Finder With Arduino | Arduino Workshop

Ultrasonic Range Finder_

You went to do Ultrasonic Range Finder Using Arduino. Today In this project we’ll make a basic ultrasonic range finder with a screen that shows the distance of an object up to 5 meters from the sensor.


≡ Required Component


Here is a list of the hardware we suggest for this tutorial on Ultrasonic Range Finder Using Arduino.

1.Arduino

2. connecting wire

3. Breadboard

4. HD44780 16×2 LCD screen

5.HC-SR04 ultrasonic sensor

6.  5K ohm Trim Pot


≡ Required  Software


  • Arduino Ide
  • LiquidCrystal

≡ The Working principle:


The ultrasonic range finder Sensor sends out a burst of ultrasound and listens for the echo that bounces off an object. The Arduino sends out a short pulse on the trigger pin to send the ultrasonic burst, at that point listens for a pulse on the echo pin utilizing the pulseIn work.

This duration between sending and receiving the pulse is equal to the time taken by the ultrasound to travel to the object and back to the sensor. The Arduino converts this time to distance and displays it on the LCD screen.


≡ Circuit diagram Ultrasonic Range Finder Arduino:


The breadboard layout for this is shown in Ultrasonic Range Finder Arduino

Ultrasonic Range Finder_ Ultrasonic Range Finder_

LCD and Potentiometer BUILD With Arduino:

Lest Put your LCD screen within your breadboard, inserting the header pins into the breadboard holes. and Also Put the potentiometer within the breadboard, and utilize jumper wires to connect your LCD screen.

The pins of the LCD screen should be labeled or numbered, either on the back or the front. In case not, they usually begin at 1 from the left when the pins are along the top. There are a number of connections from the LCD screen to Arduino GND, so utilize the breadboard ground rail to form different connections to the Arduino GND pin.

LCD SCREEN

ARDUINO

1 VSS

GND

2 VDD

+5V

3 VO contrast

Potentiometer center pin

4 RS

Pin 11

5 R/W

Pin 10

6 Enable

Pin 9

7 D0

No connection

8 D1

No connection

9 D2

No connection

10 D3

No connection

11 D4

Pin 7

12 D5

Pin 6

13 D6

Pin 5

14 D7

Pin 4

15 A BcL+

+5V

16 K BcL–

GND

Ultrasonic sensor module BUILD With Arduino :

Add the ultrasonic sensor module to your breadboard and connect VCC to +5V, Trig to Arduino pin 13, Echo to Arduino pin 12, and GND to GND, as shown in the following table.

ULTRASONIC SENSOR

ARDUINO

VCC

+5V

Trig

Pin 13

Echo

Pin 12

GND

GND

Connect your breadboard rails to Arduino +5V and GND for power


≡ Code Ultrasonic Range Finder Arduino:


For this project, code to begin with calls on the LiquidCrystal library and defines the LCD pins connected to the Arduino. And The  Pin 13 on the Arduino, connected to the trigger pin of the  Ultrasonic sensor, sends an ultrasonic signal out, and Arduino pin 12, connected to the echo pin of the  Ultrasonic sensor, receives the returning signal.

The Arduino converts the time between sending and receiving the signal into distance and shows the result on the LCD screen, in both inches and centimeters. 

#include <LiquidCrystal.h>

LiquidCrystal lcd(11, 10, 9, 7, 6, 5, 4);
int pingPin = 13;
int inPin = 12;

void setup() {
  lcd.begin(16, 2);
  lcd.print("testing...");
}

void loop() {
  // Establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  // long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 ms or more
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))):
  // a HIGH pulse whose duration is the time (in microseconds)
  // from the sending of the ping to the reception of its echo off
  // of an object.
  pinMode(inPin, INPUT);
  duration = pulseIn(inPin, HIGH);

  // Convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(inches);
  lcd.print("in, ");
  lcd.print(cm);
  lcd.print("cm");

  delay(100);
}

long microsecondsToInches(long microseconds) {
  // According to Parallax's datasheet for the PING))),
  // there are 73.746 ms/in (i.e. sound travels at 1130 fps).
  // This gives the distance traveled by the ping, outbound,
  // and return, so divide by 2 to get the distance of the obstacle.
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
  // The speed of sound is 340 m/s or 29 ms/cm.
  // The ping travels out and back, so to find the distance
  // of the object, take half of the distance traveled.
  return microseconds / 29 / 2;
}

All Arduino tutorial available Click here

 ARDUINO TUTORIAL 

 218 total views,  1 views today