0% found this document useful (0 votes)
424 views6 pages

HC SR04 Ultrasonic Sensor: Elijah J. Morgan Nov. 16 2014

The document explains how ultrasonic sensors like the HC-SR04 work by sending out sound waves and measuring the time it takes for the echo to return. It provides specifications for the HC-SR04, describes how to take distance measurements by triggering the sensor and timing the echo response, and how to wire it to a microcontroller. It also discusses sources of error like echoes that can cause incorrect readings.

Uploaded by

Kulpat TWana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
424 views6 pages

HC SR04 Ultrasonic Sensor: Elijah J. Morgan Nov. 16 2014

The document explains how ultrasonic sensors like the HC-SR04 work by sending out sound waves and measuring the time it takes for the echo to return. It provides specifications for the HC-SR04, describes how to take distance measurements by triggering the sensor and timing the echo response, and how to wire it to a microcontroller. It also discusses sources of error like echoes that can cause incorrect readings.

Uploaded by

Kulpat TWana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

HCSR04UltrasonicSensor

ElijahJ.Morgan
Nov.162014

ThepurposeofthisfileistoexplainhowtheHCSR04works.Itwillgiveabrief
explanationofhowultrasonicsensorsworkingeneral.Itwillalsoexplainhowtowire
thesensoruptoamicrocontrollerandhowtotake/interpretreadings.Itwillalsodiscuss
somesourcesoferrorsandbadreadings.

1. HowUltrasonicSensorsWork
2. HCSR04Specifications
3. Timingchart,PinexplanationsandTaking
DistanceMeasurements
4. WiringHCSR04withamicrocontroller
5. ErrorsandBadReadings

1.HowUltrasonicSensorsWork
Ultrasonicsensorsusesoundtodeterminethedistancebetweenthesensorandthe
closestobjectinitspath.Howdoultrasonicsensorsdothis?Ultrasonicsensorsare
essentiallysoundsensors,buttheyoperateatafrequencyabovehumanhearing.

Thesensorsendsoutasoundwaveataspecificfrequency.Itthenlistensforthatspecific
soundwavetobounceoffofanobjectandcomeback(Figure1).Thesensorkeepstrack
ofthetimebetweensendingthesoundwaveandthesoundwavereturning.Ifyouknow
howfastsomethingisgoingandhowlongitistravelingyoucanfindthedistance
traveledwithequation1.

Equation1. d = v t

Thespeedofsoundcanbecalculatedbasedontheavarietyofatmospheric
conditions,includingtemperature,humidityandpressure.Actuallycalculatingthe
distancewillbeshownlateroninthisdocument.
Itshouldbenotedthatultrasonicsensorshaveaconeofdetection,theangleof
thisconevarieswithdistance,Figure2showthisrelation.Theabilityofasensorto
detectanobjectalsodependsontheobjectsorientationtothesensor.Ifanobjectdoesnt
presentaflatsurfacetothesensorthenitispossiblethesoundwavewillbounceoffthe
objectinawaythatitdoesnotreturntothesensor.

2.HCSR04Specifications
ThesensorchosenfortheFirefightingDroneProjectwastheHCSR04.This
sectioncontainsthespecificationsandwhytheyareimportanttothesensormodule.The
sensormodulesrequirementsareasfollows.
Cost
Weight
Communityofhobbyistsandsupport
Accuracyofobjectdetection
Probabilityofworkinginasmokyenvironment
Easeofuse
TheHCSR04Specificationsarelistedbelow.Thesespecificationsarefromthe
CytronTechnologiesHCSR04UsersManual(source1).

PowerSupply:+5VDC
QuiescentCurrent:<2mA
Workingcurrent:15mA
EffectualAngle:<15
RangingDistance:2400cm
Resolution:0.3cm
MeasuringAngle:30
TriggerInputPulsewidth:10uS
Dimension:45mmx20mmx15mm
Weight:approx.10g

TheHCSR04sbestsellingpointisitspriceitcanbepurchasedataround$2per
unit.

3.TimingChartandPinExplanations
TheHCSR04hasfourpins,VCC,GND,TRIGandECHOthesepinsallhave
differentfunctions.TheVCCandGNDpinsarethesimplesttheypowertheHCSR04.
Thesepinsneedtobeattachedtoa+5voltsourceandgroundrespectively.Thereisa
singlecontrolpin:theTRIGpin.TheTRIGpinisresponsibleforsendingtheultrasonic
burst.ThispinshouldbesettoHIGHfor10s,atwhichpointtheHCSR04willsend
outaneightcyclesonicburstat40kHZ.AfterasonicbursthasbeensenttheECHOpin
willgoHIGH.TheECHOpinisthedatapinitisusedintakingdistance
measurements.AfteranultrasonicburstissentthepinwillgoHIGH,itwillstayhigh
untilanultrasonicburstisdetectedback,atwhichpointitwillgoLOW.
TakingDistanceMeasurements
TheHCSR04canbetriggeredtosendoutanultrasonicburstbysettingtheTRIG
pintoHIGH.OncetheburstissenttheECHOpinwillautomaticallygoHIGH.Thispin
willremainHIGHuntilthethebursthitsthesensoragain.Youcancalculatethedistance
totheobjectbykeepingtrackofhowlongtheECHOpinstaysHIGH.ThetimeECHO
staysHIGHisthetimetheburstspenttraveling.Usingthismeasurementinequation1
alongwiththespeedofsoundwillyieldthedistancetravelled.Asummaryofthisis
listedbelow,alongwithavisualrepresentationinFigure2.

