Build a motion-detecting LED with an ultrasonic sensor (HC-SR04)

By Aleksandar | 29 September 2017 | 143 Comments
In this tutorial, I will show you how you can build a motion-detecting LED using an ultrasonic sensor (HC-SR04). The parts for this build are provided by KumanTech, you can find them in their Arduino UNO Kit.



Step 1: Parts Needed

1 x Arduino board (I'm using an Arduino Uno)
1 x LED (The color doesn't matter)
1 x 220 ohm resistor
1 x Breadboard
1 x Arduino USB Cable
1 x 9V battery with a clip (optional)
6 x Jumper wires

Step 2: Positioning the Parts


First, plug in the ultrasonic sensor and the LED on the breadboard. Connect the LED's shorter lead (the cathode) to the GND pin of the sensor. Then, place the resistor in the same row as the LED's longer lead (the anode) so they are connected.

Step 3: Connecting the Parts




Now, you need to plug some wires on the back of the sensor. There are four pins - VCC, TRIG, ECHO and GND. After inserting the wires, you need to make the following connections:
The resistor's end to a digital pin of your choice, just make sure to change it later in the code!
Sensor | Arduino
VCC -> 5V
TRIG -> 5*
ECHO -> 4*
GND -> GND
* - Can be connected to any two digital pins of the Arduino, just make sure you change them in the code later!

Step 4: Uploading the Code


Now, you can plug your Arduino to your computer using an USB cable. Open up the Arduino software and upload the code that you can find here. The constants are commented, so you know exactly what they are doing and possibly change

Step 5: The Final Result

 
Preimm
August 09,2022 05:44
buy azithromycin online <a href="https://stromectolel.com/">buy stromectol 12mg sale</a> glucophage 1000mg over the counter
Nybvco
August 07,2022 23:30
cialis on line <a href="https://tadalafedpill.com/">cialis 10mg usa</a> cheap viagra online
Ldxbvi
August 06,2022 17:02
order fluconazole for sale <a href="https://diflucansx.com/">fluconazole 100mg without prescription</a> cheap sildenafil 50mg
Hgrmdo
August 04,2022 21:35
buy generic ondansetron 4mg <a href="https://simvastatinl.com/">buy simvastatin 10mg without prescription</a> purchase propecia pill
Iibzqz
August 03,2022 14:57
order zantac 300mg <a href="https://meloxicamp.com/">meloxicam tablet</a> generic flomax 0.2mg
Afkhhv
August 02,2022 08:16
buy generic tadalafil <a href="https://tadalcialsl.com/">cialis 10mg pills</a> buy generic dutasteride
Yjeaen
August 01,2022 01:11
brand esomeprazole 20mg <a href="https://sidenafilppl.com/">viagra 200mg for sale</a> cialis order online
Buflfc
July 30,2022 17:42
buy sildalis generic <a href="https://sildalispl.com/">sildenafil 100mg</a> cozaar 50mg over the counter
Cqzqmm
July 29,2022 06:11
accutane 40mg generic <a href="https://suhagrapls.com/">sildenafil 100mg uk</a> order aurogra pills
Rzazwj
July 27,2022 22:46
buy viagra 50mg <a href="https://edspill.com/">otc ed pills</a> order prednisone 5mg sale
Nftfzc
July 26,2022 14:47
methotrexate 5mg pills <a href="https://warfariny.com/">cost coumadin 5mg</a> reglan 10mg uk
Hlkdrv
July 25,2022 05:16
order cyclobenzaprine 15mg pill <a href="https://cyclobenzaprip.com/">flexeril 15mg tablet</a> clopidogrel 75mg oral
Yfwiwy
July 23,2022 16:18
buy ezetimibe 10mg without prescription <a href="https://ezetimibels.com/">buy zetia</a> domperidone oral
Vxkpzx
July 21,2022 18:49
sildenafil 50 mg <a href="https://edsildenp.com/">sildenafil 200mg for sale</a> cialis 20mg
Gjorky
July 20,2022 15:50
buy dapoxetine 60mg generic <a href="https://priligx.com/">dapoxetine 60mg without prescription</a> order allopurinol 300mg online cheap
Qvjleq
July 19,2022 22:08
essays writing <a href="https://deslorat.com/">purchase desloratadine generic</a> clarinex tablet
Pwqdll
July 19,2022 06:20
cheap prilosec 20mg <a href="https://vafdlevit.com/">vardenafil 20mg price</a> medrol 4 mg without a doctor prescription
Mkyyad
July 18,2022 06:03
order baricitinib 4mg pill - <a href="https://lisinoprilf.com/">buy lisinopril 5mg online</a> brand lisinopril 10mg
Jvgjqd
July 16,2022 10:17
buy plaquenil pills - <a href="https://casletadal.com/">cialis 20mg pills</a> cenforce 50mg drug
JbvMK
September 11,2021 20:26
JGIgNLgiy9tYGHIYfyfrGKJbg8i6TGuigf86rOUhg97BikofvguTOPig*IGkjf8
AodXR
September 03,2021 11:55
cialis substitute <a href="https://cialisortadalafil.com/">canadian generic cialis</a> cialis 5mg daily
GxjAL
September 03,2021 03:09
sildenafil pronounce <a href="https://lobviagra.net/">buy sildenafil online usa</a> generic viagra for sale
XxxSI
August 31,2021 15:26
<a href="https://domalech.ru/">prednisolon tablete</a>
WdcPE
August 28,2021 04:14
<a href="https://domalech.ru/">trazodone acetate ophth susp 1 15ml</a>
HvwUX
August 27,2021 14:53
prednisolon 5mg <a href="https://prednisoloneshop.com/">prednisone pill</a> can you take ibuprofen with prednisone
TzhJI
August 27,2021 11:58
tamoxifen and raloxifene <a href="https://tamoxifenworld.com/">tamoxifen for breast cancer prevention</a> tamoxifen survival statistics
SkwEH
August 20,2021 11:32
cialis 20mg tadalafil <a href="https://cialismom.com/">cialis en pharmacie</a> cialis et taux de psa
WrgIS
August 14,2021 20:06
Create anonymous bitcoin wallet without verification. Fast sending to the blockchain without commission. Read more at https://www.google.pl/url?q=https://www.bitcoinofficial.org/
PwhBH
August 14,2021 16:48
Create anonymous bitcoin wallet without verification. Fast sending to the blockchain without commission. Read more at https://www.google.com.tr/url?q=https://www.bitcoinofficial.org/
EjsUC
August 14,2021 04:49
Create anonymous bitcoin wallet without verification. Fast sending to the blockchain without commission. Read more at https://www.google.co.uk/url?q=https://www.bitcoinofficial.org/
JsjCX
August 14,2021 00:36
Create anonymous bitcoin wallet without verification. Fast sending to the blockchain without commission. Read more at https://www.google.it/url?q=https://www.bitcoinofficial.org/
BnrBD
August 13,2021 02:25
Create anonymous bitcoin wallet without verification. Fast sending to the blockchain without commission. Read more at https://www.google.co.jp/url?q=https://www.bitcoinofficial.org/
QmmQO
August 12,2021 16:54
Create anonymous bitcoin wallet without verification. Fast sending to the blockchain without commission. Read more at https://www.google.com.hk/url?q=https://www.bitcoinofficial.org/
ZnxON
August 12,2021 01:38
Create anonymous bitcoin wallet without verification. Fast sending to the blockchain without commission. Read more at https://www.google.com/url?q=https://www.bitcoinofficial.org/
LdwQB
August 02,2021 16:21
Pills information for patients. What side effects can this medication cause? <a href="https://eriacta4people.top">can i purchase cheap eriacta online</a> in US Best information about drug. Read information here.
PyaTU
August 02,2021 11:31
Medicines information sheet. What side effects can this medication cause? <a href="https://eriacta4people.top">cost of eriacta prices</a> in Canada Actual news about medication. Read information now.
EtrAL
August 01,2021 22:56
Medication prescribing information. Generic Name. <a href="https://tadacip4people.top">can you buy generic tadacip without rx</a> in US Best news about medicament. Get now.
LywFC
August 01,2021 22:46
Meds information. Cautions. <a href="https://eriacta4people.top">order cheap eriacta</a> in US Some what you want to know about pills. Get information here.
UtjTG
August 01,2021 08:56
Pills information. Brand names. <a href="https://kamagra4people.top">how to buy generic kamagra</a> in USA Actual what you want to know about drug. Get information here.
QjzFW
August 01,2021 06:47
Medication information for patients. Drug Class. <a href="https://tadacip4people.top">cost of generic tadacip</a> in US Best about medicines. Get now.
OmlXV
August 01,2021 04:18
Drug prescribing information. Effects of Drug Abuse. <a href="https://kamagra4people.top">buy cheap kamagra</a> in US Some trends of drug. Get now.
NfqSQ
July 31,2021 16:55
Последние данные <a href="https://urlscan.io/result/74481172-d7fb-4a5e-b452-d824c164961c/">о SARS-CoV-2</a> очень любопытны!
FnbUZ
July 31,2021 00:06
<a href="https://kmsauto-win.ru/активатор-windows-8-1/">kmsauto windows 8.1</a>
CzaET
July 29,2021 00:22
Drugs information sheet. What side effects? <a href="https://depakote4all.top">depakote prices</a> in the USA Everything about medicines. Get here.
SfbJX
July 28,2021 18:37
Drug information for patients. Drug Class. <a href="https://cymbalta4all.top">buying cymbalta</a> in USA Everything trends of medicament. Read here.
glnnjca
July 27,2021 19:50
https://adopt10plus.com/question/qzasbm6/
FudOP
July 27,2021 19:30
http://ekonomimvmeste.ukrbb.net/viewtopic.php?f=14&t=1484
BelNE
July 27,2021 07:26
Последние данные <a href="https://www.business-gazeta.ru/news/463506">о корона вирусе</a> очень необычны!
bmtqhvv
July 27,2021 06:42
https://www.alltolearn.com/ffy332f/
IrnKQ
July 27,2021 00:18
<a href="https://krasota4u.ru">cheap trazodone prices</a>
IvlDT
July 26,2021 18:27
Medication information sheet. Short-Term Effects. <a href="https://valtrex4people.top">cost of cheap valtrex</a> in the USA Actual about medication. Get here.
QddIR
July 26,2021 16:32
Последние публикации <a href="https://komiinform.ru/nt/2501">о ковиде</a> очень необычны!
HxpWR
July 26,2021 07:29
Drug prescribing information. Cautions. <a href="https://valtrex4people.top">can you buy valtrex</a> in Canada Best what you want to know about meds. Read information here.
QwpWX
July 24,2021 18:55
Meds information. Long-Term Effects. <a href="https://plaquenil4people.top">how can i get generic plaquenil for sale</a> in USA All news about pills. Get information here.
NhsQQ
July 23,2021 19:48
Drug information sheet. Effects of Drug Abuse. <a href="https://valtrex4people.top">buy generic valtrex price</a> in US Actual what you want to know about medication. Read information now.
JgyZF
July 23,2021 17:24
Meds information leaflet. Effects of Drug Abuse. <a href="https://levitra4people.top">generic levitra pills</a> in US Actual about drug. Get here.
OvaXJ
July 23,2021 01:33
Meds information leaflet. What side effects can this medication cause? <a href="https://valtrex4people.top">where to buy generic valtrex</a> in the USA Everything trends of medicines. Get here.
LpnFW
July 22,2021 21:55
Medicines information. What side effects can this medication cause? <a href="https://plaquenil4people.top">where can i get cheap plaquenil</a> in Canada Some what you want to know about drugs. Get now.
HrhGD
July 22,2021 09:34
cialis generic 2017 <a href="https://cialistodos.com/">cialis on line</a> alcohol and cialis
SoqKH
July 22,2021 07:13
cialis canadian pharmacy <a href="https://cialisdotan.com/">generic name for cialis</a> cialis soft
ChaSD
July 22,2021 02:08
Meds information for patients. Brand names. <a href="https://flagyl4people.top">where buy flagyl</a> in Canada All what you want to know about drug. Get information now.
BeeLU
July 22,2021 01:59
Meds information leaflet. What side effects can this medication cause? <a href="https://flagyl4people.top">generic flagyl no prescription</a> in USA Best about medicines. Read information here.
DwxGO
July 21,2021 01:07
viagra without a doctor prescription usa <a href="https://viagramores.org/">viagra over the counter</a> sildenafil for women
MjxQG
July 20,2021 23:02
viagra alternative <a href="https://mastviagra.com/">get viagra</a> canadian pharmacy ezzz viagra
JjlPP
July 20,2021 06:03
<a href="http://fi-hi.ru/kak-pravilno-vybrat-kakao-poroshok/">какао порошок</a>
UjtPT
July 19,2021 04:12
<a href="https://arte.style/shop/grunty-bazy/">Декоративная штукатурка хамелеон</a>
HtfXS
July 17,2021 20:01
cialis 5mg generique <a href="https://cialisspotsfrance.net/">cialis 5mg prix en pharmacie</a> le prix du cialis en pharmacie
CoyOE
July 17,2021 17:07
cialis espagne <a href="https://cialissportsfran.org/">tadalafil 10mg avis</a> quand prendre du cialis
https://txt2080.com/
July 17,2021 09:06
We all tend to focus on catchy headlines and gripping titles. That split-second interest grabber is important. Copyblogger’s great posts on headlines thankfully tell you exactly how to craft your words to create snappy headlines. How you end your post de
MfvRB
July 16,2021 20:24
<a href="https://domalech.ru">can you buy trazodone</a>
https://txt2080.com/meritcasin
July 16,2021 15:33
We all tend to focus on catchy headlines and gripping titles. That split-second interest grabber is important. Copyblogger’s great posts on headlines thankfully tell you exactly how to craft your words to create snappy headlines. How you end your post de
https://main7.net/baca/
July 16,2021 15:24
When investors tell you why they don't like your pitch, they're almost always lying. They'll usually tell you that you're too early, or you need more traction, or you need too much money, or you need too little money." Think about it: What urge grabs the
https://liveone9.com/
July 16,2021 15:11
Real compliments. Something they took great effort in. Can be hair. Shoes 90% always a good choice. Accessories…makeup. The female coders I’ve worked with seem to prefer single-line comments and tend to avoid writing sprawling multiline comments that tak
OvqHW
July 16,2021 15:04
<a href="https://domalech.ru">generic trazodone prices</a>
PecDB
July 15,2021 23:59
https://doorchange.ru/stroitelstvo-i-remont/oformlenie-okon.html
IvjMD
July 14,2021 18:34
vardenafil free samples <a href="https://mylevitralife.com/">levitra price levitra pill</a> vardenafil buy uk
EmvGL
July 14,2021 15:18
generic levitra vardenafil uk <a href="https://levitrastops.net/">vardenafil 40 mg generic levitra</a> vardenafil online pharmacy
VbtWN
July 13,2021 21:28
<a href="https://xxxhdvideo.site/">xxxxhdvideos</a>
YhnFF
July 08,2021 10:58
price of cialis <a href="https://tadalafilmast.com/">viagra cialis</a> does cialis lowers blood pressure
LjtCW
July 08,2021 08:45
best price on vardenafil <a href="https://levitraworlds.com/">is levitra generic</a> vardenafil 10mg tablets
MyzTD
July 08,2021 05:28
https://johnnylist.org/Front-Sign-LLC_132519.html
QkjRO
July 08,2021 04:50
cialis pill <a href="https://tadalafilmast.com/">cialis pills</a> cialis versus viagra
GagLV
July 08,2021 02:16
vardenafil free samples <a href="https://levitraworlds.com/">levitra ed</a> vardenafil buy uk
LtrWB
July 07,2021 20:39
Drug prescribing information. Generic Name. <a href="https://imodium4u.top">order cheap imodium no prescription</a> in Canada All what you want to know about medication. Read here.
FnoCB
July 07,2021 17:39
Medicament information for patients. Long-Term Effects. <a href="https://celebrex4all.top">generic celebrex price</a> in US Actual information about medication. Read here.
ClkHM
July 07,2021 02:40
<a href="https://sep55.ru/">рецензия на заключение строительной экспертизы</a>
IowHL
July 06,2021 22:35
roman viagra <a href="https://missaviagra.com/">walgreen viagra</a> buy viagra
VpaCK
July 06,2021 19:57
cialis recommended dosage <a href="https://cialisloves.org/">is cialis covered by insurance</a> printable cialis coupon
GpbAI
July 06,2021 06:24
viagra soft <a href="https://missaviagra.com/">generic viagra for sale</a> viagra alternative
TnsFJ
July 06,2021 02:45
cialis women <a href="https://cialisloves.org/">cialis 20mg side effects</a> how to make cialis work better
SiaEP
July 06,2021 01:34
https://filmlord2.net/
TdhGM
July 05,2021 19:30
https://98e.fun/space-uid-515797.html
CquKU
July 05,2021 17:24
http://eduvuz.ru/
DpsVD
July 05,2021 05:46
http://eduvuz.ru/
JddJJ
July 05,2021 05:12
http://friendsofpakistan.net/author/ffayd-507031/
djhjklx
July 05,2021 00:25
http://lols.ru/user/tamzmqt/
FxhUJ
July 04,2021 21:08
https://msk-intimcity.ru
TtbIU
July 04,2021 06:42
sildenafil sandoz 100 mg <a href="https://shopfranviagra.com/">shopfranviagra</a> viagra generique prix
TwpRA
July 04,2021 03:57
sildenafil pfizer prix <a href="https://shopfranviagra.com/">posologie viagra</a> effets secondaires du viagra
KcxEU
July 04,2021 03:11
http://eduvuz.ru/
EpjMO
July 03,2021 22:19
http://eduvuz.ru/
GisCL
July 03,2021 21:20
best natural viagra <a href="https://topviagralove.org/">watermelon viagra</a> online viagra
TpaLB
July 03,2021 19:02
sildenafil without a doctor prescription <a href="https://slidnenafilviagramore.com/">sildenafil for dogs</a> viagra dosages
NqcOH
July 03,2021 18:34
viagra substitute <a href="https://slidnenafilviagramore.com/">viagra for men</a> cheapest viagra
XgdPF
July 03,2021 11:47
sildenafil pas cher <a href="https://shopfranviagra.com/">viagra gratuit</a> acheter viagra sans ordonnance
HuxIW
July 03,2021 09:51
female viagra over the counter <a href="https://topviagralove.org/">viagra para mujer</a> generic sildenafil 20 mg
CzrDW
July 03,2021 07:53
female viagra <a href="https://slidnenafilviagramore.com/">viagra cock</a> viagra for sale
QkuOB
July 02,2021 21:55
This is unusual <a href="https://www.creditmagic.org/index.php/comment/141042">this page</a>
FdqAP
July 02,2021 08:07
<a href="https://pony-town.ru">pony town скачать на пк</a>
ZqoSS
July 02,2021 02:39
<a href="http://diplom-na-dom.ru/"> продаю диплом о высшем образовании</a>
JcoRN
July 01,2021 18:19
<a href="http://diplom-na-dom.ru/"> купить диплом о высшем образовании медицинском</a>
YidBO
July 01,2021 08:18
viagra no prescription <a href="https://theviagramaster.com/">sildenafil citrate 20 mg</a> sildenafil 60mg
WrbWG
July 01,2021 06:18
cialis patent expiration <a href="https://cialisnaster.com/">does cialis lowers blood pressure</a> buying cialis cheap
YdvWT
June 30,2021 22:35
<a href="https://pony-town.ru">pony town скачать бесплатно на андроид</a>
DusFK
June 27,2021 23:40
Информационная статья от врачей и экспертов о COVID-19, на авторитетном интернет-издании Коронавирус Контроль со ссылками на официальные и государственные источники Роспотребнадзор - https://coronavirus-control.ru/stoimost-vakcziny-ot-koronavirusa/ Эта ин
JpgYI
June 27,2021 21:27
Информация от врачей и экспертов о корона вирусе, на авторитетном портале Коронавирус-Контроль со ссылками на официальные и государственные источники WHO - https://coronavirus-control.ru/sertifikat-o-vakczinaczii-ot-koronavirusa/ Эта информация для меня б
EwaRC
June 27,2021 14:51
<a href="https://internationalwealth.info/foreign-bank-accounts/kak-otkryt-schet-v-shvejcarskom-banke-chastnomu-licu-iz-rossii/">открыть счет в швейцарском банке в россии</a>
GbrLW
June 26,2021 00:55
achat sildenafil <a href="https://viagrafrancemy.com/">pfizer viagra</a> viagra pour femme avis
ThxXC
June 25,2021 22:54
cialis pour femme en pharmacie <a href="https://franctadalafil.com/">cialis 20 mg avis</a> cialis schweiz
PshRL
June 25,2021 16:37
women taking viagra <a href="https://viagra4m.top/">viagra pill for men</a> viagra memes
WsgBP
June 24,2021 20:09
does cialis make you bigger <a href="https://cialiskira.net/">teva generic cialis</a> cost of cialis 5mg
HgsXU
June 24,2021 18:10
cialis generico <a href="https://cialislostik.com/">what is tadalafil</a> what is better viagra or cialis
GmiEK
June 24,2021 15:23
<a href="https://raznie-poleznosti.ru/">raznie-poleznosti.ru</a>
GnmDN
June 23,2021 21:09
Medicine information leaflet. Long-Term Effects. <a href="https://toplyrica.top">where to buy generic lyrica without rx</a> in Canada All what you want to know about pills. Read now.
LflPP
June 23,2021 21:07
<a href="https://viagra4m.top">https://viagra4m.top</a>
RcdHO
June 23,2021 20:12
Drug prescribing information. What side effects? <a href="https://pregabalinfor.top">where buy pregabalin no prescription</a> in the USA All trends of drugs. Get here.
AazTU
June 23,2021 06:03
sildenafil 20 mg <a href="https://viagrakormes.com/">buy generic 100mg viagra online</a> sildenafil walmart
GnmMW
June 23,2021 03:13
how long does it take for cialis 20mg to work <a href="https://toptadalafilmos.com/">coupon for cialis</a> cialis from india
QufME
June 22,2021 01:28
Medicine information. Short-Term Effects. <a href="https://cymbalta4m.top">order generic cymbalta</a> in Canada All what you want to know about drugs. Read here.
MvxPJ
June 21,2021 07:37
generic viagra usa <a href="https://sildenafilloveme.com/">buy viagra cheaper</a> canadian pharmacy viagra
ZtaIC
June 21,2021 02:15
Medicine information sheet. Long-Term Effects. <a href="https://lyrica2021.top">can you buy lyrica online</a> in the USA All what you want to know about pills. Get now.
PxtET
June 19,2021 03:11
sildenafil without prescription <a href="https://viagrasildenafillife.com/">discount viagra</a> buy viagra cheaply
IviRX
June 19,2021 00:59
how fast does cialis work <a href="https://cialistadalafillove.com/">does cialis work</a> cheapest cialis 20 mg
BkvFK
June 17,2021 01:20
sildenafil citrate 100mg tab <a href="https://lobviagra.net/">viagra amazon</a> sildenafil over the counter cvs
HylOS
June 16,2021 21:22
viagra gel <a href="https://luzviagra.com/">buy viagra cheapest</a> women viagra
CnjPV
May 19,2021 23:20
<a href="https://mycollegeessaywritingservicekos.com/">https://mycollegeessaywritingservicekos.com/</a>
ElyFV
May 11,2021 09:37
Meds information sheet. Drug Class. <a href="https://prednisone4u.top">buying prednisone without dr prescription</a> in USA. Some trends of medication. Read information now.
BgcAN
January 10,2021 20:27
Medicament information for patients. Long-Term Effects. <a href="https://prednisone4u.top">can i get prednisone without insurance</a> in US. Everything about drug. Get here. <a href=https://lomasrankiao.net/una-chica-un-estilo-bad-gyal/#comment-63491>Ev
AmenteeFakSaree
June 25,2020 17:30
<a href="https://cialisle.com/">cialis online cheap</a>
AmenteeFakSaree
June 23,2020 22:21
<a href="https://cialisle.com/">cialis order online</a>
AmenteeFakSaree
June 21,2020 12:01
<a href="https://cialisle.com/">cialis uk</a>
AmenteeFakSaree
June 19,2020 13:07
<a href="https://cialisle.com/">online cialis</a>
microdigisoft
June 02,2020 18:37
Nice work sir !
Leave a Reply
Your email address will not be published.Required fields are marked. *
Name *
Email *
Content
Popular blog
Categories