|
Post by papa on Jan 26, 2017 19:02:51 GMT
Soil Moisture Sensing End Node
This thread was revised, starting April 15, 2020
Does my garden (or other soil) need watering today? << I have used this hand held soil tester (search here to purchase) to check my three raised garden beds (in growing weather). However, what if I could check via a Soil Moisture Sensing Node that reports to OpenHAB? With additional parts & programming later, it can even help control watering soil that needs it. This thread is a necessary beginning toward this ability. After you finish fulfilling this thread, continue with this UPDATED thread about Irrigation Automation. For test purposes, I adapted the schematic, sketch, & text from here. Then I adapted the code to the computourist end node approach that I use in the choose_nodes sketch. I suggest you start with building just a soil moisture test unit using an 3.3 volt Arduino compatible & a solderless breadboard (see the next post). Then install an RFM69 radio to make it an end node. Below are instructions for building an end node that can be powered by batteries. Parts: One needs a 3.3 volt Arduino compatible, an RFM69 radio, a small solderless breadboard, some resistors (100 ohm & an 0 to 10 kilo ohms potentiometer), some corrosion-resistant probes, some wires to connect things, & maybe some heat shrink tubing & liquid electrical tape. The battery version in a post below requires other parts. Probes need to be long enough to reach plants' root area & rise some from the soil's top. (I first used stainless steel skewers, but they corroded & became erratic after a year or so. In 2020, I switched to two 6 inch sections of coax cable. Strip each end of the cable down to the copper center. Strip a small amount on one end for soldering the connecting wire (24 inches?). Strip 1.5 inches on the cable's other end for inserting into the soil. Drill a hole in the center of two artificial wine corks, just big enough to tightly hold the still insulated part of the coax cable. Tape the two corks side by side. Insert probes into soil until cork bottoms touch the top of the soil.
Update, June 30, 2020: Coax cable's bare copper center does not have much surface so it may not reliably touch the soil nor reliably register moisture. Packing soil around the 2 copper probes seems to help. In the future, I may add another 1.5 or 3 inches of coax to strip for each probe. Then I would fold the stripped wire back upon itself to make 1.5 inches of stripped wire with a now larger surface.
|
|
|
Post by papa on Jan 26, 2017 20:08:07 GMT
Testing a Soil Moisture Sensor, Updated April 16, 2020
<< Here's the schematic to try the soil moisture sensing concept & to experiment with resistor values for the potentiometer. (I tweaked a gardenbot.org schematic.) I suggest you use a small solderless breadboard alongside the Arduino compatible. For now you can wrap bared wire ends around the tops of the two soil probes. Later you can solder the wire connections. voltageFlip_papa.ino (1.18 KB) << Use this sketch ( updated April 16, 2020) with the above schematic to adjust your potentiometer's resistance to achieve a good operating range. On the Serial Monitor, it displays readings from each of the two probes & then an average of those two values. That sketch also is mostly what I adapted into the choose_nodes sketch. In the sketch (below), I lengthened the time between readings (to the TXinterval, the 60 seconds between transmissions), in case one wants to use battery power on this node. This should help prevent electrolysis deposits on the probes. Two digital pins from Arduino are used to flip-flop the voltage (running the current forward, then reverse). This back and forth current helps to cancel out electrolysis. Electrolysis still happens. However the electrolysis-created crust is broken up when the current reverses. So the soil moisture sensor should operate effectively for a longer period of time. Copper corrosion still seems fairly conductive. The 100 ohm resistor is just for current limiting in case the soil moisture sensor becomes shorted. For the potentiometer, try different values. The original said between 57 kilo ohms & 100 kilo ohms, but a 0 - 10 kilo ohm potentiometer worked for me. It depends on your sensor and soil. Change the value of this second resistor/potentiometer to adjust the operating range for this sensor so that your data shows up near the middle range of the total 0-1023 range. Using a voltage-ohm meter to set the potentiometer to 5 kilo ohms worked well as a start for me. Insert the probe legs into a sample pot of your soil to test the sensor. One needs to discover what readings match an ideal range of soil moisture & what's below & above, perhaps by using a hand held moisture tester (like the one mentioned in the first post above) or a "feel" test if one is skilled at that.
If a potentiometer is not adequate, use resistors to get more useful results. Resistors come in a limited variety of sizes, but one can get odd resistor values by fastening them end to end. For example, 10 kilo ohms connected to 47 kilo ohms gives 57 kilo ohms.
Next, Starting a Moisture Sensing Node that Communicates Wirelessly with OpenHAB
|
|
|
Post by papa on Jan 26, 2017 20:52:57 GMT
Starting a Moisture Sensing Node That Communicates Wirelessly to OpenHAB
Important: The following node needs you to have built & programmed an RFM69 Gateway to handle the node's communication with openHAB. ( See this thread.) You will likely be more successful with the following node if, via this thread, you start with a simpler node or at least gather helpful information. << Here's the schematic for wiring the simplest Soil Moisture Sensing End Node (revised April 15, 2020) For resistor 2, use the value that gives the best operating range of readings from dry to moist. Try adjusting a 10 kilo ohm potentiometer, perhaps starting at 5 kilo ohms (determined with a volt-ohm meter.) This end node can probably be built without a shield on top the Arduino compatible. Most wires connect to only one Arduino pin. The one exception: At the junction (J in the schematic), join the wire / resistor attached to D6 AND the wire from A0 AND the wire to the one soil probe. With the right sketch & openHAB configuration, this node could monitor the moisture level in a soil location. As the gardenbot website suggests, in a garden, one might protectively mount the node at the top of a stake. Cut the bottom off a 2 liter plastic bottle & cover the staked node with the altered bottle. Better: a water-resistant project box. In the thread that follows after this one is information on a project box I use.
|
|
|
Post by papa on Jan 26, 2017 20:54:38 GMT
Soil Moisture Sensing End Node, Programming (updated, April 15, 2020)
Go here for the latest choose_nodes sketch that can be customized to program a Soil Moisture Sensing End Node.
Necessary Customization of the Multi-Choice sketch: To program only the soil moisture sensing, UNcomment (remove the starting //) ONLY one feature define so it reads #define SOILMOISTUse a unique NODEID, never less than 05 (The following assumes NODEID 12) Use the same ENCRYPTKEY as you used for the gateway Probably UNcomment DEBUG to show node data on the Arduino IDE Serial Monitor UNcomment only one #define FREQUENCY line which matches your device If your RFM69 radio has an H in its part number, UNcomment the #define IS_RFM69HW line. Using the other defines, you can probably add other functions (like DHT temperature / humidity sensor). Caution: be careful not to use Arduino pins for more than one purpose. Also, with other functions, the node will use more power & not last as long on battery.
|
|
|
Post by papa on Jan 26, 2017 20:56:33 GMT
OpenHAB 2.5.x Configuration, New April 15, 2020 Assumes Install of openHAB, the Embedded MQTT Broker, & MQTT Binding
In PaperUI, progressively click on Inbox...SEARCH FOR THINGS...MQTT Binding...Add Manually...Generic MQTT Thing
Configure the Generic MQTT Thing using the following fields: Name Node12garden [ << This is the RFM69 Node to be accessed.] Thing ID [ openHAB generates ] Location Garden [Thing's location on which tab of PaperUI\Control ] Bridge Selection MQTT Broker - mqtt:systemBroker:embedded-mqtt-broker
To save, click the Thing's check mark in a blue disc.
Go to PaperUI/Configuration/Things & click on Node12garden. To add a new channel, click on the "+" in blue disc.
In the Add Channel Window, fill the fields: Channel type Number Value < choose type according to the item data type we want Channel id Node12Channel67 < derived from the MQTT topic below Label Soil Moist_12 < arbitrary, but create something descriptive
MQTT State Topic: home/rfm_gw/nb/node12/dev67 < where the node sends soil moisture data
Click SAVE at the lower right. ^^ After the above is saved, Soil Moist_12 Node12Channel67 (ready to link to an Item) shows under Node12garden Thing.
|
|
|
Post by papa on Jan 26, 2017 20:56:44 GMT
OpenHAB Configurations for the Soil Moisture Sensing End Node: (Updated April 15, 2020)
In openHAB's conf/items folder, have a Garden.items config file with these two entries:Number SoilMst_12 "Soil Moisture_12 [%s]" <humidity> { channel="mqtt:embedded-mqtt-broker:topic:mything:Node12Channel67" } String SoilM_Data "Soil Moisture_12 [%s]" <humidity>
Go to PaperUI/Configuration/Things/Node12garden.
Click on the blue disc beside the channel Soil Moist_12. Link it to the item SoilMst_12
soilmoist.scale (100 B) << Here is a sample soilmoist.scale file for your openHAB's conf/transform folder. The rule supplied above converts the sensor reading into a level of moisture. For example, a reading between zero & 150 translates to "very dry." From your readings & gauging what they mean in moisture, supply your own values in the soilmoist.scale file. Garden.rules config file (openHAB's conf/rules folder):rule Soil_12_Mst // converts number reading to a "dry" to "wet" description when Item SoilMst_12 changed or Time cron "0 0/1 * * * ?" then var String Mst12 = SoilMst_12.state.toString SoilM_Data.postUpdate(transform("SCALE", "soilmoist.scale", Mst12)) end Garden.sitemap config file entries (openHAB's conf/sitemaps folder): Frame label="Soil Moisture" { Text item=SoilMst_12 Text item=SoilM_Data }
|
|
|
Post by papa on Jan 26, 2017 21:01:17 GMT
<< Schematic to build your own battery version of a Soil Moisture Sensor End Node. ( updated April 15, 2015) See this post that includes " Parts list for a Bare Bones ..." Changes to that ^^ parts list for this project: You won't need the DHT11 sensor or the optional LED & its resistor. If possible, use a setting on a 10 kilo ohm potentiometer. Otherwise if necessary, add a series of resistors so via a combination, you can achieve between 10 kilo ohms to 100 kilo ohms. To program this End Node, see this later post that says "We can use a regular Arduino as a programmer" near the top. Use the same choose_nodes sketch & customization above. Instead of building a bare bones Arduino from scratch, one might use an Anarduino Miniwireless or a lowpower.com Moteino powered by battery. Those devices already have an RFM69 radio installed.
|
|
|
Post by papa on Jan 28, 2017 15:07:29 GMT
A Soil Moisture AND Soil Temperature Sensing Node ??My summary of the gardenbot.org site explanation of this sensor: This resistive type sensor (the most crude) uses two probes to pass current through the soil, and then the resistance is read to get the moisture level. More water makes the soil conduct electricity more easily (less resistance), while dry soil conducts electricity more poorly (more resistance). The circuit is mainly a voltage divider - the soil moisture sensor is one half & the larger resistance [or potentiometer] is the other half. Papa: Dry soil gives the sensor a lower reading & moist soil gives a higher reading. So seems like the sensor's reading (0-1023) actually represents the power that reaches the analog input pin given the soil's resistance.My summary of an issue gardenbot.org raises: A material's resistance changes with temperature. So when the sun beats on the soil and warms the soil, the resistance changes. This will produce a false "dry" read. For this reason, we employ the soil temperature sensor so GardenBot can use that data to warp the soil moisture to remove the false reading. Papa: The gardenbot software does have a SM1multiplier = .3 to "warp" the reading, but its declaration is commented out & the variable is not used later in the sketch. So I analyzed a table of temperature's effect on resistance & created a formula. Looks like at 20 Celsius (68 Fahrenheit), resistance has a multiplying factor of 1 (no correction needed). For each one degree C below 20C, decrease the multiplying factor (1) by .00395. For each one degree C above 20C, increase the multiplying factor (1) by .00395. Sounds like below 20C the sensor's reading reads moister than actual. Above 20C, the sensor would read drier than actual. If the above is correct, here's the formula I use to correct for soil temperature: Get the soil temp in Celsius, from that subtract 20, multiply that result times .00395, add that result to 1 & we get a corrective multiplying factor. Multiply the factor times the sensor's analog input reading from the probes. Below 20C, the factor is less than 1 & will reduce the probe reading (representing less moisture). Above 20C, the factor is more than 1 & will increase the reading (more moisture). Note: we still need to translate corrected sensor readings into what is too dry for plants, adequately moist, & more wet than ideal. Once we experimentally determine those ranges & edit the soilmoist.scale file, the OpenHAB config rule above will handle the translating. For a soil temp sensor, the gardenbot.org site describes a home made waterproofed device made from an LM335 temp sensor. For this purpose, I ordered a Waterproof DS18B20 Temperature Temp Sensor that is ready made with cable & waterproofing. My choose_nodes sketch already has most of the coding needed & I reworked it once I had the DS18B20 sensor. In case a battery is used, we can power the temperature sensor with a Arduino digital pin that we only turn on as needed. An added benefit of this sensor is being able to know when soil temperature is warm enough for seed germination. See the posts below for how to accomplish this.
|
|
|
Post by papa on Feb 8, 2017 0:55:57 GMT
A Soil Moisture AND Soil Temperature Sensing End Node With a Battery Option (Updated April 27, 2020)
This node continues from our efforts above. Before this version, I encourage you to do the above node that senses ONLY soil moisture (either the regular or battery version). That will help get you through the testing & calibrating of the soil moisture sensing. Parts: As for the node version above, one needs a 3.3 volt Arduino compatible, an RFM69 radio, a small solderless breadboard, some resistors (100 ohm & a 0 - 10 kilo ohm potentiometer), some probes that will not be too affected by corrosion (see above how I used sections of coax cable), some wires to connect things, & maybe some heat shrink tubing or liquid electrical tape. The probes need to be long enough to reach plants' root area & rise some from the soil's top. The battery version in a post below requires other parts. << Pics of DS18 Sensor Note how the DS18 sensor wire colors ^^ & the schematic below guide installing the sensor on the node: Data wire is yellow, VCC (power) wire is red, & GND wire is dark (black or blue?).Parts added for this node version: To read soil temperature, this node uses a waterproof DS18 sensor. That sensor needs a physical 4.7 kilo ohm pull up resistor (between the sensors data line & vcc power line) & a coded pull-up in the sketch does not seem to work. See this post about attaching male Dupont connectors to the sensor wires so they can be plugged into the Buono Uno sockets.
|
|
|
Post by papa on Feb 8, 2017 1:05:19 GMT
^^ Here's the schematic for wiring the Soil Moisture & Temperature Sensing End Node. (Updated, April 16, 2020)For resistor 2 (perhaps via a 10 kilo ohm potentiometer), use the value that gives the best operating range of readings. In the schematic, if wires touch, they are wired together. For example, the orange wire leading from A0 is connected to a probe wire at "J" This version of the end node might be built without a shield on top the Arduino compatible. Wires mostly connect to only one Arduino pin. The exceptions: At the junction (J in the schematic), join the wire / resistor attached to D6 AND the wire from A0 AND the wire to the one soil probe. Perhaps like me, you can jam in / connect the leads of the DS18's 4.7 kilo ohm resistor to D5 & D3 or the DS18 sensor's VCC & Data. In the schematic, note that the D5 pin is used to power the DS18 sensor. This will allow us to turn the sensor off to save power. Using some kind of insulating block (wood, plastic ?), mount the two soil probes maybe an inch apart. Leave the soil probe bottoms bare up to the top of the typical plant root level. Use heat shrink tubing or electrical tape to insulate above that root area. Perhaps with colored electrical tape, mark a probe place that should stay flush with the soil's top. As the gardenbot website suggests, in a garden, one might protectively mount the node at the top of a stake. Cut the bottom off a 2 liter plastic bottle & cover the staked node with the altered bottle. Better: a water-resistant project box. In the thread that follows after this one is information on a project box I use.
|
|
|
Post by papa on Feb 8, 2017 1:09:46 GMT
Programming (Updated, April 16, 2020)
Go here for the latest choose_nodes sketch that can be customized to program a Soil Moisture & Temperature Sensing End Node. Necessary Customization of the choose_nodes sketch: To program the soil moisture AND soil temperature sensing ... To choose a temperature scale, UNcomment ONLY one of the two following lines (remove the starting //) & leave the other line commented. // #define FAHR // Fahrenheit // #define CELS // Celsius UNcomment one line so it reads #define DS18 Also UNcomment the line with #define DS18B Leave commented: // #define DS18A
UNcomment one line so it reads #define SOILMOIST Use a unique NODEID not less than 05 (The following assumes NODEID 12) Use the same ENCRYPTKEY as you used for the gateway Probably UNcomment DEBUG to show node data on the Arduino IDE Serial Monitor UNcomment only one line with #define FREQUENCY to match the radio frequency of your device If your RFM69 radio has an H in its part number, UNcomment the line with #define IS_RFM69HW. This version of the choose_nodes sketch uses the soil temperature reading (& a formula) to correct the soil moisture reading. An added benefit of this node is being able to know when soil temperature is warm enough for seed germination. Using other defines early in the sketch, you might add other functions (like DHT temperature / humidity sensor). Caution: be careful not to use Arduino pins for more than one purpose. Also, with other functions, the node will use more power & not last as long on battery. PS The SLEEPY option will sleep the Arduino / radio / Soil Moisture probes / DS18 to use less powerAs is (but changeable), the line with "int Loops = 8" sets 8 Loops of 8 seconds (64 seconds) of sleep before waking to sense & report data. To test the SLEEPY option on a wall-powered node ... UNComment #define SLEEPY
|
|
|
Post by papa on Feb 8, 2017 1:14:19 GMT
^^ Getting results: With a working Gateway 2.4 & a Soil Moisture AND Temperature Sensing End Node (12), you should get Arduino IDE Serial Monitor readings something like the above.
|
|
|
Post by papa on Feb 8, 2017 1:21:39 GMT
Reserved for Troubleshooting the Work Just Above
|
|
|
Post by papa on Mar 24, 2020 21:13:31 GMT
Troubles with Soil Moisture SensorsOriginally, I had constructed moisture sensors from 2 stainless steel skewer lengths stabilized in 2 synthetic wine corks fastened together. These provided stable results for one growing season. In the next season (corrosion ?), they were not so reliable. I tried cleaning them & adjusting the resistors to get useful results. Tinkering in the project boxes was awkward & results still varied. I next tried 3 kinds of capacitive moisture sensors which if protected should not corrode. In my soil, the Adafruit version (STEMMA) worked the best, but all of them swung through wide ranges of values. Even averaging the values did not help. For the last growing season, I gave up on irrigating based on moisture sensors. Knowing how much drip irrigation flows over a unit of time, I used that to provide each bed with a set amount of water. ( See this post for the openHAB rules to do this timed irrigation.) Since the first season of irrigation automation, I've changed from a severely compacting top soil to a homemade potting mix. This may also be affecting my moisture sensor results. Next, An Updated Soil Moisture Sensor
|
|
|
Post by papa on Mar 24, 2020 21:47:32 GMT
About the Updated Soil Moisture SensorIn this above post, I updated the Irrigation Node schematic. The update recommends using a potentiometer for one of the soil probe resistors. I hope this provides an easier means to tweak moisture readings if that becomes necessary. Through some research & experimentation, I believe that copper corrosion conducts better than stainless steel corrosion. Therefore I've built a soil moisture sensor from two 6 inch sections of coax cable. On one end of each section, I stripped a very short length of the insulating cover & braid down to the copper wire center. On the other end of each section, I stripped 1.5 inches of the insulating cover & braid down to the copper wire center. To each section's short end of copper wire, I soldered 24 inches of 22 or 24 gauge insulated wire. I stripped a small length of the other end of the insulated wire which will be inserted into an Arduino shield socket (see schematic). On the solder joint, I generously painted all bare areas (overlapping the remaining coax insulation) with Liquid Tape insulation. Leave bare the 1.5 inches of bare copper wire, but where this wire emerges from the coax insulation, paint generously with Liquid Tape. From top to bottom of a 1.5 inch tall synthetic wine cork, I drilled a hole just big enough (1/4 inch?) to tightly hold the still insulated part of the coax cable. After the Liquid Tape dries, insert each prepared coax section into one of the wine cork holes. The soldered end is at the top. Leave about 1.5 inches above the cork, 1.5 inches inside the cork, & 3 inches below the cork. You want each coax section to fit snugly in the cork. If inserting into the cork is too hard, wiggle the drill bit to enlarge the hole a little. Put the wine corks/coax sections side by side & wrap them together with electrical tape. Into the soil, you will press the longer end of the probes until the cork's bottom rests on the soil's top. I hope that the copper wire & its corrosion will provide reliable results for a good while. The potentiometer (I'm starting at 5 kilo ohms) should allow relatively convenient tweaking of results. If necessary, I've found that soaking copper in vinegar cleans it well.
|
|
|
Post by papa on Apr 20, 2020 20:29:33 GMT
In this UPDATED thread, I document using the above Soil End Node to automate irrigation. Take a look.
|
|