rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Wireless soil moisture sensor

Mon Jul 16, 2018 3:07 am

I need to use 16 soil moisture sensors, eventually going to add humidity and temp sensor. So using wireless would be awesome. Since I need so many sensors using relays would be unrealistic, also they will be used around ballasts so don't want sensors which will get interference from them.

I'm using raspberry pi 3b plus and I already have 25 relays and 2 gpio pins being controlled for watering. The moisture sensors will further automate my system.

The current system is just plug and play relay board's on a python GUI program where I manually input how much to water and have to initiate the cycle.

User avatar
DougieLawson
Posts: 35801
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Wireless soil moisture sensor

Mon Jul 16, 2018 7:36 am

Give each sensor a Wemos (ESP8266) publishing MQTT messages connect those to your WiFi network. Run an MQTT broker on your RPi.

Once you have each sensor publishing data that way you can aggregate it with a python MQTT subscriber program.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

btidey
Posts: 1616
Joined: Sun Feb 17, 2013 6:51 pm

Re: Wireless soil moisture sensor

Mon Jul 16, 2018 8:13 am

Yes. Using esp8266 is a good solution here. It can also be made battery operated with very long battery life by using the deep sleep capability of the ESP8266 so that it wakes up at suitable intervals, takes a measurement and communicates it.

I use it in a pot plant watering system. https://www.instructables.com/id/Batter ... -Watering/

If you are using the capacitive type sensors then they give out 0-3V analog signal. This can be handled by the single ADC channel (1V) of the ESP module via a resistor divider. The ADC is not very accurate on the ESP but is good enough for this type of application.

rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Mon Jul 16, 2018 11:52 am

Damn there is a lot inside the github. I read your code (kinda lol)...

So i know python but not C however I could read the gist of what was happening, so I have several questions before I spend any money. I have not used a esp board before so this all new to me.

1- the esp board, does it have its own gpio pins which power the moisture sensors? So there are zero wires from the pi, the esp just sends packets via WiFi and the pi retrieves?

2- do I have to use C code for the esp like you did or can I use python?

3- can one esp board handle all 16 moisture sensors?

4- is it possible for me to run multiple esp. Boards if I choose to add a lot more sensor in the future?

Sorry about newb questions lol, I really do not wanna spend money multiple times. Honestly, there will be more questions but with these answer I can find examples online and purchase stuff then get hands on. New questions might get answered from me playing with board and code...

The idea for me is , ping the moisture sensor 2 times a day, if threshold is met then water a fixed amount of water to plant which will be done with the pi and relays/counter/solenoids already wired to pi. So really I just need the esp board to send sensor readings 2 times a day and the pi will do the rest.

Final question, any recommendations for soil sensor? I was hoping I could get ones that are around 7-10" long since thesee will be used in bigger plant pots but reading stuff online is hard to judge. Are there any specs I need to follow for sensors which can hook up to esp board? Ex. 3.3v etc

User avatar
DougieLawson
Posts: 35801
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Wireless soil moisture sensor

Mon Jul 16, 2018 12:05 pm

The ESP is like an Arduino with on-board WiFi. It's got pins for 3V3 or 5V (if you get a Wemos variant).

I stuffed some sample code at: https://github.com/DougieLawson/Wemos_Arduino_MQTT a while ago.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Mon Jul 16, 2018 3:03 pm

The esp I found says only 1 analog input, would I have to use breadboard and a chip to use more inputs?

Dougielawson, thanks for link. I will 100% be referring to that after I purchase 1 sensor and a board to learn it.

btidey
Posts: 1616
Joined: Sun Feb 17, 2013 6:51 pm

Re: Wireless soil moisture sensor

Tue Jul 17, 2018 10:21 am

Yes, the ESP8266 has 1 ADC input (and about 9 digital GPIO).

One could add on a I2C multichannel analog chip, but I wouldn't do it that way myself. The modules are so cheap (~UKP 1.50) that I would just use just 1 per sensor. They all communicate back to the central point over wifi. That way you avoid any hassle with wiring. They are small enough that one could package an ESP-12, a small LIPO battery (e.g. 500maH) and the moisture sensor into a self contained package not much bigger than the moisture sensor itself and then just push them into the soil wherever you want. No mucking about with wires and makes re-positioning trivial.