1. SetTRIGtoHIGH
2. SetatimerwhenECHOgoestoHIGH
3. KeepthetimerrunninguntilECHOgoestoLOW
4. Savethattime
5. Useequation1todeterminethedistancetravelled

Source2
Tointerpretthetimereadingintoadistanceyouneedtochangeequation1.The
clockonthedeviceyouareusingwillprobablycountinmicrosecondsorsmaller.Touse
equation1thespeedofsoundneedstodetermined,whichis343meterspersecondat
standardtemperatureandpressure.Toconvertthisintomoreusefulformuseequation2
tochangefrommeterspersecondtomicrosecondspercentimeter.Thenequation3can
beusedtoeasilycomputethedistanceincentimeters.

Speed
Equation2. Distance = 170.15m Meters 1e6S
100cm 170.15m
58.772S
cm

Equation3. Distance = time s
58 = s/cm = cm

4.WiringtheHCSR04toaMicrocontroller
Thissectiononlycoversthehardwareside.Forinformationonhowtointegrate
thesoftwareside,lookatoneofthelinksbeloworlookintothespecificmicrocontroller
youareusing.

TheHCSR04has4pins:VCC,GND,TRIGandECHO.
1. VCCisa5vpowersupply.Thisshouldcomefromthemicrocontroller
2. GNDisagroundpin.Attachtogroundonthemicrocontroller.
3. TRIGshouldbeattachedtoaGPIOpinthatcanbesettoHIGH
4. ECHOisalittlemoredifficult.TheHCSR04outputs5v,whichcoulddestroy
manymicrocontrollerGPIOpins(themaximumallowedvoltagevaries).Inorder
tostepdownthevoltageuseasingleresistororavoltagedividercircuit.Once
againthisdependsonthespecificmicrocontrolleryouareusing,youwillneedto
findoutitsGPIOmaximumvoltageandmakesureyouarebelowthat.

5.ErrorsandBadReadings
Ultrasonicsensorsaregreatsensorstheyworkwellformanyapplications
whereothertypesofsensorsfallshort.Unfortunately,theydohaveweaknesses.These
weaknessescanbemitigatedandworkedaround,butfirsttheymustbeunderstood.The
firstweaknessisthattheyusesound.Thereisalimittohowfastultrasonicsensorscan
getdistancemeasurements.Thelongerthedistance,theslowertheyareatreportingthe
distance.Thesecondweaknesscomesfromthewaysoundbouncesoffofobjects.In
enclosedspacesitispossible,ifnotprobablethattherewillbeunintendedechos.The
echoscanveryeasilycausefalseshortreadings.InFigure2apulsewassentout.It
bouncedoffofobject1andreturnedtothesensor.Thedistancewasrecordedandthena
newpulsewassent.Therewasanotherobjectfartheraway,sothatwhenthenewpulse
reachesobject1,thefirstsignalwillreachthesensor.Thiswillcausethesensortothink
thatthereisanobjectcloserthanisactuallytrue.Theoldpulseissmallerthanthenew
pulsebecauseithasgrownweaker.Thelongerthepulseexiststheweakeritgrowsuntil
itisnegligible.Ifmultiplesensorsarebeingused,thenumberofechoswillincrease
alongwiththenumberoferrors.Therearetwomainwaystoreducethenumberoferrors.
Thefirstistoprovideshieldingaroundthesensor.Thispreventsechoscominginfrom
angleoutsidewhatthesensorshouldactuallypickup.Thesecondistoreducethe
frequencyatwhichpulsesaresentout.Thisgivesmoretimefortheechostodissipate.


WorksCited

Source1.
HCSR04User's_Manual.docs.google.CytronTechnologies,May2013Web.5Dec.
2009.
<https://docs.google.com/document/d/1YyZnNhMYy7rwhAgyL_pfa39RsBx2qR4vP8s
aG73rE/edit>

Source2.
Attiny2313Ultrasonicdistance(HRSR04)example.CircuitDB.n.a.7Sept.2014
Web.5Dec.2014.<http://www.circuitdb.com/?p=1162>

Links

Thesearenotformattedyouwillneedtocopyandpastethemintoyourwebbrowser.

WanttolearnaboutUltrasonicSensorsingeneral?
http://www.sensorsmag.com/sensors/acousticultrasound/choosingultrasonicsensorprox
imityordistancemeasurement825

AllabouttheHCSR04

http://www.circuitdb.com/?p=1162
http://www.micropik.com/PDF/HCSR04.pdf
http://randomnerdtutorials.com/completeguideforultrasonicsensorhcsr04/
http://www.ezdenki.com/ultrasonic.php
(^fantastictutorial,explainsalotofstuff)
http://www.elecrow.com/hcsr04ultrasonicrangingsensorp316.html
(^thisonehassomecoolcharts)

You might also like