Ultrasonic distance sensor stuck at .01m

yes, i noticed it wants 5v in the specs. but DrZ is using is with just 3.3v as seen here Ultrasonic Sensor for Home Assistant w/ ESPhome + Elegoo Starter Kit - YouTube
so i am just confused atm

I would try with 5v if that’s what your data sheet says. I have had some sensors that work on 3.3v-5v and some that work on 5v only. But the led seems to always light up even if underpowered so it was hard to figure out the first time.
Also just a tidbit I ran into and maybe someone more experienced could elaborate… but I’ve found that if powering with a micro usb then trying to pull power off VCC pin you never actually get 5v due to some of the power protection stuff. I started cutting off the ends of the micro usb and going direct to power rail and then coming off the power rail direct to sensor and VIN GRD (if 5v needed and using a breadboard in that case)

Also, please note that if you power the ultrasonic sensor with 5V you will need a voltage divider on the echo pin to ensure it does not get more than 3.3V.

2 Likes

i dont have any breadboard atm. can i cheat with this new wiring?
nodemcuHC-SR04
D1 → trigger
D2 → echo

to power the sensor, use another microusb cord as you suggested,
micro usbHC-SR04
red 5v → vcc
black ground → g

that should work right?

Can you share the datasheet for the specific model you have? @exxamalte mentions the echo voltage… which he could be correct that it could send too much back to the pin… it’s possible that’s built into it to lower that already… but there are also numerous really bad copycats of these boards that leave out as much as possible

I should also have mentioned that the ESP’s input pins may be 5V tolerant. Either way, time to study the specs.

@tung256 Yes, I’m not sure myself either how many volts it can take offhand… it could also depend specifically what model/devkit version etc … also would you happen to have a volt meter ?

I would suggest getting the datasheet for your specific ultrasonic sensor, your nodemcu… and maybe a volt meter…. I did find a couple websites connecting the 5v ultrasonics direct to esp32 s… but I don’t want to cause you to ruin your board. So would be best to verify whatever you can first

The CEO of Expressif has said that the GPIOs are 5V tolerant. And others have confirmed this:

Note that is not my experience however. I was using 5V logic on a D1 mini board and it refused to boot. Added a voltage divider to the GPIO and all was well. So… :man_shrugging:

1 Like

this is the item i bought: https://www.amazon.com/gp/product/B004U8TOE6/
it says: Power supply :5V DC, quiescent current : <2mA,effectual angle: <15 ranging distance : 2cm~400 cm resolution : 0.3 cm
i do have a volt meter. do you want me to connect up everything again? or just the nodemcu by itself? where to measure voltage?

In the comments for that advertisement someone mentioned that they were sent an SRF05 instead of an SR04. This a more accurate sensor but if I remember correctly needs some adjustment to the ESPHome config. Let me see if I can find the other topic about this, standby…

EDIT: Ok, unfortunately it wasn’t an SRF05. But you still may be able to use some of this advice regarding the timeout if you do indeed have a different sensor than the SR04.

Note this is for an A02YYWM not an SRF05, so you may have to find the timings for your sensor.

The logs were also completely different (no distance at all) so it may not be your issue.

It will easily look like a tl;dr, but the thread we just plateau’d on at the following link might be helpful to you in this. Here it is. You’re not necessarily out in left field with your question, by any means.

i added the timing in and that has no effect
image

same value stuck as before.

let me play with the timing value n see if decreasing or increasing makes any differences

Yeah as I said:

I’m not convinced this is your issue.

Can you tell what part number is written on your sensor?

That’s an SR04. So ignore everything I said.

let me get another distance sensor then.
which one is known to be for sure working? pls send link

The SR04.

seems i got a dud then. let me try this waterproof sensor next https://www.amazon.com/gp/product/B07X5H77T7/

so the next sensor i got works fine out of the box fine. BUT it cant detect anything past 1m. the advertised distance is 4m
is there anything wrong with my esphome code?

sensor:
  - platform: ultrasonic
    trigger_pin: D1
    echo_pin: D2
    name: "Ultrasonic Sensor"

I can’t explain the 1m, but the default timeout is 2 metres: Ultrasonic Distance Sensor — ESPHome, so maybe have a look at defining that parameter to your needs?