<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Why does my HCR04 ultrasonic sensor give randome readings? - Programming				            </title>
            <link>https://forum.etechnophiles.com/arduino-programming/why-does-my-hcr04-ultrasonic-sensor-give-randome-readings/</link>
            <description>Hi,
Welcome to the eTechnophiles forum. 
Got a question like, \&#039;What resistor value to choose for your simple LED project\&#039; OR \&#039;Where is the resistor connected to the inbuilt LED in Arduino UNO\&#039;s schematic\&#039; - All will be answered here. 
Feel free to check out the topics below.</description>
            <language>en-US</language>
            <lastBuildDate>Sun, 13 Sep 2026 02:51:44 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>Answer to: Why does my HCR04 ultrasonic sensor give randome readings?</title>
                        <link>https://forum.etechnophiles.com/arduino-programming/why-does-my-hcr04-ultrasonic-sensor-give-randome-readings/#post-481</link>
                        <pubDate>Wed, 18 Jun 2025 05:29:37 +0000</pubDate>
                        <description><![CDATA[Before checking the sensor deeply, you should first check the power supply, as the sensor is sensitive to power supply stability. If you&#039;re powering it from an unstable source (like USB powe...]]></description>
                        <content:encoded><![CDATA[<p data-start="361" data-end="562">Before checking the sensor deeply, you should first check the power supply, as the sensor is sensitive to power supply stability. If you're powering it from an unstable source (like USB power or a breadboard with poor connections), voltage fluctuations can cause erratic readings. </p>
To reduce power instability:<br /><br />      1. Place a 100µF capacitor (electrolytic) directly across the VCC and GND pins of the HC-SR04 sensor.<br /><br />      2. This capacitor acts like a small energy reservoir, providing extra current during those brief spikes in demand, thus smoothing out voltage dips.<br />]]></content:encoded>
						                            <category domain="https://forum.etechnophiles.com/arduino-programming/">Programming</category>                        <dc:creator>Paul</dc:creator>
                        <guid isPermaLink="true">https://forum.etechnophiles.com/arduino-programming/why-does-my-hcr04-ultrasonic-sensor-give-randome-readings/#post-481</guid>
                    </item>
				                    <item>
                        <title>Why does my HCR04 ultrasonic sensor give randome readings?</title>
                        <link>https://forum.etechnophiles.com/arduino-programming/why-does-my-hcr04-ultrasonic-sensor-give-randome-readings/#post-420</link>
                        <pubDate>Thu, 03 Apr 2025 07:33:26 +0000</pubDate>
                        <description><![CDATA[I&#039;m using an HC-SR04 ultrasonic sensor with my Arduino to measure distance, but I&#039;m getting inconsistent readings. Sometimes it works fine, but other times the values jump around randomly, e...]]></description>
                        <content:encoded><![CDATA[<p>I'm using an HC-SR04 ultrasonic sensor with my Arduino to measure distance, but I'm getting inconsistent readings. Sometimes it works fine, but other times the values jump around randomly, even when there's no object moving.</p>
<p><br />Here's my code:</p>
<pre contenteditable="false">const int trigPin = 7;
const int echoPin = 6;

void setup() {
    Serial.begin(9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
}

void loop() {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);

    long duration = pulseIn(echoPin, HIGH);
    int distance = duration * 0.034 / 2;

    Serial.println(distance);
    delay(500);
}
</pre>
<p><strong>The issues I am facing:</strong></p>
<ul>
<li>The sensor sometimes returns very high or very low values randomly.</li>
<li>The readings are unstable even when there’s a fixed object in front of it.</li>
<li>Sometimes I even get 0 cm, even though there’s no obstacle that close.</li>
</ul>
<p> </p>]]></content:encoded>
						                            <category domain="https://forum.etechnophiles.com/arduino-programming/">Programming</category>                        <dc:creator>Jignesh</dc:creator>
                        <guid isPermaLink="true">https://forum.etechnophiles.com/arduino-programming/why-does-my-hcr04-ultrasonic-sensor-give-randome-readings/#post-420</guid>
                    </item>
							        </channel>
        </rss>
		