Skip to content

Ultrasonic distance sensor with Arduino and HC-SR04 (Arduino + HC-SR04)

Good night,

Going on with my adventures with Arduino and sensors, today I decided to play with Ultrasonic sensor HC-SR04 to measure distance.

HC-SR04 is pretty easy to work with, it has 4 pins, VCC to energy, Trig to start a measurement, Echo to get the distance, and GND to ground.

It has a library to get it working, it is called Ultrasonic. The only problem that I had was the Library is out of date, it still uses WProgram.h but Arduino 1.0.1 uses Arduino.h, so I updated it. (You can get on the end of the post).

The library must be included on your dir “arduino-1.0.1/libraries” and you must restart your IDE.

Sensor VCC connects to Arduino +5V pin
Sensor Trig connects to Arduino PIN 12
Sensor Echo connects to Arduino PIN 13
Sensor GND connnects to Arduino GND PIN

You can configure it on trig and echo variables.

[code lang=”c”]
#include “Ultrasonic.h”
int trig = 12;
int echo = 13;
Ultrasonic ultrasonic(trig,echo);

void setup() {
Serial.begin(9600);
}

void loop()
{
Serial.print(“Distance CM:”);
Serial.println(ultrasonic.Ranging(CM));
Serial.print(“Distance INC:”);
Serial.println(ultrasonic.Ranging(INC));
delay(100);
}
[/code]

Referências:
HC-SR04 DataSheet
Biblioteca Ultrasonic atualizada para Arduino 1.0.1

Published inAndroid

