This project shows how to build a self-contained battery operated soil moisture sensor using the Sparkfun Thing and soil moisture probe. The sensor sends perodic status messages letting you know it is working, and alerts when the soil moisture or battery are low. The sensor can be used for monitoring both indoor plants or an outside patio garden.
It uses WIFI, and can select the best WIFI to use from a list of available WIFI. It uses a deep sleep mode to conserve battery power, and uses MOSFETs to expand the use of the single A0 analog pin on the Thing. The software uses Arduino IDE for development and management, and IFTT to send email messages. IFTT is a free service. You can also run multiple sensors on the same IFTTT service.
There are 6 physical components to this project. They are:
- A project box to house the electronics
- A battery to power the electronics
- A daughter board with electronics to expand the use of the single A0 pin
- The Sparkfun Thing computer with WIFI to perform and transmit the measurements
- A sensor board to provide a stable frame for the probe
- A Sparkfun soil moisture probe, mounted to the sensor board, to measure the soil moisture.
Two measurements are taken by the ESP8266 Thing. They are the soil moisture and the battery voltage. Both measurements are analog voltages and are measured by the A0 analog circuit of the ESP8266 Thing. There is only one A0 circuit and it can only measure voltages up to 1 volt.
The measurements, on the other hand, have different and higher voltages. The soil moisture voltage goes up to 3.3 volts, and the battery voltage goes up to 4.2 volts. Each measurement needs a unique voltage divider to reduce their voltage to the 1.0 volt range. Additionally, the 2 different voltage dividers need to be combined to access the single A0 analog circuit, and they cannot interfere with each other.
To do this, the 2 different voltage dividers share a common resistor (R3) which goes to the A0 analog circuit. The voltage dividers also use MOSFET’s to gate the other half of the voltage divider to R3. MOSFET Q1 gates the R1 voltage for the battery voltage to R3, and Q2 gates the R2 voltage for the soil moisture to R3. The MOSFET’s, when switched off, stop the voltage dividers from interfering with each other.
The following are the parts and tools used to build this project:
QTY Description Manufacturer Part Number
- 1 Project box Hammond 1551KBK
- 1 LIPO Battery 1200 mAh Adafruit PID: 258
- 1 Sparkfun Thing Sparkfun WRL-13231
- 1 Soil Moisture Probe Sparkfun SEN-13322
- 2 N-channel MOSFET Fairchild BS270
- 1 Resistor 10K
- 1 Resistor 4.7K
- 1 Resistor 2.2K
- 1 Bakelite Perf Board Adafruit PID: 2670
- 3 feet 22 AWG Hook-up Wire Multiple colors Sparkfun PRT-08022
- 6 Male Break Away pins Sparkfun
- 3 Male Break Away RA pins Sparkfun PRT-00553
- 3 Female Crimp Pins Pololu 1930
- 3 Female Crimp Housing Pololu 1900
- Wire cutters
- Wire strippers
- Solder & Soldering iron
- Dremel
- Large and small files
- Combination square
- Needle nose pliers
Use scissors to cut out the sensor board and the small daughter board. Use the wire cutters to nip out the 2 corners, and the file to straighten all the edges.
The sensor board is 3 inches by 1-3/8 inches. Nip ot the 2 corners for the screw posts inside the project box. The 2 corner cuts are about ¼ by ¼. Cut short, then nip and file for a tight fit.
Test fit the boards. The sensor board needs to be snug or the moisture probe will wiggle. The daughter board needs to fit between the Thing and the inside edge of the box.
The project box has one cut so the moisture probe can extend out. You will need a combination square to measure the cut; masking tape and a pencil to mark the cut, and a Dremel with a cutoff wheel and a 1/8 routing bit to make the cut.
The 2 PCB standoffs at the bottom of the box need to be cut off so the battery can fit properly. Make sure they are cut flush.
The cut location for the probe can be different depending on the battery. So, it is best to measure the cut location with the battery.
Put masking tape on the inside and outside of the box. Put the battery, sensor board, and daughter board in the box (the daughter board simulates the height of the moisture probe). Make sure they all lay flat. Mark the location at the top of the daughter board and then measure that mark from the top of the box with the combination square. This is the TOP of the cut. It should measure about 3/16 inch from the top of the box
Then mark that location on the outside of the box. Add 2/16 to the TOP measurement for the BOTTOM measurement, and mark that on the outside of the box.
Mark the left and right side of the cut on the outside of the box. With the top of the box facing up, place the combination square on the left side. Make a mark 3/16 from the left, and 1-3/16 from the left. The 1-3/16 mark should be at the screw hole post.
Use the Dremel with a 1/8 router bit and make the cut. I recommend using a low speed for better control. Use a small flat file to clean up the edges.
When done, you should be able to fit everything inside the box. That includes the battery, sensor board, sensor (with probe extending out of the box), Thing, and the daughter board. You also need to make sure the pin holes on the sensor line up with the holes on the sensor board. Stick some pins in the sensor holes and make sure they line up with the holes on the sensor board. DO NOT PUNCTURE THE BATTERY.
If the holes do not line up, then trim the side of the sensor board nearest the project box cut and the screw post cutout in very small increments. Use nippers and/or a file. Reposition the sensor board so it touches the side of the box with the cut. Recheck the fit of all component and the alignment of the pins. Repeat this process till the holes line up.
Build Sensor BoardPut the battery, sensor board, moisture sensor, and Thing in the project box. Make sure everything fits, then determine which pin holes to use on the sensor board. Use 3 male break-away right angle pins to secure the sensor to the board. Solder the pins on the backside of the board and the topside of the sensor. Use a female pin to ensure correct spacing between pin and probe while soldering.
The daughter board provides 2 voltage dividers and consists of 2 mosfet's and 3 reststors. Below are the steps to build the daughter board.
Start by adding the 2 MOSFET’s to the board. Bend the MOSFET’s so they lay flat. Note the orientation of the Drain, Gate, and Source legs of the MOSFET
Bend the legs then solder the Gate leg. Note, the gate legs are used as PCB traces so don’t trim them yet.
Cut 2 pieces of white wire about 3 inches each. The wires go through the outermost holes, bend 90 degrees, and touch the hole next to them. Trim the MOSFET legs so the legs and the wire just overlap, then solder the connections. Alligator clips and/or “helping hands” help in the process.
R3 is connected to the ground wire on one side, and the S leg of both MOSFET’s and the A0 wire on the other side.Again, use the legs of the MOSFET’s and the R3 leg as PCB traces. Trim the MOSFET leg and R3 resistor leg so the legs and the wire just overlap
Cut 1 black wire and 1 yellow wire about 3 inches each. The black wire is for ground and the yellow is for the A0 analog circuit. The wires go through the outermost holes, bend 90 degrees, and touch the hole next to them. Solder the connections. Alligator clips and/or “helping hands” help in the process.
R2 is connected to the Drain leg of Q2 on one side, and the wire going to the signal pin of the soil moisture Probe on the other side. Note the hole orientation of R2 to Q2.
Cut 1 red wire about 3 inches long. The wire goes through the outermost holes, bends 90 degrees, and touches the hole next to it. The Drain leg bends towards Q1 and touches the leg of R2. Solder the connections and trim the excess off the R2 legs. Alligator clips and/or “helping hands” help in the process.
R1 is connected to the Drain leg of Q1 on one side, and the wire going to VIN on the ESP8266 Thing. Note the hole orientation of R1 where it uses the same hole as Q1.
Cut 1 red wire about 3 inches long. The wire goes through the outermost holes, bends 90 degrees, and touches the hole next to it. One leg of R1 goes in the same hole as the D leg of Q1, and the VIN wire touches the other leg of R1. Solder the connections and trim the excess off the R1 legs. Alligator clips and/or “helping hands” help in the process
The daughter board is now complete.
Wire ESP8266 ThingTo wire the Thing you will need the Thing, daughter board, male breakaway pins, assorted wire, female crimp pins and shells, soldering iron and solder, strippers, wire cutters, and needle nose plyers.
First, solder 6 breakaway male pins to the Thing. They go on DTR, TX0, RXI, 3V3, NC, GND, and are used for programming the Thing and deep sleep. After soldering the pins, remove the plastic holders and bend the pins to a 45-degree angle. This is needed so the Thing, with pins, will fit in the box.
Next, cut 3 pieces of wire about 2 ½ inches. Use the needle nose plyers to crimp the female crimps onto the wire, then add the shells. My wires are color coded red=power, black=ground, yellow=signal (for deep sleep).
Fit, trim, and solder the wires to the Thing. The yellow wire is used for deep sleep. The yellow female pin goes on the DTR male pin, and then to XPD hole on the Thing. Leave some slack to you can pull the female pin off the DTR (when you program the Thing). The red and black wires will go to the moisture sensor. The red goes to GPIO4 (which will supply the power) and the black goes to ground. Note the location of this ground as the other ground is used by the daughter board.
Begin soldering the wires of the daughter board to the Thing. Start by fitting, trimming, and soldering the black ground wire and the yellow ADC wire. Make it snug. When finished, make sure the Thing and the daughter board fit in the box.
Next, solder the red VIN and the 2 white GPIO wires. Q1 wire goes to GPIO13, and Q2 wire goes to GPIO12.
Next, trim the last red wire to size. It goes to the soil moisture sensor. Add a female crimp and shell. All the wiring is complete and should look like this picture. Also, test fit the whole assembly to make sure it fits in the box.
Lastly, cut the PWR LED to extend the battery life
These instructions assume that you have basic Arduino IDE skills and know how to download and run programs on the Thing. However, I would like to share my methods of downloading and running programs. Basically, I use a 6-pin header to download programs, and a 5 pin header to run programs (because DTE cannot be connected when running the Arduino IDE Serial Monitor). The 5-pin header is actually a 6 pin header with 1 pin nibbled off with wire cutters. Here are examples of using the headers:
Both the EEPROM and WIFICLIENTSECURE should be included with your Arduino IDE. You will also need to download the following libraries and programs:
- Arduino-ifttt-maker-master https://github.com/witnessmenow/arduino-ifttt-maker
- Arduinojson-master https://github.com/bblanchon/ArduinoJson
- Soil moisture program from here
The first test is used to check out the daughter board. The first test does not use WIFI or IFTTT. Bring up the soil moisture program and make sure the TESTMODE is set to 2 and DEBUG to 1. Setup the cable for “download” and download the code to the Thing. Power off the Thing, setup the cable for “run”, start the IDE Serial Monitor, and power on the Thing. The Serial Monitor will display soil moisture and battery voltage once every 3 seconds.
Now is a good time to make any adjustments to moisture and/or voltage calculations. Also, adjust sleep settings for measuring and sending status message. And, don't forget to update low moisture and low voltage trigger levels.
Second TestThe second test does use WIFI and IFTTT. However, it only forces a status message every minute. Use this test to ensure you get an email from IFTTT. Bring up the soil moisture program and make sure the TESTMODE is set to 1 and DEBUG to 1. Setup the cable for “download” and download the code to the Thing. Power off the Thing, setup the cable for “run”, start the IDE Serial Monitor, ensure there is a jumper between XPD and DTR, and power on the Thing. The Serial Monitor will display soil moisture and battery voltage once every 60 seconds. You should also get an email from IFTTT containing a status message.
Operational ModeIf the first and second tests are okay its time to go operational. Bring up the soil moisture program and make sure the TESTMODE is set to 0 and DEBUG to 0. Setup the cable for “download” and download the code to the Thing. The soil moisture probe is ready to go into a pot.
If you want, you can force a status message to ensure everything is working before you button up the probe. Make sure power is off, jumper pin 5 to ground, turn on power, remove the jumper within 5 seconds. You should get an email from IFTTT with a status message within a minute. If you get the email, button up the probe. You are done.
Comments