3.3V Mod for Ultrasonic Sensors (prepare HC-SR04 for 3.3V Logic on ESP32/ESP8266, Particle Photon, Etc.)

TL;DR: On the sensor, cut the trace to the Echo pin, then re-connect it using a voltage divider (Echo trace -> 2.7kΩ -> Echo pin -> 4.7kΩ -> GND).

Edit: There has been some debate on whether the ESP8266 is actually 5V tolerant on GPIO inputs. Espressif claims both that it is and that it isn't. Personally, I would only take the risk if I had "leftover" ESP8266s.

If you are anything like me, you have come to know and like the HC-SR04 as the de facto standard for low-cost ultrasonic distance sensing for 5V-based Arduino projects. That's why I have quite a few of them lying around here.

But the world of hobby electronics has been steadily moving from 5V towards 3.3V. The Raspberry Pie and many other boards, like those based on the ESP8266, ESP32 or boards like the Particle Photon, are working with 3.3V logic on their input/output pins.

If we connect the sensor to 5V power and at the same time to 3.3V pins, the Echo pin's output will also be 5V and will most likely destroy the 3.3V pins of our microcontroller board. We could try to connect an as-is HC-SR04 to 3.3V power and will be able to get measurements, but unfortunately, these will often be much less accurate.

The solution is to still connect the sensor to 5V VCC, but to make sure that the Echo signal that reaches the microcontroller only has 3.3V by creating a voltage divider using two resistors. Lucky for us, the HC-SR04's Trigger pin does not need 5V and also the accepts the 3.3V that we get from our microcontroller's pins.

With above description and links, you most likely already have enough information to create a voltage divider as part of your circuit on a breadboard and hook up an ultrasonic sensor correctly.

If you want to learn how to modify one or several HC-SR04s so they are 3.3V-ready as self-contained units, without any extra circuitry, read on below.

Step 1: What You Need

  1. HC-SR04 Ultrasonic Sensor
  2. One 4.7kΩ and one 2.7kΩ resistor (or any combination of resistors in the 1-50kΩ range with R1/(R1+R2) = ca. 0.66)
  3. Soldering equipment
  4. X-Acto knife (or any knife that is similarly sharp and pointy)
  5. Acceptable soldering skills -- or the willingness to destroy a HC-SR04 while trying out something new :)
  6. Optional: magnifying glass, multimeter, oscilloscope, particle collider, ...

Step 2: Find the Trace to the Echo Pin and Cut It

Look closely at the sensor's board (possibly using a magnifying glass) and find the trace which leads to the Echo pin.

Note: Your HC-SR04 might have a different printed circuit board (PCB) layout than the one shown here! The trace might also be on the other side (when a trace ends in a round circle, this is is usually a connection to the opposite side of the PCB).

Optional: Take your multimeter and check that you have identified the correct trace by testing for continuity between the Echo pin and the solder joint where the trace connects to something on the PCB. It should show zero ohms.

Using the knife, cut the trace carefully several times in the same spot. Pay attention not to cut neighboring traces. Then, scrape off the trace until you first see its metal, then see it disappear, and you are sure there's no connection any more.

Note: If you don't completely sever the trace, the Echo pin will still deliver the full 5 volts to your microcontroller's pin.