1,670 Comments

  1. Big thanks to whoever wrote this, you saved me a lot of time hunting for the same info on other sites, and a stop at ideaswithoutnoise only added more useful detail without going off topic, that kind of focus is honestly hard to come across these days when most posts wander everywhere.

  2. Thanks again for the post, I learned a couple of things I can actually use later this week, and after I went over gardenvertex the rest of the site looked equally promising, definitely going to spend more time here when I get a free moment over the weekend to read more carefully.

  3. Comfortable reading experience throughout, no jarring tone shifts and no awkward formatting, and a look at nightlifehub kept that smooth feel going, the kind of editorial polish that goes unnoticed when present but glaring when absent is something this site has clearly invested in across the broader content as well which deserves recognition.

  4. Picked this up while looking for something else and ended up reading every paragraph because it was actually informative, and after executeprogress I was sure I would come back, that does not happen often when most sites bury the useful parts under endless ads and pop ups today and across most categories online.

  5. Loved the writing voice here, friendly without being fake and confident without being arrogant, and a stop at buildforwardlogic carried the same tone forward, the kind of personality that makes a reader feel welcome rather than lectured at which is a balance plenty of writers struggle to find no matter how long they have been at it.

  6. A piece that did not waste any of its substance on sales or promotion, and a look at profitnexus continued that pure content focus, sites that resist the urge to monetise every paragraph are increasingly rare and this one has clearly made the editorial choice to keep the writing clean from commercial intrusion which I value highly.

  7. Sayt rasmiy litsenziya asosida ishlaydi va foydalanuvchilar ma’lumotlarini himoya qiladi.
    Yangi nashrlar va ommabop o’yinlar kazino sahifasida birinchi o’rinda namoyon bo’ladi.
    starz888 https://888-uz8.com/
    Sport tikish bo’limida futbol, tennis, basketbol va kibersport kabi ko’plab sport turlari mavjud.
    Promo takliflar foydalanuvchilar uchun qulay tarzda saytda joylashtirilgan.
    Yangi hisob yaratish telefon, email yoki bir tugma orqali tez va oson bajariladi.

  8. Closed the tab and immediately reopened it ten minutes later because I wanted to reread a part, and a stop at actionwithsignal drew the same return, content that pulls you back after closing it is doing something well beyond the average and worth marking as exceptional in my mental catalogue of reliable sites.

  9. Bookmarking this for later, the kind of resource I want to keep nearby, and a quick look at inkedvoyager confirmed the rest of the site is worth the same treatment, definitely going into my reference folder for the next time the topic comes up at work or in conversation with someone who asks.

  10. Now considering carefully how to share this site with the right audience rather than broadcasting widely, and a look at socialcircle extended that careful sharing impulse, content worth sharing carefully rather than spamming is content that has earned a higher kind of recommendation and this site has earned that careful shareability throughout pieces.

  11. Decided to set aside time later to read more carefully, and a stop at digitaljournal reinforced that decision, content that earns a calendar entry rather than just a passing read is in a different tier altogether and this site is clearly working at that elevated level which I really do appreciate as a reader today.

  12. Thanks for putting in the work to make this approachable, plenty of sites cover the same ground but most do it badly, and a quick visit to clarityturnskeys confirmed this one stands apart, simple language and useful examples without anyone trying to sell me anything along the way which I really appreciated.

  13. http://www.factorytapestry.com is a Trusted Online Wall Hanging Tapestry Store. We are selling online art and decor since 2008, our digital business journey started in Australia. We sell 100 made-to-order quality printed soft fabric tapestry which are just too perfect for decor and gifting. We offer Up-to 50 percent OFF Storewide Sale across all the Wall Hanging Tapestries. We provide Fast Shipping USA, CAN, UK, EUR, AUS, NZ, ASIA and Worldwide Delivery across 100+ countries.

  14. If I had encountered this site five years ago I would have been telling everyone about it, and a look at visualharbor extended that retrospective enthusiasm, the version of me who used to recommend favourite blogs frequently would have made sure friends knew about this one and that earlier enthusiasm is partially returning to me here.

  15. Came away with some new perspectives I had not considered before, and after strategyforwardpath those ideas felt more complete, the kind of content that stays with you a little while after reading rather than slipping out the moment you switch tabs and move on with your day to whatever comes next.

  16. Now recognising the post as a rare example of careful writing on a topic that mostly receives careless treatment, and a stop at forwardenergyactivated extended that contrast with the average elsewhere, content that highlights how much the average is settling for low quality is content that has both internal merit and external value as a benchmark.

  17. Just want to acknowledge that the writing here is doing something right, and a quick visit to brightlivinghub confirmed the same standards run across the broader site, recognising good work is something I try to do when I find it because the alternative is silence and silence rewards mediocrity.

  18. Left me wanting to read more rather than feeling burned out, that is a good sign, and a look at stellarpath confirmed there is plenty more here to explore, the kind of writing that builds appetite rather than killing it which is a rare quality on the modern open internet today across most categories of content.

  19. Bookmark earned and shared the link with one specific person who would care, and a look at quantumleafhub got the same targeted share, sharing carefully rather than broadcasting is a discipline I try to maintain and this site is generating shares from me at a sustainable rate rather than the spam rate of viral content.

  20. Liked the way the post balanced confidence and humility, and a stop at gentleparent maintained the same balance, knowing when to assert and when to acknowledge uncertainty is a sign of mature thinking and the writers here have clearly developed that calibration through what I assume is years of careful work on their craft.

  21. I really like the calm tone here, it does not push anything on the reader, and after I went through digitalhaven I felt the same way, just steady useful content laid out without drama, which is exactly what someone trying to learn something quickly needs to find rather than aggressive marketing.

  22. Found the writing surprisingly fresh for what is by now a well covered topic, and a stop at urbanmarket kept that freshness going across the related pages, original perspective on familiar ground is hard to come by and this site has clearly earned its place in the conversation rather than just rehashing old ideas.

  23. fantastic points altogether, you simply gained a new reader. What would you suggest about your post that you made some days ago? Any positive?

  24. 888 مراهنات هو موقع للمراهنات والألعاب الإلكترونية يقدم خدمات تسجيل الدخول والدعم بلغات متعددة.
    تجذب المنصة جمهورًا واسعًا بفضل تنوع ألعابها وخدماتها.

    القسم الثاني:
    توفر 888starz ألعاب سلوتس وبث مباشر ومراهنات على المنافسات الرياضية.

    القسم الثالث:
    تساعد هذه العروض في زيادة فرص اللعب بموارد إضافية.

    القسم الرابع:
    بالرغم من المزايا يجب على المستخدمين اللعب بمسؤولية وتحديد حدود ميزانيتهم.

  25. Skipped the comments section but might come back to read it, and a stop at artistneedle hinted at a quality reader community, sites where the comments are worth reading separately from the post are increasingly rare and signal a particular kind of audience that has grown around the editorial vision over time gradually.

  26. В каталоге платформы доступны слоты, живые дилеры и разнообразные спортивные события для ставок в любое время.
    888 бет https://888starz-uzb6.com

  27. Раздел с играми на 888starz включает слоты, настольные игры и live-раздел с живыми дилерами.

    Контактные каналы включают чат, электронную почту и раздел FAQ с подробными ответами.
    888starz site https://888-uz1.com

  28. Worth flagging this site to a few specific friends who would appreciate the editorial sensibility, and a look at progresswithcontrol added more pages I will mention to them, recommending sites to specific people requires understanding both the site and the person and this site is making those personalised recommendations easy and natural for me.

  29. A thoughtful read in a week that has been mostly noisy, and a look at shadowbeast carried that thoughtful quality across more pages, finding pockets of considered writing in a week of distractions is one of the small wins of careful curation and this site is providing those pockets at a sustainable rate.

  30. Thanks for the strategies you are discussing on this blog. Another thing I would like to say is the fact that getting hold of copies of your credit profile in order to look at accuracy of any detail is one first activity you have to undertake in credit improvement. You are looking to clean your credit history from detrimental details flaws that spoil your credit score.

  31. Felt like the writer was speaking directly to someone with my level of curiosity, neither talking down nor showing off, and a stop at actionremovesfriction kept that comfortable matching going, finding writing that meets you where you are rather than asking you to climb up or stoop down feels great every time it happens.

  32. Reading this in the gap between work projects was a small but meaningful break, and a stop at nexustower extended that gentle reset, content that provides genuine refreshment rather than just distraction during work breaks is content with a particular kind of utility and this site fits that role for me reliably during work days.

  33. Started smiling at one paragraph because the writing was just nice, and a look at focusandexecute produced a couple more such moments, prose that produces small spontaneous reactions in the reader is doing more than just transferring information and the writers here are clearly hitting that level fairly consistently throughout pieces.

  34. Reading this gave me the rare experience of fully agreeing with all the conclusions, and a stop at claritypowersresults continued that agreement pattern, content that aligns with my existing views without seeming designed to do so is just content that happens to be reasonable and this site reads as reasonable rather than ideological mostly.

  35. Now noticing the post fit a particular gap in my reading without my having articulated the gap before, and a look at broadcastnova extended that gap filling effect, content that meets needs I had not consciously formulated is content with reader insight and this site has clearly developed that anticipatory editorial sense across many pieces.

  36. Spent a few minutes here and came away with a clearer picture of the topic, the writing keeps things simple without dumbing them down, and after a stop at clarityturnsideas the rest of the points lined up neatly which is something I appreciate when I am short on time and need answers fast.

  37. Worth pointing out that the writing reads as confident without being defensive about it, and a look at actioncreatespace extended that secure tone, content that does not pre emptively argue against imagined critics has a different quality from defensive writing and this site reads as written from a place of real ease.

  38. Approaching this with the usual skepticism I bring to new sites and being slowly persuaded, and a stop at focusbeatsfriction continued that gradual persuasion, the careful path from skeptical reader to genuine fan is the only one I trust and this site has walked me along that path through patient consistent quality across pieces.

  39. Glad I gave this a chance instead of bouncing on the headline, and after strongharbor I was certain I had made the right call, snap judgements based on titles miss a lot of good content and this is a reminder to slow down and check things out before scrolling past in a hurry.

  40. Appreciate the work that went into laying this out so clearly, every section earns its place without filler, and a look at ideasunlockmovement confirmed the same care, definitely the kind of place that deserves a return visit when the topic comes up again later in the future or for any related question.

  41. In the middle of an otherwise scattered day this post landed as a moment of focus, and a stop at clarityroute extended that focused feeling across more pages, content that anchors a fragmented day rather than contributing to the fragmentation is content with real centring effect and this site is providing that anchoring function for me.

  42. Reading this site over the past week has changed how I evaluate content in this space, and a look at progressengineon extended that recalibration, the standards I bring to reading on the topic have shifted upward as a direct result of regular exposure to this kind of work and that shift will outlast any single reading session.

  43. stars888 هي منصة مراهنات عبر الإنترنت تقدم ألعاب كازينو وخيارات رهان متنوعة للمستخدمين العرب.
    888starz هي منصة ترفيهية تقدم تجارب لعب متميزة.

    القسم الثاني:
    تضيف المنصة ألعابًا جديدة بانتظام لتبقي تجربة المستخدم متجددة.

    القسم الثالث:
    توفّر المنصة خيارات دفع متنوعة تراعي احتياجات المستخدمين المختلفة.

    القسم الرابع:
    يستفيد اللاعبون من نظام نقاط ومكافآت يعزز من قيمة اللعب المستمر.

  44. Adding this site to my regular reading list, the post earned that on its own, and a quick stop at clarityguidesexecution sealed the decision, the kind of place worth checking back with from time to time because it consistently produces material that holds up against a critical reading too which I really value.

  45. موقع مراهنات 888
    تتميز المنصة بواجهة أنيقة وسهلة التصفح مما يسهل على الأعضاء الوصول إلى المحتوى.

    القسم الثاني:
    تهتم 888starz بتحديث محتواها لضمان تجربة حديثة ومتنوعة للمستخدمين.

    القسم الثالث:
    توفر المنصة أدوات معلوماتية مثل جداول المباريات وإحصاءات اللاعبين لتسهيل الاختيار.

    القسم الرابع:
    تسعى المنصة للحفاظ على بيئة تشريعية سليمة عبر الالتزام بالمعايير المحلية والدولية.

  46. Once you find a site like this the search for similar voices begins, and a look at victorysquad extended the search energy, finding a high quality reference point makes the gap between it and adjacent sources visible in a way it was not before and this site has provided that high reference point across multiple recent visits.

  47. Will recommend this to a couple of friends who have been asking about this exact topic, and after visionintoprocess I have even more reason to do so, the kind of site that earns word of mouth rather than chasing it through aggressive marketing or paid placements is always a treat to find online.

  48. Nice to see a post that does not try to overcomplicate the basics for the sake of looking smart, and once I looked at progresswithcontrol the same direct tone was there too, which honestly makes a difference when you are short on time and want answers without long pointless intros.

  49. Bookmark folder created specifically for this site, and a look at clarityleadsaction confirmed the dedicated folder was the right call, dedicated folders for individual sites are a level of organisation I rarely deploy and this site has earned that level of dedicated tracking based on the consistency I have seen so far across sessions.

Leave a Reply

Your email address will not be published. Required fields are marked *