{"id":81,"date":"2026-02-26T16:39:06","date_gmt":"2026-02-26T15:39:06","guid":{"rendered":"https:\/\/elrebo.de\/?p=81"},"modified":"2026-02-26T16:39:08","modified_gmt":"2026-02-26T15:39:08","slug":"hcsr04_sensor","status":"publish","type":"post","link":"https:\/\/www.elrebo.de\/index.php\/2026\/02\/26\/hcsr04_sensor\/","title":{"rendered":"hcsr04_sensor"},"content":{"rendered":"\n<p id=\"block-ba52b210-d104-4fde-a632-10cbcb3c5b2e\">An ESP-IDF component for <a href=\"https:\/\/elrebo.de\/index.php\/2026\/02\/20\/physical-computing\/\">Physical Computing<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-04934845-0494-4239-8980-9a0598c094ce\">Purpose<\/h2>\n\n\n\n<p id=\"block-c9a9f4c8-2271-4fa0-96fd-a2934e610c6b\">Distance measurement with an HCSR04 sensor for ESP32 systems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-dab95eeb-30b1-4adb-aff2-59912931069c\">How it is done<\/h2>\n\n\n\n<p id=\"block-57d32859-10bd-4201-83ab-9f44dd3122db\">Distance measurement is implemented as a simple C++ class <code>Hcsr04Sensor<\/code>.<\/p>\n\n\n\n<p id=\"block-57d32859-10bd-4201-83ab-9f44dd3122db\">It has one public method <code>GetDistance<\/code>, which returns the measured distance as a float.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-4b33a468-7d65-4059-81cd-f05bc139bcf2\">Where to find it<\/h2>\n\n\n\n<p id=\"block-e3570804-282a-42fb-a1a7-15866fc48f65\"><code>hcsr04_sensor<\/code> is published on the ESP Registry at <a href=\"https:\/\/components.espressif.com\/components\/elrebo-de\/hcsr04_sensor\">https:\/\/components.espressif.com\/components\/elrebo-de\/hcsr04_sensor<\/a>.<\/p>\n\n\n\n<p id=\"block-9bf38eb0-dd0a-4903-8854-b667d909a1dc\">The source code can be found at <a href=\"https:\/\/github.com\/elrebo-de\/hcsr04_sensor\">https:\/\/github.com\/elrebo-de\/hcsr04_sensor<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-81787b41-dec8-474a-a616-9fdad19eba72\">How to use it<\/h2>\n\n\n\n<p id=\"block-f1356d26-fba4-428e-be89-9152fcbbb58f\">As an ESP-IDF component hcsr04_sensor must be included into idf_component.yml as a dependency. As usual this can be done by executing this command:<\/p>\n\n\n\n<p id=\"block-01365eb0-23de-4086-9e6d-efb27460c2ee\"><code>idf.py add-dependency \"elrebo-de\/hcsr04_sensor^1.0.6\"<\/code><\/p>\n\n\n\n<p id=\"block-38365fcf-8f84-48a9-ac55-0bfda022161d\">In CMakeLists.txt <code>\"elrebo-de__hcsr04_sensor\"<\/code> has to be added as a requirement.<\/p>\n\n\n\n<p>Now you can include <code>hcsr04_sensor.hpp<\/code> and use the Hcsr04Sensor class in your program.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An ESP-IDF component for Physical Computing Purpose Distance measurement with an HCSR04 sensor for ESP32 systems. How it is done Distance measurement is implemented as a simple C++ class Hcsr04Sensor. It has one public method GetDistance, which returns the measured distance as a float. Where to find it hcsr04_sensor is published on the ESP Registry [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":134,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-81","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oss"],"_links":{"self":[{"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/comments?post=81"}],"version-history":[{"count":2,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":135,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/posts\/81\/revisions\/135"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/media\/134"}],"wp:attachment":[{"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elrebo.de\/index.php\/wp-json\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}