Ultrasonic Distance sensor - Error

Hi all
I’m trying to use a AJ-SR04M ultrasonic sensor with a ESP8266 module, but I can’t seem to get it working

After the config is configured and uploaded to the module I get an error where the sensor is not connected and the value returned is “nan”
This sensor works with 3-5V so I believe the 3.3V of the ESP8266 module would be sufficient.
(I’ve tested it with an Arduino on the 3.3V rail with the ping library and worked 100%)

I believe the trigger command is sent as the sensor has a LED on the board itself which lights up if a trigger is “sent” but it seems like no valid value is returned.

The trigger period is set to 1s

However, I’ve observed that if the 3.3V supply to the sensor is removed there is a single value returned and it’s quite accurate, if the 3.3V is supplied to the sensor again the nan value returns.

This got me thinking, do I need to put a pullup or pulldown resistor maybe on the echo line, maybe the pin used is not pulled down to 0v or something like that.

I’m really not sure what causes this weird behavior.

Any help or advice would be greatly appreciated!

Keep on automating!
Cheers

Did you read this one:

Worked for me…

I plugged my AJ-SR04M to the 5V on my D1 Mini and it works.

1 Like

Thank you very much for your reply!
I’ve tried everything, but still can’t get it to work for some reason.

UART Debug gives the following:
[D][uart_debug:114]: >>> 55

But I have no idea what that means.

The 47K resistor is connected and I’ve used the custom sensor data in the eshome directory exactly the same as in your explanation etc.

Any idea what I could try perhaps?

Sorry for the delay.
Try this.

Set the pulse_time to 20us and timeout to 4.0m

Hi,

I copied everything from this video (https://www.youtube.com/watch?v=w02i853taN8) and the sensor worked for me.

Regards,

Richard

1 Like

what pins exactly ? 5v GND D1 D2 ? … what yaml ?

It seems perfect to me, with ESP32 on GPIO17 and GPIO16 without resistor on SR04M. Thank You!