{"id":1462,"date":"2012-10-20T02:34:51","date_gmt":"2012-10-20T05:34:51","guid":{"rendered":"http:\/\/wordpress.matbra.com\/?p=1462"},"modified":"2012-10-19T02:50:24","modified_gmt":"2012-10-19T05:50:24","slug":"sensor-de-distancia-ultrasonico-com-arduino-e-hc-sr04-arduino-hc-sr04","status":"publish","type":"post","link":"https:\/\/wordpress.matbra.com\/en\/2012\/10\/20\/sensor-de-distancia-ultrasonico-com-arduino-e-hc-sr04-arduino-hc-sr04\/","title":{"rendered":"Ultrasonic distance sensor with Arduino and HC-SR04 (Arduino + HC-SR04)"},"content":{"rendered":"<p>Good night,<\/p>\n<p>Going on with my adventures with Arduino and sensors, today I decided to play with Ultrasonic sensor HC-SR04 to measure distance.<\/p>\n<p>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.<\/p>\n<p>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).<\/p>\n<p>The library must be included on your dir &#8220;arduino-1.0.1\/libraries&#8221; and you must restart your IDE.<\/p>\n<p>Sensor VCC connects to Arduino +5V pin<br \/>\nSensor Trig connects to Arduino PIN 12<br \/>\nSensor Echo connects to Arduino PIN 13<br \/>\nSensor GND connnects to Arduino GND PIN<\/p>\n<p>You can configure it on trig and echo variables.<\/p>\n<p>[code lang=&#8221;c&#8221;]<br \/>\n#include &#8220;Ultrasonic.h&#8221;<br \/>\nint trig = 12;<br \/>\nint echo = 13;<br \/>\nUltrasonic ultrasonic(trig,echo);<\/p>\n<p>void setup() {<br \/>\n  Serial.begin(9600);<br \/>\n}<\/p>\n<p>void loop()<br \/>\n{<br \/>\n  Serial.print(&#8220;Distance CM:&#8221;);<br \/>\n  Serial.println(ultrasonic.Ranging(CM));<br \/>\n  Serial.print(&#8220;Distance INC:&#8221;);<br \/>\n  Serial.println(ultrasonic.Ranging(INC));<br \/>\n  delay(100);<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>Refer\u00eancias:<br \/>\n<a href=\"http:\/\/iteadstudio.com\/store\/images\/produce\/Sensor\/HCSR04\/HC-SR04.pdf\" target=\"_blank\">HC-SR04 DataSheet<\/a><br \/>\n<a href='http:\/\/wordpress.matbra.com\/wp-content\/uploads\/Ultrasonic.rar'>Biblioteca Ultrasonic atualizada para Arduino 1.0.1<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/wordpress.matbra.com\/en\/2012\/10\/20\/sensor-de-distancia-ultrasonico-com-arduino-e-hc-sr04-arduino-hc-sr04\/\">Continue reading<span class=\"screen-reader-text\">Ultrasonic distance sensor with Arduino and HC-SR04 (Arduino + HC-SR04)<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[190],"tags":[215,283,284,278],"class_list":["post-1462","post","type-post","status-publish","format-standard","hentry","category-android-2","tag-arduino-2","tag-distancia","tag-hc-sr04","tag-sensors","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/psjGE-nA","_links":{"self":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/1462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/comments?post=1462"}],"version-history":[{"count":3,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/1462\/revisions"}],"predecessor-version":[{"id":1465,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/1462\/revisions\/1465"}],"wp:attachment":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/media?parent=1462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/categories?post=1462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/tags?post=1462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}