You can run a form of micro-python on the ESP chip, or even Basic. C or C++ is not too scary though and there is a lot of support for Arduino programming on this module. See https://www.esp8266.com/ for a very good support forum on all hardware and programming aspects.

Most of the stuff in my github code is associated with running watering schedules, controlling the pump etc. A version which just did a sleep with occasional wake followed by a MQTT message as suggested would be much simpler. Note that one thing is that the maximum one shot sleep time is about 72 minutes. You could either do reporting more often and sort it out centrally or you could use NTP to get the real time and then check that during each wake up to see if it was time to do a report. My github code uses the NTP approach to arrange its schedule.

Note that it would be easy to add digital humidity and temp sensors into the mix. They are cheap and don't need any extra ADC channels so can just be connected to GPIO / I2C

btidey
Posts: 1616
Joined: Sun Feb 17, 2013 6:51 pm

Re: Wireless soil moisture sensor

Tue Jul 17, 2018 10:37 am

Just answering a couple more of your questions.

The moisture sensors I use can be powered from 3.3 - 5V. Internally they use a LDO regulator. They could just be connected to the 3.3V supply for the ESP module but they do draw about 5mA supply current which would drain a battery powered solution. That is why I chose to power the sensor via a GPIO line which can supply the 5mA current needed. During sleep the GPIO is off and the sensor is powered down. When it wakes up it tuns that GPIO high to power the sensor before taking a reading. That way the overall current for the ESP/Sensor/regulator is about 20uA during sleep and about 80mA for about 3 seconds every wake period. If the sleep is say 1 hour then the average current is about 70uA.

There is no real limit to the number of esp modules you can run. The traffic on the wifi network is trivial as they are sleeping most of the time. The only possible limit would be in the network router but most decent units will have no problem. I currently have about 50 wifi devices

rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Tue Jul 17, 2018 11:41 am

Can you post links to the sensor you use and whatever boards you use for the battery powered solution? I didn't think of running 1 per pot, thought one controllong 8. Your way seems to make sense and be easier. Because it only sleeps for a little while, have you had the corrosion issues I've seen online on the sensor itself? I don't mind changing sensors out once a year if need be as they are cheap.

A big question though, when it awakes from sleep can I get a battery level from the esp8266?

Edit- so I looked up the esp12 which seems to be a small add on for the esp8266? I'm seeing most people using a power cord to power it all, if I were to go this route of 1 per pot than I 100% would need battery powered per unit. Also need battery to last a good while. Finally, can you post link to your github? Wouldn't mind seeing your code you used cause you may be using the sensors exactly how I would be. Sounds as if I could mimick your sensor setup and just apply it to my existing program.

PiGraham
Posts: 3576
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Wireless soil moisture sensor

Tue Jul 17, 2018 12:12 pm


rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Tue Jul 17, 2018 12:15 pm

Funny I was just reading that link for battery consumption lol

btidey
Posts: 1616
Joined: Sun Feb 17, 2013 6:51 pm

Re: Wireless soil moisture sensor

Tue Jul 17, 2018 4:59 pm

rickyh89 wrote:
Tue Jul 17, 2018 11:41 am
Can you post links to the sensor you use and whatever boards you use for the battery powered solution? I didn't think of running 1 per pot, thought one controllong 8. Your way seems to make sense and be easier. Because it only sleeps for a little while, have you had the corrosion issues I've seen online on the sensor itself? I don't mind changing sensors out once a year if need be as they are cheap.

A big question though, when it awakes from sleep can I get a battery level from the esp8266?

Edit- so I looked up the esp12 which seems to be a small add on for the esp8266? I'm seeing most people using a power cord to power it all, if I were to go this route of 1 per pot than I 100% would need battery powered per unit. Also need battery to last a good while. Finally, can you post link to your github? Wouldn't mind seeing your code you used cause you may be using the sensors exactly how I would be. Sounds as if I could mimick your sensor setup and just apply it to my existing program.
I get my moisture sensors from eBay; search for Analog Capacitive Soil Moisture Sensor. You can either get them locally or wait longer and get them cheap from China

I haven't had any corrosion issues so far (not long in use though). As they capacitance types don't rely on an electrode touching the soil then corrosion issues should be less.

I use a 18650 battery as It is also pumping water but I reckon I will get well over a year in use. With just the sensor you should be able to achieve similar with smaller battery.

