NodeMCU V3 and HC-SR04

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
CiDsTaR
Posts: 3
Joined: Sun Dec 22, 2019 10:14 pm

NodeMCU V3 and HC-SR04

Post by CiDsTaR » Sun Dec 22, 2019 10:54 pm

Hello everyone,

I'm doing some tests with NodeMCU v3 board and HC-SR04.

It's a simple script that boots up, connects to WiFi, reads distance, sends it to a MQTT topic, and goes to deep sleep.

I'm using 18650 LiPos so I use three devices to manage power:
- TP4056 to charge batteries.
- DC booster (https://es.aliexpress.com/item/32807311456.html) to get 5v from LiPo and supply 5v to HC-SR04.
- LDO (MCP1700-3302E) to power the NodeMCU board with a stable 3.3V line.

As HC-SR04 works at 5v, im using a simple voltage divider (1K+2K) to step down Echo signal and don't overcharge any GPIO.
Im using this lib: https://github.com/lemariva/uPySensors/ ... /hcsr04.py

Im having issues with the HC-SR04 board:
- Instead of getting a stable read, I get sometimes a distance and in the next reading the half. For example, If I do 10 readings, 6 are 14cm and 4 are 28cm.
- Cannot get a real value of readings. For example, for a given real distance of ~55cm, I'm getting readings of 14cm and 28cm, but nothing near the real distance.

Can anybody help me?

Regards,
CiDsTaR

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: NodeMCU V3 and HC-SR04

Post by kevinkk525 » Mon Dec 23, 2019 8:13 am

I'm using a similar setup. You can try to use my driver, but you need to strip it of all project specific methods and objects: https://github.com/kevinkk525/pysmartno ... /hcsr04.py

I also have trouble with inconsitent readings and only between 3cm and 80cm the readings were more or less accurate. I do multiple readings, remove the most extreme ones and use an average of the remaining readings. That seems to work acceptable but is of course a bit slow.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

CiDsTaR
Posts: 3
Joined: Sun Dec 22, 2019 10:14 pm

Re: NodeMCU V3 and HC-SR04

Post by CiDsTaR » Tue Dec 24, 2019 5:51 pm

Have you ever given a try to HC-SR04P variant, that is supposed to work @3v?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: NodeMCU V3 and HC-SR04

Post by kevinkk525 » Tue Dec 24, 2019 8:45 pm

No I haven't tried that one yet.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

CiDsTaR
Posts: 3
Joined: Sun Dec 22, 2019 10:14 pm

Re: NodeMCU V3 and HC-SR04

Post by CiDsTaR » Wed Jan 29, 2020 3:19 pm

kevinkk525 wrote:
Tue Dec 24, 2019 8:45 pm
No I haven't tried that one yet.
I just received my HC-SR04P sensors.

Before any further tests, It seems that:
- It uses an IC named "RCWL-1601".
- It works pretty well at 3v. (Be careful with max current if you plan to use any GPIO pin as power source).
- It can be powered with the same 3v source as the ESP8266 (i.e. a Lipo with a LDO regulator).
- I'm getting more accuracy than with a HCSR04 sensor.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: NodeMCU V3 and HC-SR04

Post by kevinkk525 » Wed Jan 29, 2020 3:24 pm

That's good news! Thanks for sharing your findings.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Xanny
Posts: 3
Joined: Mon Feb 03, 2020 3:57 am

Re: NodeMCU V3 and HC-SR04

Post by Xanny » Mon Feb 03, 2020 4:00 am

I've had some issues with the WiFi radio interfering with my sensors, so the steps I've taken is letting the WiFi connect when the board boots up, hit a url that pings me telling me it's active, and then I shut down the WiFi radio, and wait for sensor activation. If the sensor activates, then I have it connect to the WiFi again (it doesn't take long, a couple seconds at the most) and fire off the event via another url. I haven't had any false positives in a long time doing it that way, maybe that could help someone else having any interference issues.

Post Reply