Simple Ultrasonic Range Finder Using Arduino. Circuit Diagram, Program and Theory
Simple Ultrasonic Range Finder Using Arduino. Circuit Diagram, Program and Theory
(http://www.circuitstoday.com)
SPONSORED SEARCHES
HC SR04 is an ultrasonic range nding module with an accuracy of 0.3cm. The sensing range of this module is from 2cm to 5 meter. Working current of this sensor is
15mA and the measuring angle is 15°. The photograph of front and back side of the HC-SR04 sensor is shown in the gure below.
(http://www.circuitstoday.com/wp-content/uploads/2014/05/HC-SR04-ultrasonic-range- nder.png)
HC-SR04 has four pins. Their names and functions are explained below.
http://www.circuitstoday.com/ultrasonic-rangefinder-using-arduino 1/11
16/12/2018 Simple ultrasonic range finder using arduino. Circuit diagram, program and theory
(http://www.circuitstoday.com/wp-content/uploads/2014/05/HC-SR04-timing-
diagram.png)Circuit diagram.
Full circuit diagram of the ultrasonic range nder using arduino is shown in the gure below.
(http://www.circuitstoday.com/wp-content/uploads/2014/05/ulrasonic-range- nder-using-arduino.png)
Trigger pin of the ultrasonic range nder module is connected to digital pin 0 of the arduino. Echo pin of the ultrasonic module is connected to the digital pin 13 of the
arduino. SPDT switch S1 is used to select the unit of the measurement shown in the display. Pole of the SPDT switch S1 is connected to digital pin 4 of the arduino. If
digital pin 4 is held high, the output will be in centimeters and if the digital pin 4 is held low, the output will be in inches. Digit driver transistor Q1, Q2 and Q3 of the
arduino are interfaced to digital pins 1, 2 and 3 of the arduino. Multiplexed segments a to dp are interfaced to digital pins 5 to 12 of the arduino. The arduino board can
be powered through the +9V jack given on the board. 5V supply needed in some other parts of the circuit can be obtained from the 5V source available in the arduino
board. Resistors R9, R10 and R11 limits the base current of the corresponding transistors. 330 ohm resistors R1 to R8 limits the current through the corresponding
segments. Pin out of an E1-3056ASR1 three digit MUX seven segment display in shown in the gure below.
http://www.circuitstoday.com/ultrasonic-rangefinder-using-arduino 2/11
16/12/2018 Simple ultrasonic range finder using arduino. Circuit diagram, program and theory
(http://www.circuitstoday.com/wp-content/uploads/2014/05/3-digit-multiplexed-display-pinout.png)
Program.
#include <NewPing.h>
#define trig 0
#define echo 13
#define maximum 200
int a;
int unit;
int usec;
int input=4;
int disp1=1;
int disp2=2;
int disp3=3;
int segA=5;
int segB=6;
int segC=7;
int segD=8;
int segE=9;
int segF=10;
int segG=11;
int segDP=12;
For communicating with the ultrasonic range nder module, library function <NewPing.h> is used. The job of sending the 10uS trigger pulse, waiting for the echo and
measuring the width of the echo etc are done by the library function. Just one line of code usec=sonar.ping()will make the arduino to do all the jobs said above and
the width of the echo pulse in micro seconds will be stored in the variable usec. Dividing the pulse width in uS by 58 will give the distance in cm and dividing the pulse
width in uS by 148 will give the distance in inch. An “if – else” loop is used for selecting the unit according to the position of the SPDT selector switch(S1). Displaying
the distance on the three digit 7 segment display is done by the method used in the earlier project Voltmeter using arduino (http://www.circuitstoday.com/voltmeter-
using-arduino).
This is just the LCD version of the above project. The working principle of this circuit is same as that of the 7-segment LED version. Only change is on the display
device. In this circuit a 16×2 LCD display is used for displaying the distance. The distance in cm and inch are displayed simultaneously on the LCD screen. Before
attempting the LCD version, go through this article: Interfacing LCD to Arduino (http://www.circuitstoday.com/interfacing-lcd-to-arduino). Circuit diagram of the LCD
range nder is shown below.
http://www.circuitstoday.com/ultrasonic-rangefinder-using-arduino 3/11
16/12/2018 Simple ultrasonic range finder using arduino. Circuit diagram, program and theory
(http://www.circuitstoday.com/wp-content/uploads/2014/05/ultrasonic-range- nder-LCD.png)
lcd.begin(16,2);
}
void loop()
{ lcd.clear();
lcd.setCursor(2,0);
lcd.print("Range Finder");
usec=sonar.ping();
cm=usec/58;
inch=usec/58/2.54;
lcd.setCursor(0,1);
lcd.print(cm);
lcd.print("cm");
lcd.setCursor(7,1);
lcd.print(inch);
lcd.print("inch");
delay(250);
SPONSORED SEARCHES
Tags: ultrasonic range nder (http://www.circuitstoday.com/tag/ultrasonic-range- nder), ultrasonic range nder (http://www.circuitstoday.com/tag/ultrasonic-
range nder), ultrasonic range nder LCd (http://www.circuitstoday.com/tag/ultrasonic-range nder-lcd)
Categories: Arduino (http://www.circuitstoday.com/category/arduino)
tt
http://www.circuitstoday.com/ultrasonic-rangefinder-using-arduino 4/11