If you are only taking a moisture reading once or twice per day then it is possible to reduce power consumption further by only activating the wifi once very n sleeps. This allows the module to wake up say once per hour, do a sleep count check and exit in < 300mSec. This could get your average current usage down to less than 30uA.

The ESP8266 is the processor chip containing CPU, wifi, RAM and IO. It is packaged into different modules. Some like NodeMCU come with a built in USB connection and are breadboard friendly for doing software development. It is good to have one of these. They are not so good for deploying in very low power solutions as the extra on board circuitry is drawing extra current.

Getting battery level during wake up really needs the ADC which is also being used to read the moisture sensor. I do use the ADC for battery level in other apps and it works well. As the moisture sensor is being powered from a GPIO it might be possible to mux it with the battery voltage using a few external components.

rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Tue Jul 17, 2018 10:36 pm

hey, so this is the sensor i am going to buy.
https://www.dfrobot.com/product-1385.html

it seems to be almost identical to the ebay one i think you were talking about. These are more money but i cant wait 3 weeks or more from china. As for the battery, i am only going to check the moisture reading 2 times a day and use it for only this one sensor, nothing else. Do you have a battery in mind you think would work ok? i am unsure how to calculate the battery capacity and really do not wanna buy things multiple time to get correct parts as its a decent size system. The watering sensors alone going to cost me around $200.
http://www.dx.com/p/3-7v-1000mah-20c-li ... 05uShgRVwA ... Is this along the lines of what you were talking about?

alright as for the esp8266 , there is an entire family of them. i am assuming i would go with a 12 or 12F. any recommendations? Its only purpose is for one sensor.
They are small enough that one could package an ESP-12, a small LIPO battery (e.g. 500maH) and the moisture sensor into a self contained package not much bigger than the moisture sensor itself and then just push them into the soil wherever you want. No mucking about with wires and makes re-positioning trivial.
The idea of having the sensor connected to a small box with battery and board in it would be awesome.

Thank all of you for helping thus far. i would rather spend my time playing with code then buying an waiting for shipping of wrong parts!

rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Tue Jul 17, 2018 10:47 pm

Just found this, i do not need the LCD screen or any LED lights. I am ok with buying something around $10 range each if its all built together. Obviously i would still need the deep sleep feature for the soil sensors to save battery life. i also do not care about charging them but if this is built in feature i could always buy 1 extra and swap it out when batteries die out.

https://www.ebay.com/i/192565041447?chn=ps

This appears to be the same thing without the LCD

https://www.ebay.com/itm/Mini-WiFi-WeMo ... 0677.m4598

i am beginning to think it would be cheaper to just buy 2 more RPI and put my relay boards on each one. the relay boards have 8 ADC channels on each one. however, the sensors say they cant have longer wires on them cause signal interference would make it inaccurate. so i guess that is out of the question. wifi looks like only route.

btidey
Posts: 1616
Joined: Sun Feb 17, 2013 6:51 pm

Re: Wireless soil moisture sensor

Wed Jul 18, 2018 9:50 am

Those linked items are basically like the development boards I mentioned but with built in battery holder / charger. They are certainly fine for doing development but you won't get the ultimate battery life even when you put use sleep. They will typically draw 0.3 to 0.5mA in sleep due to the extra circuitry like the usb serial interface.

Battery life time in hours is the maH capacity of the battery divided by the average current draw of the circuitry.

So a 2500maH 18650 with a 0.3mA would last around 7500 hours or about 300 days. Might be a bit less due to background loss in the battery over time. Maybe that is OK for you and it is a convenient off the shelf type solution. If I were doing it I would still go for the lower power solution; longer life, lower cost, smaller size, possibly smaller battery. But you have to put extra effort into the hardware side to put it all together.

E.g. ESP-12F 0.03mA solution with 18650 gives 3000 days or with a much smaller 500mAH battery still gives 600 days. Even a 350mAH battery should give over a year. These type of cells are used a lot in things like small quad copters and can be got pretty cheap.

Why not just get a couple of sensors locally and get things working while you wait for the cheaper parts?

rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Wed Jul 18, 2018 3:31 pm

https://www.walmart.com/ip/8-pcs-Univer ... 3=&veh=sem

This is only $9 shipped.

https://www.amazon.com/gp/aw/d/B075H8X7 ... 1BjLRtttVL