Optional: With the multimeter, check that you have completely severed the same trace by again testing continuity between the Echo pin and the solder joint where the trace connects to something on the PCB. It should show infinite ohms (if it shows something in the mega-ohms range, that's ok, too).

Step 3: Solder 2.7kΩ Between the Echo Pin and Its Trace's End

If you haven't already, find where the Echo pin's trace (which you severed) directly leads another element, like an IC.

In my example, it is connected to pin 2 of that chip in the middle of the PCB.

Cut and bend the 2.7kΩ resistor's legs to exactly fit between the Echo pin and the other connection.

Then solder the resistor in place (cleaning the parts to solder and applying flux probably won't hurt, either).

Step 4: Solder 4.7kΩ Resistor Between Echo Pin and GND Pin

Cut and bend the 4.7kΩ resistor's legs to fit between the Echo pin and the GND pin (or their solder points on the PCB), and solder them there.

Optional: Use a multimeter to check the resistance between the connections to make sure there are no shorts.

Extremely optional: Hook up the trigger pin to your programmed MCU, don't connect the Echo pin yet, and make sure that the Echo signal is 3.3V and not 5V using your favorite oscilloscope. Okay, I'm 85% kidding on that one. :)

You should now be able to hook up your modified sensor to any 3.3V microcontroller. You still need to power it with 5 volts, but many microcontroller boards (that have a voltage regulator) also accept 5 volts, so this should work out just fine in many projects.

Added bonus: this modded sensor will be backward compatible with 5V projects, because most 5V microcontrollers (like Arduino/ATMEGA) can interpret 3.3V signals the same way as they do 5V.



    • Organization Contest

      Organization Contest
    • Epilog X Contest

      Epilog X Contest
    • Paper Contest

      Paper Contest

    13 Discussions


    27 days ago on Step 4

    Many HC-SR04 units can run fine on either 5.0 volts or 3.3 volts. They are sometimes sold as "HC-SR04+" parts but I never see the "+" printed on the parts. Yours looks like the duel 5/3.3 volt part.

    If you have one of these simply connect the Vcc to 3.3 volts and it will work. But perhaps you get better range with 5 volts? I don't know

    4 replies

    Reply 26 days ago

    PS: To clarify, all of them seem to work with 3.3V, too, but then I found a thread where someone found out about the unreliable measurements on 3.3V and assumed that's true for all of these Sensors. If there are more reliable "+" variants that would be cool indeed!


    Reply 26 days ago

    Thanks! I wasn't aware of there being 3.3/5V variants of the sensor. Didn't find a proper datasheet for mine, which would've helped. ;)


    Question 8 weeks ago on Step 1

    Perhaps my lack of electronics will show but how many watts are the resistor? 0.5w ?

    2 answers

    Answer 26 days ago

    As albertson.chris pointed out, the way I talk about "15mA going through the pin" is misleading. It was my rather clumsy attenpt to explain that you can use resistors of just about any power rating, as the power dissipated is negligible (assuming this pin is connected to a high-impedance uC pin -- short-circuiting it to ground might produce different results (and smells ;) ) of course).


    Answer 7 weeks ago

    I would just use the lowest power rating resistors I have lying around as there will hardly be any current going through the Echo pin.

    I tried to find some more detailed info on the Echo output's maximum allowed current draw and couldn't find any. Even if the sensor's complete power consumption of 15mA were to go through that pin (which it won't), 0.5 W would still be around 20 times of what was needed.


    5 months ago

    Great information! Thanks for sharing your electronics knowledge.

    1 reply

    Reply 27 days ago

    "Even if the sensor's complete power consumption of 15mA were to go through that pin" It does NOT work that way. If you placed a low enough value resistor from echo to ground the unit would draw more than 15ma. You could likely get it to draw 20.

    Try "Ohm's Law". Let's assume the tiny chip's output pin can supply 1 mA (0.001 A) before it burns up. At 5 volts, the resister that draws 1ma is r= 5.0/0.001 Ohms or 5000 ohms. So long as the resistors add up to over 5K you'd not blow the part. But now the HC-SR01 is not long drawing 15ma from the power supply it is drawing 16ma. the 5K load on the output has caused a jump in power consumption.

    So the power consumption of the device has nothing to do with choosing a resister. What if you used a 50-ohm resistor? It would cause the device to consume a total of 115 mA and likely fail to do to some internal heating. The resister is not determined by the power consumption but the other way around, the resister strongly influences the power consumption and therefore you want the value to be hight.

    Your resistors are close the about the best values are given but the reasoning was wrong.

    People were questioning the value. The best answer is to calculate the answer. Answer: You have placed and about, roughly 1mA load of the the chip. That is likely OK

    Now lets computer how many watts Wats is i^2 * r. Assume a 5K resistor and 1ma current: 5000 * 0.001 * 0.001 = 5 milliWatts So any resister you happen to have will work even a 1/8thWatt would be an order of magnitude oversized.

    You have the right answers but the answer was maybe arrived at by a correct guess based on experience. Better to get out an old envelope and check


    7 weeks ago

    Thanks, but i think you dont get 3.3 V, see the picture. Does it work correctly?

    Zajeta slika.PNG
    2 replies

    Reply 7 weeks ago

    PS: And to answer your question: yes, it works great on my ESP! :)


    Reply 7 weeks ago

    You're absolutely right! The two specific resistors I used result in 3.18V (as I wrote, the ideal ratio of R1/(R1+R2) is 0.66, whereas here it's 0.635). But when choosing those specific resistors, I found that the difference of ca 0.12V will not be a problem when using this sensor in any hobby application. After all, the treshold on what voltage is interpreted as high or low is usually 2V or even lower on 3.3V input pins (a difference of roughly 1.3V, so we have some wiggle room).

    There are probably better combinations -- if you find a combination of two commonly available resistors that gives us 3.3B exactly, please post back so others can use it and I will add it to the instructable.