ESP 8266 and HC-SR04

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
popperchris
Normal user
Posts: 12
Joined: 18 Jun 2017, 08:50

ESP 8266 and HC-SR04

#1 Post by popperchris » 18 Jun 2017, 09:00

Good Mornig Forum,

i have ordert an ESP 8266 Borad and an HC-SR 04 Ultraschall Sensor.

This a the Board:
https://www.amazon.de/gp/product/B06Y1L ... UTF8&psc=1

and that the Sensor:
https://www.amazon.de/gp/product/B00W7F ... UTF8&psc=1

Then on the Borad is installed :
GIT version: v2.0.0-dev10

When i connect the Sensor to the Borad and setup a new Device the Distanz Counter is alway 0 or increase


Thanks and Reagrds
Christoph

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: ESP 8266 and HC-SR04

#2 Post by Shardan » 18 Jun 2017, 17:12

Hello,

and welcome on board.

Please see the wiki: https://letscontrolit.com/wiki/index.php/HC-SR04

Simply: The HC-SR04 does not work (or works very unreliable ond only on short distances) with 3,3V.
The sensor must be run on 5V. Please do NOT connect directly to your nodeMCU as the output runs on 5V
and might destroy your chip.

You will need a level shifter like this:
https://www.amazon.de/XCSOURCE-Logische ... el+shifter
or this:
https://de.aliexpress.com/item/IIC-I2C- ... 06565.html

It's no mistake to grab 5 or 10 of them, they are cheap and used often.

I can confirm the ESPEasy 2.0.0DEV10 runs with HC-SR04 as i'm just testing such a circuit for me.

Regards
Shardan
Regards
Shardan

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: ESP 8266 and HC-SR04

#3 Post by toffel969 » 27 Jun 2017, 14:14

popperchris wrote: 18 Jun 2017, 09:00 Good Mornig Forum,

i have ordert an ESP 8266 Borad and an HC-SR 04 Ultraschall Sensor.

This a the Board:
https://www.amazon.de/gp/product/B06Y1L ... UTF8&psc=1

and that the Sensor:
https://www.amazon.de/gp/product/B00W7F ... UTF8&psc=1

Then on the Borad is installed :
GIT version: v2.0.0-dev10

When i connect the Sensor to the Borad and setup a new Device the Distanz Counter is alway 0 or increase


Thanks and Reagrds
Christoph
As Shardan pointed out, the HC-SR 04 definitly works with ESP Easy (I tried it from RC146). The level shifter is indeed needed. The speaker does not power up with 3.3V. It definitly works though, I use it to monitor the water level in my rain water tank
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

popperchris
Normal user
Posts: 12
Joined: 18 Jun 2017, 08:50

Re: ESP 8266 and HC-SR04

#4 Post by popperchris » 06 Jul 2017, 15:42

HI all,

i have orderd the LevelShifter and test it.

It works.

Thanks for Support.

Regards
Christoph

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: ESP 8266 and HC-SR04

#5 Post by Shardan » 06 Jul 2017, 16:46

Anytime :)
Regards
Shardan

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: ESP 8266 and HC-SR04

#6 Post by alabama » 29 Nov 2017, 10:05

Hi community,

please let me use this thread for my questions.
I use a ESP8266-01 together with a HC-SR04. For the first Setup I use a simple voltage divider for connect the echo from the HC-SR04 to the ESP8266-01. For my tests I use something like this
https://www.amazon.de/Steckbrett-Supply ... V+5V+power
for power.
This works fine, but only if I first start the ESP8266-01 without the echo from the HC-SR04 connected and connecting this when the ESP8266-01 is running.

First question: Is this normal?
I want to use this System next summer in my garden and it should start work imediately whithot the need of special sequence of plugging the wires if it's connected to the power.

Now I decided to Change the voltage didider by a https://www.amazon.de/XCSOURCE-Logische ... el+shifter (yes, I bought 5 of them, ;) )
Before I install one of this Logical Level converter into my System I want to try it's functionality. So I do
1. connect the 5V-Pin of the Level converter to the 5V of the power supply
2. connect the 3.3V-Pin of the Level converter to the 3,3V of the power supply
3. connect the GND of both sides to the GND of the power supply
4. measure the voltage on all Pins on the L-side and the H-side without any other connections by use of an oscilloscope