That's $12 shipped. X 8 = $96

https://www.amazon.com/gp/aw/d/B075H8X7 ... 1BjLRtttVL

This would be $60 for 8 of them shipped.

So $165 to do 8 pots with PnP hardware (other than my code) I do not mind that.

I think I could only really save on the $12 board esp12f but the savings wouldn't be that great cause I still would have to box each one with a battery and buy a battery holder plus shipping. How do you think the 9800mAh battery will hold up in my application? Getting a year out of a battery is awesome in my use case cause batteries are cheap.

This project is something I see everyday and interact with so I am not in a possition to worry about not being able change a battery.

btidey
Posts: 1616
Joined: Sun Feb 17, 2013 6:51 pm

Re: Wireless soil moisture sensor

Wed Jul 18, 2018 5:52 pm

As I said the integrated module may suit you if you want to keep the hardware effort to a minimum. You would get a usable if not the best battery life and youjust recharge when they run low.

Don't however believe the 9800mAH claim for a 18650 LIPO battery. That is is pure mythology. Look at the reviews. The guy who did a real test got 600mAh. Most quality 18650s are 2500mAH, some expensive premium ones maybe get 3600mAh. Anything above that is pure fakery and could be much worse than a genuine 2500mAh cell. I am surprised Walmart is advertising them.

Just search for 18650 fakes and you will come up with many sites showing the hazards of believing stated capacities. Some cells on eBay have a tiny cell inside and the rest is just filling.

rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Wed Jul 18, 2018 6:11 pm

Wow, thanks! I'm ordering tonight so I'll make sure to do my research on batteries first.

I'm pretty excited to do my code over with everything automated, sucks my GUI is for nothing now as it was set up for manually feeding. However, making an app for IOS for monitoring is going to be fun. If only those chips could check battery life once a day while checking moisture reading.

New program is going to ping moisture sensors 2 times a day, count how many sensors are dry, multiply that times 1,1.5 or 2 gallons. Whichever trial an error works out best. Then fill my drum with water, add nutrients, mix drum, test ph an add if needed, retest ph until in spec, feed and
Then pump remaining water out of my dump tube. Finally, update the monitoring app, save data into DB and send a progress report via text or email or if possible the IOS app could set an alert to the phone when app Is updated.

I'm looking forward to coding it honestly! I love the mind work involved.

Edit - major thanks to you guys for helping with hardware side of things.

btidey
Posts: 1616
Joined: Sun Feb 17, 2013 6:51 pm

Re: Wireless soil moisture sensor

Wed Jul 18, 2018 9:28 pm

Sounds good.

Couple of last remarks before you get stuck in.

Those modules have a 3.2:1 divider between the external pin and the ESP8266 ADC so you can connect moisture sensor output straight in.

The moisture sensors like I use have a fairly high output impedance (~10K) so best read by something with high input resistance. The divider is 220K + 100K so that will not effect the output much.

I assume by 'ping' twice a day you mean the ESP8266 will wake up from sleep twice a day and send in its results. You can't communicate with the ESP8266 while it is sleeping.

Best of luck.

PhatFil
Posts: 1342
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Wireless soil moisture sensor

Wed Jul 18, 2018 10:06 pm

before you spend have you checked out the xaomi plant sensor as employed in this project https://github.com/ThomDietrich/miflora-mqtt-daemon

rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Thu Jul 19, 2018 1:09 am

uhh, i do now lol... just when i think i have it all figured out. Thanks for adding that phatfil, This is most likely the route im going to take. everything i need already built. going to be a learning curve for the code with that though.

PhatFil
Posts: 1342
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Wireless soil moisture sensor

Thu Jul 19, 2018 2:06 am

rickyh89 wrote:
Thu Jul 19, 2018 1:09 am
uhh, i do now lol... just when i think i have it all figured out. Thanks for adding that phatfil, This is most likely the route im going to take. everything i need already built. going to be a learning curve for the code with that though.
for less complicated/sophisticated use of the basic miflora library check out the root miflora project, Thom's project wraps that upto query the sensors for data and publishes it as mqtt and shoehorns it into some home automation formats too.

Ive simply lifted Thoms code prefixed it with a list of mac addresses for my sensors and changed the mqtt topic to a Phils house relevant string ;) NodeRed sits on a Pi0 in the background to respond as needed ;)

