<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://w.electrodragon.com/w/index.php?action=history&amp;feed=atom&amp;title=HC-SR04_Ultrasonic_sensor</id>
	<title>HC-SR04 Ultrasonic sensor - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://w.electrodragon.com/w/index.php?action=history&amp;feed=atom&amp;title=HC-SR04_Ultrasonic_sensor"/>
	<link rel="alternate" type="text/html" href="https://w.electrodragon.com/w/index.php?title=HC-SR04_Ultrasonic_sensor&amp;action=history"/>
	<updated>2026-06-10T07:13:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.2</generator>
	<entry>
		<id>https://w.electrodragon.com/w/index.php?title=HC-SR04_Ultrasonic_sensor&amp;diff=11758&amp;oldid=prev</id>
		<title>Chao at 12:11, 27 November 2016</title>
		<link rel="alternate" type="text/html" href="https://w.electrodragon.com/w/index.php?title=HC-SR04_Ultrasonic_sensor&amp;diff=11758&amp;oldid=prev"/>
		<updated>2016-11-27T12:11:46Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Product Features: ==&lt;br /&gt;
Ultrasonic Ranging Module HC-SR04 provides 2cm-400cm non-contact distance sensing capabilities,Ranging accuracy up to 3mm; module comprises an ultrasonic transmitter, a receiver and a control circuit.&amp;lt;br /&amp;gt;&lt;br /&gt;
Basic operating principle:&amp;lt;br /&amp;gt;&lt;br /&gt;
(1) IO port TRIG trigger ranging to at least 10us high level signal;&amp;lt;br /&amp;gt;&lt;br /&gt;
(2) the module automatically sends eight 40khz square wave, automatically detects whether a signal return;&amp;lt;br /&amp;gt;&lt;br /&gt;
(3) a signal to return to a high output through the IO port ECHO high duration of ultrasound wave from the transmitter to the time of the return. Test distance = (high level time * sound velocity (340M / S)) / 2;&amp;lt;br /&amp;gt;&lt;br /&gt;
== Connection ==&lt;br /&gt;
See the wiring below, VCC for 5V power supply, GND to ground, TRIG trigger control for Signal input, ECHO back Sound for signal output.&lt;br /&gt;
[[File:Ultrasonic_sensor..jpg]]&lt;br /&gt;
== Frequency ==&lt;br /&gt;
[[File:Frequency..jpg]]&amp;lt;br /&amp;gt;&lt;br /&gt;
The above timing diagram that you only need to provide more than a 10uS pulse trigger signal, the module internally issued eight 40kHz cycle level and detect the echo. Once the echo wave signal is detected then output the echo signal. The pulse width of the echo signal is proportional to the measured distance. Thus transmit signals to the received echo signal The time interval can be calculated distance. &amp;lt;br /&amp;gt;&lt;br /&gt;
''Formula: uS/58 = cm or uS/148 = inches; or: Distance = High level time * sound velocity (340M / S) / 2;'' &amp;lt;br /&amp;gt;&lt;br /&gt;
The recommended measurement period more than 60ms, so as to prevent the emission signal influence echo signal.&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Note: This module should not be charged to connect to electrical connections, and then let the GND terminal to connect the module, otherwise it will affect the module working properly.&amp;lt;br /&amp;gt;&lt;br /&gt;
Ranging area of the object is not less than 0.5 square meters and the plane try to be smooth, otherwise the impact of measurement result&lt;br /&gt;
&lt;br /&gt;
== Demo Code - Use A0 and A1 for analog read == &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Arduino&amp;quot;&amp;gt; &lt;br /&gt;
/* Define pins for HC-SR04 ultrasonic sensor */&lt;br /&gt;
&lt;br /&gt;
#define echoPin A1 // Echo Pin = Analog Pin 0&lt;br /&gt;
#define trigPin A0 // Trigger Pin = Analog Pin 1&lt;br /&gt;
&lt;br /&gt;
#define LEDPin 13 // Onboard LED&lt;br /&gt;
&lt;br /&gt;
long duration; // Duration used to calculate distance&lt;br /&gt;
long HR_dist=0; // Calculated Distance&lt;br /&gt;
&lt;br /&gt;
int minimumRange=5; //Minimum Sonar range&lt;br /&gt;
int maximumRange=200; //Maximum Sonar Range&lt;br /&gt;
&lt;br /&gt;
/*--------------------SETUP()------------------------*/&lt;br /&gt;
void setup() {&lt;br /&gt;
 //Begin Serial communication using a 9600 baud rate&lt;br /&gt;
 Serial.begin (9600);&lt;br /&gt;
 &lt;br /&gt;
 //Setup the trigger and Echo pins of the HC-SR04 sensor&lt;br /&gt;
 pinMode(trigPin, OUTPUT);&lt;br /&gt;
 pinMode(echoPin, INPUT);&lt;br /&gt;
 pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*----------------------LOOP()--------------------------*/&lt;br /&gt;
void loop() {&lt;br /&gt;
 getDistance();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/*--------------------getDistance() FUNCTION ---------------*/&lt;br /&gt;
void getDistance(){ &lt;br /&gt;
 &lt;br /&gt;
 /* The following trigPin/echoPin cycle is used to determine the&lt;br /&gt;
 distance of the nearest object by bouncing soundwaves off of it. */ &lt;br /&gt;
 digitalWrite(trigPin, LOW); &lt;br /&gt;
 delayMicroseconds(2); &lt;br /&gt;
&lt;br /&gt;
 digitalWrite(trigPin, HIGH);&lt;br /&gt;
 delayMicroseconds(10); &lt;br /&gt;
 &lt;br /&gt;
 digitalWrite(trigPin, LOW);&lt;br /&gt;
 duration = pulseIn(echoPin, HIGH);&lt;br /&gt;
 &lt;br /&gt;
 //Calculate the distance (in cm) based on the speed of sound.&lt;br /&gt;
 HR_dist = duration/58.2;&lt;br /&gt;
 &lt;br /&gt;
 /*Send the reading from the ultrasonic sensor to the computer */&lt;br /&gt;
 if (HR_dist &amp;gt;= maximumRange || HR_dist &amp;lt;= minimumRange){&lt;br /&gt;
 /* Send a 0 to computer and Turn LED ON to indicate &amp;quot;out of range&amp;quot; */&lt;br /&gt;
 Serial.println(&amp;quot;0&amp;quot;);&lt;br /&gt;
 digitalWrite(LEDPin, HIGH); &lt;br /&gt;
 } else {&lt;br /&gt;
 /* Send the distance to the computer using Serial protocol, and&lt;br /&gt;
 turn LED OFF to indicate successful reading. */&lt;br /&gt;
 Serial.println(HR_dist);&lt;br /&gt;
 digitalWrite(LEDPin, LOW);&lt;br /&gt;
 }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
[[Category: Proximity Sensor]]&lt;/div&gt;</summary>
		<author><name>Chao</name></author>
	</entry>
</feed>