{"id":253,"date":"2011-12-13T22:12:14","date_gmt":"2011-12-13T21:12:14","guid":{"rendered":"http:\/\/stigern.net\/blog\/?p=253"},"modified":"2011-12-20T08:07:23","modified_gmt":"2011-12-20T07:07:23","slug":"ultrasonic-hc-sr04-sensor","status":"publish","type":"post","link":"https:\/\/stigern.net\/blog\/ultrasonic-hc-sr04-sensor\/","title":{"rendered":"Ultrasonic HC-SR04 Sensor"},"content":{"rendered":"<p>I&#8217;ve stumbled by this neat little sonar sensor on eBay a few days ago, I&#8217;ve had some bad experiences with other similiar ultrasonic sensors so I was kind of\u00a0skeptic to this one. But for the low price I couldn&#8217;t resist. Anyhow, it turned out to be a great sensor. It&#8217;s\u00a0accurate\u00a0down to 1 cm, which is perfect and in most cases more than enough. You get it for around 5$ on eBay.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"HC-SR04\" src=\"http:\/\/www.stigern.net\/images\/hc-sr04.jpg\" alt=\"\" width=\"320\" height=\"245\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Only problem I ran into when using it with arduino was the library, got some nasty compiling errors. So I changed a few lines in the library and made it work with Arduino 1.0 and older arduino IDEs.<\/p>\n<p><strong><a href=\"http:\/\/stigern.net\/forum\/download\/file.php?id=6\" target=\"_blank\">Download HC-SR04 Library for Arduino 1.0<\/a><\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/img7.imageshack.us\/img7\/9834\/img20111203184610.jpg\" alt=\"\" width=\"320\" height=\"240\" \/><\/p>\n<p>Also wrote a little example for using it with a serial display:<\/p>\n<p>&nbsp;<\/p>\n<p>[codesyntax lang=&#8221;cpp&#8221; lines=&#8221;no&#8221; blockstate=&#8221;collapsed&#8221;]<\/p>\n<pre>#include &lt;SoftwareSerial.h&gt;\r\n#include \"Ultrasonic.h\"\r\nUltrasonic ultrasonic(12,13);\r\n\r\nSoftwareSerial mySerial(5,4);\r\n\r\nvoid setup()\r\n{\r\nmySerial.begin(9600);\r\n}\r\n\r\nvoid loop()\r\n{\r\nmySerial.print(\"Distance: \");\r\nmySerial.print(ultrasonic.Ranging(CM));\r\nmySerial.println(\" Cm.\");\r\ndelay(250);\r\nmySerial.print(\"?f\"); \/\/ Clear display.\r\n}<\/pre>\n<p>[\/codesyntax]<\/p>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve stumbled by this neat little sonar sensor on eBay a few days ago, I&#8217;ve had some bad experiences with other similiar ultrasonic sensors so I was kind of\u00a0skeptic to this one. But for the low price I couldn&#8217;t resist. Anyhow, it turned out to be a great sensor. It&#8217;s\u00a0accurate\u00a0down to 1 cm, which is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,4],"tags":[77,16,67,78,73,74,76,75,72,71],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-arduino-electronics","category-electronics","tag-1-0","tag-arduino","tag-cheap","tag-ebay","tag-hc","tag-hc-sr04","tag-library","tag-sensor","tag-sonar","tag-ultrasonic"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":15,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":364,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions\/364"}],"wp:attachment":[{"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}