iirc the walkthrough has a single apt-get install command which when copied kicked up errors, while 'apt-get install bluetooth' 1st before everything else worked for me.

rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Thu Jul 19, 2018 2:15 pm

Thanks for head's up with install... yeah I'll need use the original libs cause mine won't be a terminal script. I'm making GUI so I'll have to know what is doing what.

It's cool to see that video he had up though because now I know it has all the features I want to use. Most likely very easy to adapt the sensor lib with mqtt and at that point would be straight forward to implement into a GUI.

Edit- I think I should learn node red , it really seems to be used often with RPI. I opened it other day just to see and I had no idea what was going on lol. Python is only language I know.

rickyh89
Posts: 55
Joined: Mon Jun 18, 2018 11:01 pm

Re: Wireless soil moisture sensor

Wed Aug 29, 2018 4:36 pm

PhatFil wrote:
Thu Jul 19, 2018 2:06 am
rickyh89 wrote:
Thu Jul 19, 2018 1:09 am
uhh, i do now lol... just when i think i have it all figured out. Thanks for adding that phatfil, This is most likely the route im going to take. everything i need already built. going to be a learning curve for the code with that though.
for less complicated/sophisticated use of the basic miflora library check out the root miflora project, Thom's project wraps that upto query the sensors for data and publishes it as mqtt and shoehorns it into some home automation formats too.

Ive simply lifted Thoms code prefixed it with a list of mac addresses for my sensors and changed the mqtt topic to a Phils house relevant string ;) NodeRed sits on a Pi0 in the background to respond as needed ;)

iirc the walkthrough has a single apt-get install command which when copied kicked up errors, while 'apt-get install bluetooth' 1st before everything else worked for me.
Finally just got my sensor in, I'm regretting only buying 1 because the 30+ days it took to come in but once I get a good test of it working I'll have to order the other 20 or so... apparently the size of image is too big so I can't show picture.

Either way, I'll most likely start a test script tomorrow for sensor to send message with info and Mqtt and have the pi print out results to terminal, if that goes smooth than this project will be a walk in the park.

PhatFil
Posts: 1342
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Wireless soil moisture sensor

Wed Aug 29, 2018 7:51 pm

Have fun, after instaling Thoms project a couple of times now, my commands differ from the git hub instructions slightly..

#1 do the usual sudo apt-get update etc

Code: Select all

sudo apt-get install bluetooth
sudo apt-get install git python3 python3-pip bluez
sudo git clone https://github.com/ThomDietrich/miflora-mqtt-daemon.git /opt/miflora-mqtt-daemon

cd /opt/miflora-mqtt-daemon
sudo pip3 install -r requirements.txt
this will install the base miflora libs and get you ready to go..
use hcitool to scan for your ble sensors, and note down the mac addy of all the plant sensors,
add them 1 at a time, pull batteries or fariday cage the ones you have processed and got addys for as the macs all start the same and with 4 or more on the screen all labeled 'plant care' - well i get number blind.. you may not..

DO NOT BE TEMPTED TO INSTALL THE PHONE APP AND PAIR THE SENSORS the phone app could easily upgrade the sensor firmware and result in Thoms code failing to correctly communicate with them..

If familiar with python Thoms code should be way less of the black box it is to me, he uses some of the python data structures like dictionaries that i have no clue about..

fwiw i use the sensors with a simple set of node red flows which i would be happy to share (nothing ground breaking they are my first flows..)
My implementation uses Tasmota firmware flashed onto esp8266/5 based sonoff relay controllers. Im using the SV modules as my pumps are all tiny 5v dc jobs, for an even smaller controller footprint you could use the above mentioned wemos d1 boards with their associated dughter/module boards for battery/psu and a relay.. https://github.com/arendst/Sonoff-Tasmota/wiki https://www.itead.cc/sonoff-sv.html

while im not in business with them i am a sonoff fan boy and buying direct from itead/sonoff and selecting basic sf pnp (couriers will charge extra vat and handeling fees etc) your delivery should arrive within 3 weeks generally sooner.. (the sonoff supplied abs boxes predrilled and supplied with cable glands are worth looking at if using small sized boards in a wet environment (cheap sticky back membrane switches in a paper thin ribbon cable make ideal easy button extenders for that rarely needed hard reset and manual overide of the automatic switching..

Return to “Automation, sensing and robotics”