And now I was really astonished: All Pins on the L-side show me 3.3V and all Pins on the H-side Show me 5V, Independent if i connect one of the Pins with someting else. If I connect for example one of the H-side-Pins with 5V nothing changes. I think my soldering is all right, the Status LED shines if I connect the 5V and GND on the H-side, it dont shine if I only connect the 3.3V on the L-side. The same behavior on all 5 devices.

Second question: Is this normal?
I espected that I get only the 3.3V on the pin opposit of that 5V-pin with contact to 5V and all the other Pins are 0V, or I get 5V on the pin opposite to a pin on the L-side with contact wit 3.3V and all the other Pins are 0V.

This parts are really cheap, but I don't contact the Level converter to my ESP88266 and not to my HC-SR04 because I fear that it will be damaged.

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: ESP 8266 and HC-SR04

#7 Post by Shardan » 29 Nov 2017, 11:00

Hello,

let me answer second question first, The level converter.
This is the schematic for a one channel level converter:
.
600px-Level-Converter_Inside.jpg
600px-Level-Converter_Inside.jpg (76.91 KiB) Viewed 10057 times
.
As you can see, input and output have a pull-up resistor to 3.3V / 5V. So with a voltmeter you will see 3.3V on one sinde and 5V on the other, that's OK.
A more detailed description how this circuit works is in the Wiki: https://www.letscontrolit.com/wiki/inde ... _Converter.

The ESP-01 is a somewhat limited module. The availlable GPIO-0 and GPIO-2 both are used to select start modes.
If on boot GPIO-0 is set to low the module starts into flash mode, this is used to flash a new firmware.
With GPIO-2 you can switch to a firmware on SD-Card - very much theoretical as the ESP-01 does not allow connecting one and ESPEasy does not support it.

So if your HC-SR04 pulls low one of these pins at startup, the module won't start into ESPEasy. that's correct.
The voltage divider with the relatively low resistor will always pull the pin low. A 3.3V zener diode might work better.

Anyways this are workarounds that might work or not. The sensor might activate on power-on so you always might run into problems.
Use a WeMos D1 or nodeMCU with more GPIO's and use GPIO 12/13 or 13/14 for example might be best practice here.

A possible workaround i never tried:
If you don't need the serial port, you may switch the serial transmission from ESPEasy off in the advanced settings.
This frees RX/TX and they might be used as GPIO1 / GPIO3. Serial debug is no longer possible then.

Regards
Shardan
Regards
Shardan

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: ESP 8266 and HC-SR04

#8 Post by alabama » 29 Nov 2017, 13:11

Thank you for your patience. I see now that all devices work fine, the only problem is my knowledge. My first and my last steps in the topic of electronics are about 35 years in the past for about 2 years at school. (Of course that is no excuse, with the GPIO0 I would have to know, after all, I only a few days ago the FW flashed.) Now I feel the desire for my smart home to refresh this and expand. I read the wiki about the level converter, but I not really understand that the pullup resistances are already included. And that the ES8266-01 is the really lowest version is also right. But I thought it mus be enough to check the water level inside the rain barrel. It is always the same: If you try first the cheapest one you have to by very often a second one.

So next I'll include the leven divider into my System and check if it work. If everythin ist fine while this winter I can replace the ESP8266 for the real use next summer for the garden Irrigation by some WeMos D1 or nodeMCU - they are really not much more expensive.

EDIT:
Your are right - of cause. I checked it tonight and it works like it should. And because the level converter shows high without any signal it even works direct after start.
Thanks again.

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: ESP 8266 and HC-SR04

#9 Post by riker1 » 23 Apr 2018, 16:04

Hi
did you ever had a problem with wrong readings?
I have often shorter readings in distance ......

thanks

alabama
Normal user
Posts: 90
Joined: 24 Nov 2017, 10:04

Re: ESP 8266 and HC-SR04

#10 Post by alabama » 26 Apr 2018, 16:21

Yes, I do. Up to now I use only two of these devices. And the one mor, the other less - which is changing from time to time - reports sometimes wrong readings. So I think this is not usable for any alarm systems, I think. But I have to say that I use it only in my test eyuipment. Perhaps it will be better if verything is a little bit more professional.

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests