HC-SR04 Ultrasonic sensor

  • Hey all real electronics pros....
    I am getting ready to setup my first HC-SR04 circuit on a breadboard.

    • I will power the HC from my ESP board using 5V
    • The ESP sends signals to the Trigger pin on the HC via code
    • The echo pin on the HC sends a signal to the ESP and is read via code
    • The echo pin output comes as 5V and I will need a voltage divider etc to lower the voltage to 3.3 or less volts so I don't hurt the ESP board.

    Am I correct with these assumptions?

    Code is readily available but I am not seeing what I would expect in the code.
    Before I examined any code I envisioned getting the distance from the sensor in the setup. Then in the loop test the return and get the distance and compare the distance from the setup to the distance captured in the loop. If they varied greatly I would consider that the sensor was triggered. Is this approach not valid?


  • Sounds good.

    Note that if you use HC-SR04+ (with the plus), you can power it with 3.3V and skip the voltage divider.

  • @gbales
    I haven't used this particular sensor, but I am aware that ultrasonic devices can have a significant power surge while they are 'ranging'. I suggest a 330uf or larger capacitor across the 5v and ground leads at the HC-SR04.

  • My pulseIn is apparently timing out as the distance returned is always 0.
    I have been over the circuit, testing the voltages and I am seeing values that would indicate the echo pin is high.
    Could someone offer some additional testing to do. What to look for.
    I could post my code and pic of the circuit if they think that would help.
    I don't really know what to look for other than to see if voltages are present.
    I see voltage at the Trig and echo pin.
    I have 4 sensors and tried all of them with the same result.
    I tried 2 code examples from github. Both gave same results.

  • Hi everyone...

    I have built a circuit for the ESP8266 and ultrasonic sensor.
    First thing I could use some advice on is I have to pull the ground from 3.3V in the circuit in order for the flash to be successful.

    Next...likely related.

    I am having a strange issue with my ESP8266 and ultrasonic sensor circuit.
    The code uploads fine.
    But I am getting this error if my circuit is live. (Just connect the ground)
    I am running this via the 3.3V off the ESP8266 pro.
    Fatal exception (0):
    epc1=0x40100003, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

    This is such a simple circuit and I am using code from the internet and various samples all do the same thing so I feel very confident ruling out the code.

    Can anyone offer some ideas on what I need to check.

  • We can't really say much without seeing the circuit and the code.

  • Ok I am trying to upload an image and getting message that the only allow file type is pdf

  • ![0_1490309139444_IMG_20170323_171504__1490308934_99_198_160_173.jpg](Uploading 100%)

  • Ive tried a similar project with two hcsr04 sensors I could only get one input from the two sensors. It has something to do with not having an rtc.

Log in to reply

Looks like your connection to WEMOS Forum was lost, please wait while we try to reconnect.