{"id":25881,"date":"2019-11-04T17:57:09","date_gmt":"2019-11-04T09:57:09","guid":{"rendered":"\/blog\/?p=25881"},"modified":"2020-11-05T18:14:49","modified_gmt":"2020-11-05T10:14:49","slug":"hc-sr04-features-arduino-raspberrypi-guide","status":"publish","type":"post","link":"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/","title":{"rendered":"Arduino Ultrasonic Sensor Overview and Tutorials"},"content":{"rendered":"\n<p>With Arduino ultrasonic sensors like the HC-SR04, you can measure the distance. Through this Arduino tutorial, you will learn how an Ultrasonic sensor works and how do you use it with the Arduino and even with the Raspberry Pi.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png\" alt=\"\" width=\"522\" height=\"262\"\/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">What is an Arduino Ultrasonic Sensor?<\/span><\/strong><\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2019\/11\/hcsr04-1.png\" alt=\"\" class=\"wp-image-25891\" width=\"165\" height=\"194\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-1.png 330w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-1-255x300.png 255w\" sizes=\"(max-width: 165px) 100vw, 165px\" \/><\/figure><\/div>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\">An ultrasonic sensor is a sensor that measures distances through ultrasound which travels through the air. If the ultrasound hits an object or obstacle on its path, it will then bounce back towards the sensor.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong> Ultrasonic Sensor<\/strong> Working Principle<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/11\/How-ultrasonic-sensor-works.jpg?w=700&amp;ssl=1\" alt=\"\"\/><figcaption><a href=\"https:\/\/randomnerdtutorials.com\/complete-guide-for-ultrasonic-sensor-hc-sr04\/\">ref<\/a><\/figcaption><\/figure><\/div>\n\n\n\n<p>Here is a simple example of how an ultrasonic sensor works to measure distance: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Firstly, the transmitter (trig pin) sends a sound wave<\/li><li>The object picks the wave up, reflecting it back to the sensor.<\/li><li>The receiver (echo pin) picks it up<\/li><\/ul>\n\n\n\n<p style=\"background-color:#eafffc;color:#000000\" class=\"has-text-color has-background\"><strong>The time between transmission and reception allows distance between to be calculated since sound&#8217;s velocity in air is known.<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>Examples of Arduino Ultrasonic Sensors<\/strong><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">HC-SR04<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/05\/image-64.png\" alt=\"\" class=\"wp-image-32828\" width=\"295\" height=\"173\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/05\/image-64.png 555w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/05\/image-64-300x176.png 300w\" sizes=\"(max-width: 295px) 100vw, 295px\" \/><\/figure><\/div>\n\n\n\n<p>One of the most popular ultrasonic sensors would be the HC-SR04. The configuration pin of HC-SR04 is VCC (1), TRIG (2), ECHO (3), and GND (4). The&nbsp;supply voltage&nbsp;of VCC is&nbsp;5V&nbsp;and you attach TRIG and ECHO pin to any Digital I\/O in your Arduino Board to power it.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Specifications<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>Power Supply: DC 5V<\/li><li>Working Current: 15mA<\/li><li>Working Frequency: 40Hz<\/li><li>Ranging Distance : 2cm \u2013 400cm\/4m<\/li><li>Resolution : 0.3 cm<\/li><li>Measuring Angle: 15 degree<\/li><li>Trigger Input Pulse width: 10uS<\/li><li>Dimension: 45mm x 20mm x 15mm<\/li><\/ul>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Grove &#8211; Ultrasonic Distance Sensor<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/05\/image-65.png\" alt=\"\" class=\"wp-image-32829\" width=\"284\" height=\"157\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/05\/image-65.png 441w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/05\/image-65-300x167.png 300w\" sizes=\"(max-width: 284px) 100vw, 284px\" \/><\/figure><\/div>\n\n\n\n<p>Next up we have our very own Grove &#8211; Ultrasonic Distance Sensor, Seeed&#8217;s very own version of an ultrasonic distance sensor which is comparative to the HC-SR04.<\/p>\n\n\n\n<p>It can measure from 3cm to 350cm&nbsp;with the accuracy up to 2mm.&nbsp; It&nbsp;is a perfect ultrasonic&nbsp;module for distance measurement, proximity sensors, and&nbsp;ultrasonic detector.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Specifications<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>Power Supply: 3.3V &#8211; 5V<\/li><li>Operating Current: 8mA<\/li><li>Working Frequency: 40Hz<\/li><li>Ranging Distance : 3cm \u2013 350cm\/3.5m<\/li><li>Resolution : 1 cm<\/li><li>Measuring Angle: 15 degree<\/li><li>Trigger Input Pulse width: 10uS TTL<\/li><li>Dimension: 50mm x 25mm x 16mm <\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>HC-SR04 vs <a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html?utm_source=blog&amp;utm_medium=blog\">Seeed Grove Ultrasonic Distance Sensor<\/a><\/strong><\/span><\/h2>\n\n\n\n<p>So what is the difference between the HC-SR04 and <a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html?utm_source=blog&amp;utm_medium=blog\">Seeed Grove Ultrasonic Distance Sensor<\/a>?<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/github.com\/SeeedDocument\/Grove_Ultrasonic_Ranger\/raw\/master\/optimizing\/Compare.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><th><\/th><th>Grove &#8211; Ultrasonic Distance Sensor<\/th><th>HC-SR04<\/th><\/tr><tr><td><strong>Working Voltage<\/strong><\/td><td>3.3V \/ 5V compatible<br>Wide voltage level: 3.2V &#8211; 5.2V<\/td><td>5V<\/td><\/tr><tr><td><strong>Measurement Range<\/strong><\/td><td>3cm &#8211; 350cm<\/td><td>2cm &#8211; 400cm<\/td><\/tr><tr><td><strong>I\/O Pins needed<\/strong><\/td><td>3<\/td><td>4<\/td><\/tr><tr><td><strong>Operating Current<\/strong><\/td><td>8mA<\/td><td>15mA<\/td><\/tr><tr><td><strong>Dimensions<\/strong><\/td><td>50mm x 25mm x 16mm<\/td><td>45mm x 20mm x 15mm<\/td><\/tr><tr><td><strong>Ease of pairing with Raspberry Pi<\/strong> <strong>and Arduino<\/strong><\/td><td>Easy, directly connect to I\/O of Raspberry Pi<br><br>Has Grove Connector for easy connection to Arduino<\/td><td>Requires voltage conversion circuit<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>The main differences we can observe from the table above include:<\/strong><\/h4>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\"><strong>Working Voltage<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Grove -Ultrasonic Distance Sensor supports a wider voltage level<\/li><\/ul>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\"><strong>I\/O Pins Needed<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Transmitting and receiving signals on the Grove-Ultrasonic Distance Sensor share one pin, saving the requirement of using all available pins<\/li><\/ul>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\"><strong>Ease of pairing with Raspberry Pi and Arduino<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The Grove Ultrasonic Distance Sensor supports 3.3V, allowing it to be directly connected to the I\/O of the Raspberry Pi instead of using a voltage conversion circuit<\/li><li>With the onboard plug and play Grove connector, if you have a <a href=\"https:\/\/www.seeedstudio.com\/Base-Shield-V2.html\">Grove-Base shield<\/a> or a <a href=\"https:\/\/www.seeedstudio.com\/Seeeduino-V4-2-p-2517.html\">Seeeduino<\/a>, you can easily connect the Grove-Ultrasonic Distance Sensor with a wire.<\/li><\/ul>\n\n\n\n<p style=\"background-color:#f5fafd;color:#000000\" class=\"has-text-color has-background\"><strong>Despite the popularity of HC-SR04, the <a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html\">grove ultrasonic distance sensor<\/a> is a more versatile option that allows for lesser external components and easier pairing with the Raspberry Pi and the Arduino. Not to mention, we provide full documents and libraries for Arduino, Python, and&nbsp;Codecraft so that you can use the Grove &#8211; Ultrasonic Distance Sensor with Arduino and&nbsp;Raspberry pi easily! <\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">Getting started with Ultrasonic Sensor Arduino and Raspberry Pi Pairing Guide<\/span><\/strong><\/h2>\n\n\n\n<p>For this tutorial, we will be using the <a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html?utm_source=blog&amp;utm_medium=blog\">Grove Ultrasonic Distance Sensor<\/a> and pair it with the Arduino and Raspberry Pi. For the first tutorial, we have the guide for Arduino. Scroll down for the tutorial on Raspberry Pi.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Ultrasonic Sensor Arduino Guide:<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">What do you need? <\/h4>\n\n\n\n<figure class=\"wp-block-gallery columns-3 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"210\" height=\"157\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2019\/11\/seeeduino-v4.2-1.jpg\" alt=\"\" data-id=\"27056\" data-full-url=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2019\/11\/seeeduino-v4.2-1.jpg\" data-link=\"\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/seeeduino-v4-2-2\/\" class=\"wp-image-27056\"\/><figcaption class=\"blocks-gallery-item__caption\"><a href=\"http:\/\/www.seeedstudio.com\/Seeeduino-V4.2-p-2517.html?utm_source=blog&amp;utm_medium=blog\">Seeeduino V4.2<\/a><\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"210\" height=\"157\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2019\/11\/base-shield-1.jpg\" alt=\"\" data-id=\"27057\" data-full-url=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2019\/11\/base-shield-1.jpg\" data-link=\"\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/base-shield-3\/\" class=\"wp-image-27057\"\/><figcaption class=\"blocks-gallery-item__caption\"><a href=\"https:\/\/www.seeedstudio.com\/Base-Shield-V2.html?utm_source=blog&amp;utm_medium=blog\">Grove Base Shield<\/a><\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"441\" height=\"245\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/05\/image-65.png\" alt=\"\" data-id=\"32829\" data-full-url=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/05\/image-65.png\" data-link=\"\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/image-65-3\/\" class=\"wp-image-32829\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/05\/image-65.png 441w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/05\/image-65-300x167.png 300w\" sizes=\"(max-width: 441px) 100vw, 441px\" \/><figcaption class=\"blocks-gallery-item__caption\"><a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html?utm_source=blog&amp;utm_medium=blog\"> Grove Ultrasonic Distance Sensor <\/a><\/figcaption><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p>You can either watch the following video or read the written tutorial below for the instructions!<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube aligncenter wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"How to measure and display the distance with Arduino#Grove#Arduino\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/XTEKL-thGX8?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Step by step instructions<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Hardware connections<\/strong><\/h4>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\"><strong>Step 1: <\/strong>Connect Ultrasonic Ranger to port D7 of Grove-Base Shield<\/p>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\"><strong>Step 2: <\/strong>Plug Grove &#8211; Base shield into Seeeduino<\/p>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\"><strong>Step 3: <\/strong>Connect Seeeduino to PC via a USB cable<\/p>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\">It should look like this after completing the above steps:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/github.com\/SeeedDocument\/Grove_Ultrasonic_Ranger\/raw\/master\/img\/arduino%20connection.jpg\" alt=\"\" width=\"306\" height=\"230\"\/><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Software configurations:<\/strong><\/h4>\n\n\n\n<p><strong>Step 1: <\/strong>Download the&nbsp;<a href=\"https:\/\/github.com\/Seeed-Studio\/Grove_Ultrasonic_Ranger\/archive\/master.zip\">UltrasonicRanger Library<\/a>&nbsp;from Github.<\/p>\n\n\n\n<p><strong>Step 2:<\/strong> Refer&nbsp;<a href=\"http:\/\/wiki.seeedstudio.com\/How_to_install_Arduino_Library\">How to install library<\/a> Arduino if you are unsure on how to install library to your Arduino.<\/p>\n\n\n\n<p><strong>Step 3:<\/strong> Copy the code into Arduino IDE and upload it. If you do not know how to upload the code, please check our guide on&nbsp;<a href=\"http:\/\/wiki.seeedstudio.com\/Upload_Code\/\">how to upload code<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"Ultrasonic.h\"\n\nUltrasonic ultrasonic(7);\nvoid setup()\n{\n    Serial.begin(9600);\n}\nvoid loop()\n{\n    long RangeInInches;\n    long RangeInCentimeters;\n\n    Serial.println(\"The distance to obstacles in front is: \");\n    RangeInInches = ultrasonic.MeasureInInches();\n    Serial.print(RangeInInches);\/\/0~157 inches\n    Serial.println(\" inch\");\n    delay(250);\n\n    RangeInCentimeters = ultrasonic.MeasureInCentimeters(); \/\/ two measurements should keep an interval\n    Serial.print(RangeInCentimeters);\/\/0~400cm\n    Serial.println(\" cm\");\n    delay(250);\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Step 4:<\/strong> We will see the distance display on the terminal as below:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>The distance to obstacles in front is:\n2 inches\n6 cm\nThe distance to obstacles in front is:\n2 inches\n6 cm\nThe distance to obstacles in front is:\n2 inches\n6 cm<\/code><\/pre>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\">If you&#8217;re looking to connect <strong>multiple ultrasonic to one Arduino<\/strong>, you can do so by connecting one to D2 and the other to D3. Below are the respective codes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"Ultrasonic.h\"\n\nUltrasonic ultrasonic1(2);\nUltrasonic ultrasonic2(3);\nvoid setup()\n{\n    Serial.begin(9600);\n}\nvoid loop()\n{\n    long RangeInCentimeters1;\n    long RangeInCentimeters2;\n\n    RangeInCentimeters1 = ultrasonic1.MeasureInCentimeters(); \/\/ two measurements should keep an interval\n    Serial.print(RangeInCentimeters1);\/\/0~400cm\n    Serial.println(\" cm\");\n\n    RangeInCentimeters2 = ultrasonic2.MeasureInCentimeters(); \/\/ two measurements should keep an interval\n    Serial.print(RangeInCentimeters2);\/\/0~400cm\n    Serial.println(\" cm\");\n\n    delay(250);\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Using <strong>Ultrasonic Sensor with Raspberry Pi<\/strong><\/h3>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\">In this guide, we&#8217;ll be using the Raspberry Pi 3B for the guide below but other models that support the base hat can be used as well.<\/p>\n\n\n\n<p><em>If you&#8217;ve yet to own raspberry pi, you can pick up a <a href=\"https:\/\/www.seeedstudio.com\/Raspberry-Pi-Zero-p-4254.html?utm_source=blog&amp;utm_medium=blog\">Raspberry Pi Zero<\/a>, a low-cost option to use alongside the Grove-Ultrasonic Distance Sensor. <\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>What do you need?<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-gallery columns-3 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"525\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2019\/11\/raspberry-pi-3-model-b.jpg\" alt=\"\" data-id=\"27061\" data-full-url=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2019\/11\/raspberry-pi-3-model-b.jpg\" data-link=\"\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/raspberry-pi-3-model-b\/\" class=\"wp-image-27061\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/raspberry-pi-3-model-b.jpg 700w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/raspberry-pi-3-model-b-300x225.jpg 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><figcaption class=\"blocks-gallery-item__caption\">Raspberry Pi<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"525\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2019\/11\/grove-base-hat-2.jpg\" alt=\"\" data-id=\"27062\" data-full-url=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2019\/11\/grove-base-hat-2.jpg\" data-link=\"\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/grove-base-hat-3\/\" class=\"wp-image-27062\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/grove-base-hat-2.jpg 700w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/grove-base-hat-2-300x225.jpg 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><figcaption class=\"blocks-gallery-item__caption\"><a href=\"https:\/\/www.seeedstudio.com\/Grove-Base-Hat-for-Raspberry-Pi.html\">Raspberry Pi Base Hat<\/a><\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"441\" height=\"245\" src=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/05\/image-65.png\" alt=\"\" data-id=\"32829\" data-full-url=\"https:\/\/blog.seeedstudio.com\/wp-content\/uploads\/2020\/05\/image-65.png\" data-link=\"\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/image-65-3\/\" class=\"wp-image-32829\" srcset=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/05\/image-65.png 441w, https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2020\/05\/image-65-300x167.png 300w\" sizes=\"(max-width: 441px) 100vw, 441px\" \/><figcaption class=\"blocks-gallery-item__caption\"> <a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html?utm_source=blog&amp;utm_medium=blog\"> Grove Ultrasonic Distance Sensor <\/a> <\/figcaption><\/figure><\/li><\/ul><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step by Step Instructions<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Hardware Connections<\/strong><\/h4>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\"><strong>Step 1: <\/strong>Plug the Grove Base Hat into Raspberry <\/p>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\"><strong>Step 2: <\/strong>Connect the Grove &#8211; Ultrasonic Ranger to port D5 of the Base Hat<\/p>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\"><strong>Step 3:<\/strong> Connect the Raspberry Pi to PC through USB cable<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You can connect the ultrasonic ranger to any GPIO port as well but make sure you change the command with the corresponding port number<\/li><\/ul>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\">It should look something like this after completing the above steps:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/github.com\/SeeedDocument\/Grove_Base_Hat_for_Raspberry_Pi\/raw\/master\/img\/connect2.jpg\" alt=\"\" width=\"256\" height=\"192\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Software Configurations:<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Step 1<\/strong>. Follow&nbsp;<a href=\"http:\/\/wiki.seeedstudio.com\/Grove_Base_Hat_for_Raspberry_Pi\/#installation\">Setting Software<\/a>&nbsp;to configure the development environment.<\/li><li><strong>Step 2<\/strong>. Download the source file by cloning the grove.py library.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~\ngit clone https:\/\/github.com\/Seeed-Studio\/grove.py<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Step 3<\/strong>. Execute below commands to run the code. <\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>cd grove.py\/grove\npython grove_ultrasonic_ranger.py 5 6<\/code><\/pre>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\">Following is the grove_ultrasonic_ranger.py code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import sys\nimport time\nfrom grove.gpio import GPIO\n\nusleep = lambda x: time.sleep(x \/ 1000000.0)\n\n_TIMEOUT1 = 1000\n_TIMEOUT2 = 10000\n\nclass GroveUltrasonicRanger(object):\n    def __init__(self, pin):\n        self.dio =GPIO(pin)\n\n    def _get_distance(self):\n        self.dio.dir(GPIO.OUT)\n        self.dio.write(0)\n        usleep(2)\n        self.dio.write(1)\n        usleep(10)\n        self.dio.write(0)\n\n        self.dio.dir(GPIO.IN)\n\n        t0 = time.time()\n        count = 0\n        while count &lt; _TIMEOUT1:\n            if self.dio.read():\n                break\n            count += 1\n        if count >= _TIMEOUT1:\n            return None\n\n        t1 = time.time()\n        count = 0\n        while count &lt; _TIMEOUT2:\n            if not self.dio.read():\n                break\n            count += 1\n        if count >= _TIMEOUT2:\n            return None\n\n        t2 = time.time()\n\n        dt = int((t1 - t0) * 1000000)\n        if dt > 530:\n            return None\n\n        distance = ((t2 - t1) * 1000000 \/ 29 \/ 2)    # cm\n\n        return distance\n\n    def get_distance(self):\n        while True:\n            dist = self._get_distance()\n            if dist:\n                return dist\n\n\nGrove = GroveUltrasonicRanger\n\n\ndef main():\n    if len(sys.argv) &lt; 2:\n        print('Usage: {} pin_number'.format(sys.argv[0]))\n        sys.exit(1)\n\n    sonar = GroveUltrasonicRanger(int(sys.argv[1]))\n\n    print('Detecting distance...')\n    while True:\n        print('{} cm'.format(sonar.get_distance()))\n        time.sleep(1)\n\nif __name__ == '__main__':\n    main()<\/code><\/pre>\n\n\n\n<p style=\"background-color:#e1ffdd;color:#000000\" class=\"has-text-color has-background\"><strong>If everything goes well, you should see the following result (It shows the distance measured by the sensor)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pi@raspberrypi:~\/grove.py\/grove $ python grove_ultrasonic_ranger.py 5 6\nDetecting distance...\n121.757901948 cm\n246.894770655 cm\n2.60205104433 cm\n0.205533257846 cm\n0.657706425108 cm\n247.433267791 cm\n122.485489681 cm\n^CTraceback (most recent call last):\n  File \"grove_ultrasonic_ranger.py\", line 110, in &lt;module>\n    main()\n  File \"grove_ultrasonic_ranger.py\", line 107, in main\n    time.sleep(1)\nKeyboardInterrupt<\/code><\/pre>\n\n\n\n<p style=\"color:#000000\" class=\"has-text-color\">You can quit this program by simply pressing <strong>Ctrl + C<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Arduino Ultrasonic Sensor Projects<\/h2>\n\n\n\n<p>Now you know how to program your Ultrasonic sensor, why not try your hand at some of these projects! <\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Drinking Reminder Water Bottle<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hackster.imgix.net\/uploads\/attachments\/860491\/title_Iy9Zgjbqas.jpg?auto=compress%2Cformat&amp;w=900&amp;h=675&amp;fit=min\" alt=\"Drinking Reminder Water Bottle with AllThingsTalk\" width=\"352\" height=\"264\"\/><\/figure><\/div>\n\n\n\n<p> Do you often forget to drink water when you are busy? With this project, you can create a drinking reminder to alert you to drink water! With the ultrasonic sensor, it is able to detect the changes in the water level in the bottle and also calculate how much water was drunk! <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">What do you need:<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.seeedstudio.com\/Wio-Link.html\">Seeed Wio Link<\/a><\/li><li><a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html?utm_source=blog&amp;utm_medium=blog\">Grove Ultrasonic Distance Sensor<\/a><\/li><li><a href=\"https:\/\/www.seeedstudio.com\/Grove-I2C-Hub.html\">Grove &#8211; I2C Hub<\/a><\/li><li><a href=\"https:\/\/www.seeedstudio.com\/Grove-RTC-DS1307.html\">Grove -RTC<\/a><\/li><li><a href=\"https:\/\/www.seeedstudio.com\/Grove-OLED-Display-1-12.html\">Grove &#8211; OLED Display 1.12&#8243;<\/a><\/li><\/ul>\n\n\n\n<p>Interested? You can find the full tutorial <a href=\"https:\/\/project.seeedstudio.com\/SeeedStudio\/drinking-reminder-water-bottle-with-allthingstalk-b62cf1\">here<\/a>! <\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Trash Sensor<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/png.pngtree.com\/png-vector\/20190531\/ourlarge\/pngtree-trash-bin-icon-png-image_1252339.jpg\" alt=\"Trash Bin Icon, Clean, Thin, Trash PNG and Vector with Transparent ...\" width=\"231\" height=\"231\"\/><\/figure><\/div>\n\n\n\n<p>Ever wonder how much trash you produce in a week? Want to know how fast you fill up your recycling bin? <\/p>\n\n\n\n<p>With this project, you can track your trash (or recycling) build-up and receive notifications when it needs to be taken out. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">What do you need:<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>Arduino Yun<\/li><li><a href=\"https:\/\/www.seeedstudio.com\/micro-SD-Card-with-Card-Reader-32GB-Class-10-p-4082.html\">Micro SD Card with Card Reader-32GB<\/a> (or any SD card with 4 GB or more)<\/li><li>USB-A to Micro-USB Cable<\/li><li>Jumper Wires<\/li><li><a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html?utm_source=blog&amp;utm_medium=blog\">Grove Ultrasonic Distance Sensor<\/a> <\/li><\/ul>\n\n\n\n<p>Interested? You can find the <a href=\"https:\/\/project.seeedstudio.com\/RChloe\/trash-sensor-18b056\">full tutorial by RChloe on Seeed Project Hub!<\/a><\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Ultrasonic Sensor Home Alarm<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/hackster.imgix.net\/uploads\/cover_image\/file\/100013\/IMG_0115.JPG?auto=compress%2Cformat&amp;w=900&amp;h=675&amp;fit=min\" alt=\"GSM Home Alarm V1.0\" width=\"361\" height=\"270\"\/><figcaption>Ref: <a href=\"https:\/\/project.seeedstudio.com\/Tiobel\/gsm-home-alarm-v1-0-41e4dc\">Hugo Gomes<\/a><\/figcaption><\/figure><\/div>\n\n\n\n<p>Want a security system but they are just too pricey? Why not make one of your own for much cheaper! This project allows you to build an alarm system that will call you if the ultrasonic sensor detects a difference in the distance being measured.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">What do you need:<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>Arduino UNO \/ <a href=\"http:\/\/www.seeedstudio.com\/Seeeduino-V4.2-p-2517.html?utm_source=blog&amp;utm_medium=blog\">Seeeduino V4.2<\/a><\/li><li><a href=\"https:\/\/www.seeedstudio.com\/GPRS-Shield-V3-0.html\">GPRS Shield V3.0<\/a><\/li><li><a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html?utm_source=blog&amp;utm_medium=blog\">Grove Ultrasonic Distance Sensor<\/a>  <\/li><li>Power supply 12V@2A <\/li><li><a href=\"https:\/\/www.seeedstudio.com\/Bread-board-Clear-8-2-x-5-3cm-p-262.html\">Breadboard<\/a><\/li><\/ul>\n\n\n\n<p>Interested in this project? You can check out the full tutorial by <a href=\"https:\/\/project.seeedstudio.com\/Tiobel\/gsm-home-alarm-v1-0-41e4dc\">Hugo Gomes on Seeed Project Hub!<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Summary<\/strong><\/h2>\n\n\n\n<p>I hope the above tutorials have been helpful, if you need any further technical support, you can send an email to techsupport@seeed.cc<\/p>\n\n\n\n<p><a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html?utm_source=blog&amp;utm_medium=blog\">The Grove-Ultrasonic Distance Sensor<\/a> is now in stock now, get one while you can! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>With Arduino ultrasonic sensors like the HC-SR04, you can measure the distance. Through this Arduino<\/p>\n","protected":false},"author":2850,"featured_media":27067,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","_price":"","_stock":"","_tribe_ticket_header":"","_tribe_default_ticket_provider":"","_tribe_ticket_capacity":"0","_ticket_start_date":"","_ticket_end_date":"","_tribe_ticket_show_description":"","_tribe_ticket_show_not_going":false,"_tribe_ticket_use_global_stock":"","_tribe_ticket_global_stock_level":"","_global_stock_mode":"","_global_stock_cap":"","_tribe_rsvp_for_event":"","_tribe_ticket_going_count":"","_tribe_ticket_not_going_count":"","_tribe_tickets_list":"[]","_tribe_ticket_has_attendee_info_fields":false,"iawp_total_views":0,"footnotes":""},"categories":[1],"tags":[2020,1886,733,1884,2019,1807,1889,1911,1888,2397,1113,3205,3204],"class_list":["post-25881","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","tag-arduino-guide","tag-grove-ultrasonic-distance-sensor","tag-grove-sensor","tag-hc-sr04","tag-raspberry-pi-guide","tag-raspberry-pi-zero","tag-receiver","tag-seeeduino-v4-2","tag-transmitter","tag-ultrasonic-proximity-sensor","tag-ultrasonic-sensor","tag-ultrasonic-sensor-project","tag-ultrasonic-sensor-range"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Arduino Ultrasonic Sensor Overview and Tutorials - Latest News from Seeed Studio<\/title>\n<meta name=\"description\" content=\"With Arduino ultrasonic sensors like the HC-SR04, you can measure the distance. Through this Arduino tutorial, you will learn how an Ultrasonic sensor works and how do you use it with the Arduino and even with the Raspberry Pi.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arduino Ultrasonic Sensor Overview and Tutorials - Latest News from Seeed Studio\" \/>\n<meta property=\"og:description\" content=\"With Arduino ultrasonic sensors like the HC-SR04, you can measure the distance. Through this Arduino tutorial, you will learn how an Ultrasonic sensor works and how do you use it with the Arduino and even with the Raspberry Pi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Latest News from Seeed Studio\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-04T09:57:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-05T10:14:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png\" \/>\n\t<meta property=\"og:image:width\" content=\"701\" \/>\n\t<meta property=\"og:image:height\" content=\"352\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Shawn\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shawn\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/\",\"url\":\"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/\",\"name\":\"Arduino Ultrasonic Sensor Overview and Tutorials - Latest News from Seeed Studio\",\"isPartOf\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png\",\"datePublished\":\"2019-11-04T09:57:09+00:00\",\"dateModified\":\"2020-11-05T10:14:49+00:00\",\"author\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/c9b61b761840d544e2d830b0e3bc9fe2\"},\"description\":\"With Arduino ultrasonic sensors like the HC-SR04, you can measure the distance. Through this Arduino tutorial, you will learn how an Ultrasonic sensor works and how do you use it with the Arduino and even with the Raspberry Pi.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/#primaryimage\",\"url\":\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png\",\"contentUrl\":\"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png\",\"width\":701,\"height\":352,\"caption\":\"HC-SR04 Arduino and Raspberry Pi Guide\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.seeedstudio.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Arduino Ultrasonic Sensor Overview and Tutorials\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#website\",\"url\":\"https:\/\/www.seeedstudio.com\/blog\/\",\"name\":\"Latest News from Seeed Studio\",\"description\":\"Emerging IoT, AI and Autonomous Applications on the Edge\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.seeedstudio.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/c9b61b761840d544e2d830b0e3bc9fe2\",\"name\":\"Shawn\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5afdc71205d9d485de69bc4b192294e3?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5afdc71205d9d485de69bc4b192294e3?s=96&r=g\",\"caption\":\"Shawn\"},\"url\":\"https:\/\/www.seeedstudio.com\/blog\/author\/shawn\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Arduino Ultrasonic Sensor Overview and Tutorials - Latest News from Seeed Studio","description":"With Arduino ultrasonic sensors like the HC-SR04, you can measure the distance. Through this Arduino tutorial, you will learn how an Ultrasonic sensor works and how do you use it with the Arduino and even with the Raspberry Pi.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/","og_locale":"en_US","og_type":"article","og_title":"Arduino Ultrasonic Sensor Overview and Tutorials - Latest News from Seeed Studio","og_description":"With Arduino ultrasonic sensors like the HC-SR04, you can measure the distance. Through this Arduino tutorial, you will learn how an Ultrasonic sensor works and how do you use it with the Arduino and even with the Raspberry Pi.","og_url":"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/","og_site_name":"Latest News from Seeed Studio","article_published_time":"2019-11-04T09:57:09+00:00","article_modified_time":"2020-11-05T10:14:49+00:00","og_image":[{"width":701,"height":352,"url":"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png","type":"image\/png"}],"author":"Shawn","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Shawn","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/","url":"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/","name":"Arduino Ultrasonic Sensor Overview and Tutorials - Latest News from Seeed Studio","isPartOf":{"@id":"https:\/\/www.seeedstudio.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/#primaryimage"},"image":{"@id":"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png","datePublished":"2019-11-04T09:57:09+00:00","dateModified":"2020-11-05T10:14:49+00:00","author":{"@id":"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/c9b61b761840d544e2d830b0e3bc9fe2"},"description":"With Arduino ultrasonic sensors like the HC-SR04, you can measure the distance. Through this Arduino tutorial, you will learn how an Ultrasonic sensor works and how do you use it with the Arduino and even with the Raspberry Pi.","breadcrumb":{"@id":"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/#primaryimage","url":"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png","contentUrl":"https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png","width":701,"height":352,"caption":"HC-SR04 Arduino and Raspberry Pi Guide"},{"@type":"BreadcrumbList","@id":"https:\/\/www.seeedstudio.com\/blog\/2019\/11\/04\/hc-sr04-features-arduino-raspberrypi-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.seeedstudio.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Arduino Ultrasonic Sensor Overview and Tutorials"}]},{"@type":"WebSite","@id":"https:\/\/www.seeedstudio.com\/blog\/#website","url":"https:\/\/www.seeedstudio.com\/blog\/","name":"Latest News from Seeed Studio","description":"Emerging IoT, AI and Autonomous Applications on the Edge","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.seeedstudio.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/c9b61b761840d544e2d830b0e3bc9fe2","name":"Shawn","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.seeedstudio.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5afdc71205d9d485de69bc4b192294e3?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5afdc71205d9d485de69bc4b192294e3?s=96&r=g","caption":"Shawn"},"url":"https:\/\/www.seeedstudio.com\/blog\/author\/shawn\/"}]}},"modified_by":"Gigi","views":98025,"featured_image_urls":{"full":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",701,352,false],"thumbnail":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover-80x80.png",80,80,true],"medium":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover-300x151.png",300,151,true],"medium_large":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",640,321,false],"large":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",640,321,false],"1536x1536":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",701,352,false],"2048x2048":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",701,352,false],"visody_icon":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",32,16,false],"magazine-7-slider-full":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",701,352,false],"magazine-7-slider-center":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",701,352,false],"magazine-7-featured":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",701,352,false],"magazine-7-medium":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",701,352,false],"magazine-7-medium-square":["https:\/\/www.seeedstudio.com\/blog\/wp-content\/uploads\/2019\/11\/hcsr04-cover.png",675,339,false]},"author_info":{"display_name":"Shawn","author_link":"https:\/\/www.seeedstudio.com\/blog\/author\/shawn\/"},"category_info":"<a href=\"https:\/\/www.seeedstudio.com\/blog\/category\/news\/\" rel=\"category tag\">News<\/a>","tag_info":"News","comment_count":"0","_links":{"self":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts\/25881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/users\/2850"}],"replies":[{"embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/comments?post=25881"}],"version-history":[{"count":65,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts\/25881\/revisions"}],"predecessor-version":[{"id":72948,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/posts\/25881\/revisions\/72948"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/media\/27067"}],"wp:attachment":[{"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/media?parent=25881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/categories?post=25881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.seeedstudio.com\/blog\/wp-json\/wp\/v2\/tags?post=25881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}