Water level sensor powered by solar

I’ve almost finished building my a water level sensor for a water butt powered with a solar panel/18650 battery, and using the HC-SR04 sensor with a D1 mini.

I seem to have hit a problem where the ultrasonic sensor is returning a distance of 0.01m regardless of what i put in front of the sensor. If i plug it directly into a 5v/1amp USB plug, it starts reporting correctly.

Measuring the voltage being delivered from the 18650 to the d1 mini/HC-SR04 is currently around 2.95v, and the data sheets suggest that it needs 3.3v, so i’m guessing the low voltage is causing it to report incorrectly rather than not report at all.

My 2nd question, my solar panel is connected to a tp4056 and wired to a single 18650 battery. Which in turn is then connected to a LDO to cap the voltage to 3.3v being delivered to the d1 mini. The 18650 should get charged to 4.7v (which i’ve never seen it do, even on a full day of sun). Can i wire two 18650 batteries to a single tp4056 in parallel and would that sustain delivery of 3.3v (assuming the batteries are reasonably charged).

Well, 2.95V means pretty much empty battery, you should avoid that if you want to have a long life for the cell.
Second: 4.7V is WAY to much for 18650 cell. 4.3V is a reasonable maximum, 4,2 is even better (=longer life). Your best option is to use dedicated lithium charge/discharge circuit. You can also use step-up converter to 5V if 3.3V is too low.
Do you plane to use sleep function for D1 mini? Constant use will drain one small cell pretty quick…

Thanks for responding Pavel.

Looking at the guide I followed, it does say max 4.2v (not sure where I got 4.7 from). The dedicated lithium charge/discharge circuit - I believe this is essentially what the tp4056 does. (it prevents over charge, and also cuts off when battery voltage is too low).

A step-up may be useful, although this should all work fine with 3.3v.

Im suspecting my issues are either the 18650 batteries are duff. Or a single cell isn’t enough to power the d1 mini and ultrasonic sensor. So I’d be interested to know if I could wire another 18650 in parallel.

I will look at setting up deep sleep on the d1 mini once I can get it all working.

The datasheet pointed to by the esphome page says the ultrasonic is a 5v device. https://www.electroschematics.com/wp-content/uploads/2013/07/HC-SR04-datasheet-version-2.pdf

Sparkfun agrees Ultrasonic Distance Sensor - HC-SR04 - SEN-15569 - SparkFun Electronics

Yeah, i believe that this device is indeed 5V one. The problem at 3.3V can be uncompatible MCU or too low power for US sensors.
I played a bit with it when i made my heating oil measuring device years ago. It does have some flaws: signal tends to bounce from walls of the tank, so occasionally i’ve got some strange readings, like at given time level was like 500L higher,then it dropped again… I had to put an appr. 5cm long round tubes on sensors to “direct” sound only towards liquid to get permanent useable results.

However, you should also know a couple of things, like:

  • this device is highly dependant on temperature change, so temperature measurement and recalculation of level is essential for precision. Which is logical - sound speed is temperature dependant.
  • when using with water, i guess device will “rust” pretty quickly. After all, it’s not protected in any way, so humidity will eventually destroy it… I’ve had it above oil tank appr. 6 months and whole device was covered with thin oil film…
    At the end i decided to use professional level meter (1m long sensor rod) with RS485 output (was pretty expensive, around 250€). But at that time i didn’t have HA yet, all is connected on AVR controller, so now if i decide to connect whole thing to HA i’d have to make some kind of adapter circuit.

Thanks both, i did look back at the HC-SR04 i purchased and can see it does state 5v required - it seems i purchased the wrong one, as someone else had recommended a specific version the HC-SR04+ that can work at 3v (HC-SR04+ Low-Voltage UltraSonic Distance Sensor – 4tronix).

I’ve ordered one of those and will see if that can make a difference.

I’ve also found a potential other problem. Whilst the solar panels i’ve got can output ~4-5 volts, the current provided by these panels is woefully low - in bright sunlight yesterday it was giving off 0.05mA. So either my multimeter is duff, or the cheap Chinese panels i’ve bought are duff. Either way if that is accurate, then that won’t provide enough current to charge the 18650.

Thanks for the hints, once it’s fully working i’ll have a play around with placement etc to get best accuracy. Regarding longevity of the device, thankfully they’re very cheap and modular. So if it needs replacing once a year, then that’s not too bad.

Solar panel should be pretty big to be able to charge battery, preferrable in one day from zero to full. Also - bear in mind that sometimes it can be cloudy for days - in such condition cell outputs very low current (if any at all), so battery must be big enough (or consumption small enough) to last for days (not only one day).

That makes no sense unless we know what load is being fed.

Ah right, so you’re saying the panels will only give off a low current unless there’s something connected to them? They weren’t connected to the tp4056 at the time i measured the current - it did occur to me that perhaps the panels weren’t charging up the 18650 sufficiently, so thought i’d have a quick check what current it was providing.

You don’t want to use a tp4056 if your power source for charging the 18650 is solar. The tp4056 is expecting a steady power input which solar won’t provide, as a result it frequently resets and overall charging speed is badly affected.

Adafruit sells a similar charger based on a TI bq24074 which works much better for solar sources. Check out the description and links to the tech breakdown here: Adafruit Universal USB / DC / Solar Lithium Ion/Polymer charger [bq24074] : ID 4755 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits

I use the above with my 18650+solar sensors. You can put a small booster on the output, which is regulated, if you need 5v, etc.

Another thing I like about it is it has pins for an optional thermistor you can tape to the battery for temperature control - it’ll shut off charging if the battery gets too warm. If your sensor is outdoors/remote location this is a must in my opinion.

2 Likes

Maybe you could use a 3V ToF sensor if you like as an alternative? I don’t know how It would perform compared to ultrasonic. It is smaller.