ESP8266 battery powered with SR04

I need to power a ESP8266 board with a 18650 battery. This is done on Vin pin of the board.

I also need to attach a SR04 distance sensor to the board. However, this sensor requires 5V to work, so I'll connect it on the Vin pin as well.

But when I connect both the battery and the sensor pin the readings are wrong, mostly because the sensor doesn't have enough power.

So my question is what solutions are available?

I was thinking to connect the battery via the USB pin, but I don't know if it helps or worse, it damages something.

That might be terribly wrong. What's the voltage of the 18650?

3.7V, but can reach 4.2V when fully charged.

Thanks! I don't think the SR04 will work at all. Too low voltage. As I don't know everything about the ESP I wonder if the onboard regulator likes such a low voltage.

Actually I have a temperature sensor and a soil moisture sensor and they work fine.

When the board was powered from the PC via USB everything was fine.

You can't compare very different kinds of sensors like that. The SR04 is an ultrasonic I think. It uses more power when sending the sound pulse than any passive sensor like soil moisture...
But, of course, try.

Can You use 2 x 18650 and step down converters giving the correct voltage?

ESP8266 and ESP32 can operate from a single 18650 battery, because it´s minimum required voltage is 3V. In the other hand, you´re right and SR-04 won´t operate.

It will not help you at all, because ESP works in 3.3 level and it will not provide you 5V to feed the sensor. Moreover, if you feed the sensor with 5V, the ECHO channel will return a 5V signal to ESP, which can damage it.

Use a bidirectional level shifter like this one --> Bi-Directional Logic Level Converter Hookup Guide - SparkFun Learn

Applied to what pin? The 3.3 volt pin I can understand, but connecting 3V to Vin?

That seems reasonable. I'm trying to understand it, but I'm sort of a newbie.

Where will the battery be connected and which pins from the board would be connected to the level shifter?
All 3.3V pins are taken by other sensors.

Well, that´s a question that I didn´t do to myself before. I´m using a module like the one below. Maybe it has a level shifter on the board, since it´s also able to recharge the battery.

image

[url]https://www.amazon.com/HiLetgo-Adjustable-DC3-0-30V-DC5-35V-Converter/dp/B00LP2LZ4M[/url]

Level shifters are used for logic signals, not for power.

Quoting: "Maybe it has a level shifter on the board". Maybe is alarming. Posting guesses that are wrong will be taken serious by ignorant members giving them really bad advice.

Need to check the reply #12....

@ runaway_pancake
Yes, of course.

Yes, you´re right and @runaway_pancake suggestion is better.

Can I connect that to VIN pin or it has to be a 3.3V pin?

Because all 3.3V pins are taken.

Use a solder iron or screw blocks. Vin is not an alternative to 3.3V pin

You mean to share a 3.3V pin between two sensors?

I like these modules. They combine charging of the 18650 battery via USB micro connector, protection circuits for the battery and a boost converter that can be set to 5V to power the HCSR04.

The level shifter will still be required on the echo output of the rangefinder to protect the ESP and I do not know if the HCSR04 will trigger from 3.3V.

Yes. Why not? Just make sure that the total current consumption is within limits. That's likely not a problem.