# Automated Moisture Sensor

**URL:** <https://community.sparkfun.com/t/automated-moisture-sensor/37011>\
**Category:** Projects\
**Created:** [June 4, 2019, 11:03pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011 "2019-06-04T23:03:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [June 4, 2019, 11:03pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/1 "2019-06-04T23:03:03Z")

</div>

I’d like to connect a soil moisture sensor to a diaphragm irrigation valve such that the sensor actuates the valve when the moisture level drops below a user-defined threshold. The valve is equipped with a solenoid for actuation. The moisture sensor should be solar-powered, but the valve doesn’t have to be. The sensor and the solenoid should communicate wirelessly.

Initially, I only want to control one valve. Eventually I’d like to control two dozen valves or so. On a long enough timeline, the system would be controlled by a phone and could receive input from other sensors (temperature, pressure, humidity, etc).

Locating the sensor on the website is easy enough. However, can you please help me determine the most optimal models of other hardware that I would need (boards, solar panels, battery backup, etc.)?

Thank you!

---

<div class="post-metadata">

**Author:** ![El\_Duderino](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/el_duderino/32/6367_2.png) [@El\_Duderino](https://community.sparkfun.com/u/El_Duderino)\
**Post date:** [June 5, 2019, 8:14pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/2 "2019-06-05T20:14:13Z")

</div>

Hi evanlavin,

To get started with this project, I would recommend taking a look at our guides for the SparkFun Photon Weather Shield. Specifically, the [[Optional Peripherals](https://learn.sparkfun.com/tutorials/photon-weather-shield-hookup-guide-v11#optional-peripherals) section goes over using the Soil Moisture Sensor with this shield and a [[Particle Photon](https://www.sparkfun.com/products/13774). The [[Particle Docs page](https://docs.particle.io/) will help you familiarize yourself with the Photon and the Particle IDE.

The Photon Weather Shield has some optional power options to add in a battery or solar power source. The [[SparkFun Sunny Buddy](https://www.sparkfun.com/products/12885) will help to efficiently charge an attached battery to keep the project powered up.

On the solenoid end of the circuit, you would need another Photon or other WiFi-connected microcontroller to listen to the sensor data and then trigger a relay to power the solenoid since the digital output of a microcontroller would most likely not be able to power a solenoid on its own. We have quite a few different relays available in our [[relay category](https://www.sparkfun.com/categories/422) if you want to look through that.

I hope this helps you get started with this project. Let us know if you have any follow-up questions about these or another of our products and we would be happy to help as much as we can.]([Relay - SparkFun Electronics](https://www.sparkfun.com/categories/422))]([https://www.sparkfun.com/products/12885](https://www.sparkfun.com/products/12885))]([https://docs.particle.io/](https://docs.particle.io/))]([Particle Photon (Headers) - WRL-13774 - SparkFun Electronics](https://www.sparkfun.com/products/13774))]([Photon Weather Shield Hookup Guide V11 - SparkFun Learn](https://learn.sparkfun.com/tutorials/photon-weather-shield-hookup-guide-v11#optional-peripherals))

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [December 16, 2019, 10:42pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/3 "2019-12-16T22:42:10Z")

</div>

Hi, TS-Mark~

Apologies, I had no idea that you had responded here. Not sure how the notifications work. Thank you for your feedback.

I’ve actually purchased a photon and photon weather shield, and the process of working with particle has been completely unproductive and disappointing. At this point, I’m not interested in utilizing their platform if I can possibly avoid it. If I purchase an Arduino weathershield, can you tell me if it’s possible to combine it with soil moisture and temperature sensors? I don’t see anything on your Arduino weathershield hookup guide, but I’ve had much better luck interfacing with Arduino via Linux in the past (as opposed to zero luck with particle).

Thanks!

Evan

---

<div class="post-metadata">

**Author:** ![El\_Duderino](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/el_duderino/32/6367_2.png) [@El\_Duderino](https://community.sparkfun.com/u/El_Duderino)\
**Post date:** [December 18, 2019, 9:09pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/4 "2019-12-18T21:09:35Z")

</div>

Hi Evan,

Not a problem. You can enable notification settings in your profile for any of your posts or for entire forums or you can click the “Subscribe Topic” button near the top of this page next to the “E-mail”, “Print View” and “Bookmark Topic” buttons if you want e-mail notifications of a reply.

As for attaching a soil moisture sensor and (I assume) a soil temperature sensor to an Arduino with a Weather Shield, you can but will most likely need to use an Arduino with a larger pinout than the Uno since the Weather Shield utilizes all six Analog pins on a standard Uno/Uno clone. What you could do is modify the Weather Shield (assuming you are using an R3 Arduino that has dedicated SDA/SCL pins) to disconnect A4 and A5 from the I2C bus and then use those pins for the inputs from the temp and soil moisture sensors. You can either sever the trace going to those pins from the rest of the Weather Shield’s I2C circuit or you can bend out or not solder pins for A4/A5. For code, I would recommend taking a look at our [[Hookup Guide](https://learn.sparkfun.com/tutorials/soil-moisture-sensor-hookup-guide) for the Soil Moisture sensor. Depending on which temperature probe you choose, there may be example code out there for that as well like this [[DS18B20 Temperature Sensor](https://www.sparkfun.com/products/11050).

I hope this helps!]([Temperature Sensor - Waterproof (DS18B20) - SEN-11050 - SparkFun Electronics](https://www.sparkfun.com/products/11050))]([Soil Moisture Sensor Hookup Guide - SparkFun Learn](https://learn.sparkfun.com/tutorials/soil-moisture-sensor-hookup-guide))

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [December 30, 2019, 7:15pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/5 "2019-12-30T19:15:36Z")

</div>

It seems like something like the Arduino Due would be better. The Due appears to have the same pin pattern as the Uno, so I’m assuming the weather shield would work with the Due as well. Are you able to verify? Thanks!

---

<div class="post-metadata">

**Author:** ![El\_Duderino](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/el_duderino/32/6367_2.png) [@El\_Duderino](https://community.sparkfun.com/u/El_Duderino)\
**Post date:** [December 31, 2019, 7:12pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/6 "2019-12-31T19:12:58Z")

</div>

Hi again Evan,

While the Due has the same pinout as an Uno, it runs on a different processor (SAM vs AVR) so you might run into some compatibility problems with our example code. A quick test did not throw any compile errors when testing with the [[Basic Firmware Example](https://learn.sparkfun.com/tutorials/arduino-weather-shield-hookup-guide-v12#example-firmware---basic) for the Weathe Shield so it will at least compile and upload to the board. You may need to tweak the code a bit, specifically the Wire.begin(); call, but otherwise, the Due will have more than enough pins to add a soil moisture and temperature sensor to your circuit.]([Arduino Weather Shield Hookup Guide V12 - SparkFun Learn](https://learn.sparkfun.com/tutorials/arduino-weather-shield-hookup-guide-v12#example-firmware---basic))

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [March 15, 2020, 10:08pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/7 "2020-03-15T22:08:12Z")

</div>

I’m at a point where I’d like to add wifi to the project. I’ve read a lot about the esp8266. Would you recommend your [[8266 module](https://www.sparkfun.com/products/13678), or would it be simpler to add [[usb](https://www.sparkfun.com/products/12700) and use a [[usb adapter](https://www.sparkfun.com/products/15449)?]([Edimax 2-in-1 Wi-Fi 4 N150 & Bluetooth® 4.2 Nano USB Adapter - WRL-22824 - SparkFun Electronics](https://www.sparkfun.com/products/15449))]([SparkFun USB Type A Female Breakout - BOB-12700 - SparkFun Electronics](https://www.sparkfun.com/products/12700))]([WiFi Module - ESP8266 (4MB Flash) - WRL-17146 - SparkFun Electronics](https://www.sparkfun.com/products/13678))

---

<div class="post-metadata">

**Author:** ![TS-Chris](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/ts-chris/32/6057_2.png) [@TS-Chris](https://community.sparkfun.com/u/TS-Chris)\
**Post date:** [March 16, 2020, 5:54pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/8 "2020-03-16T17:54:10Z")

</div>

It would be much easier to add a ESP8266 module than to try to add a USB enabled WiFi adapter.

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [March 18, 2020, 11:46pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/9 "2020-03-18T23:46:08Z")

</div>

Ordered, thanks! 🙂

Next question: I need to add an LCD display to my weather node. At the moment it just needs to output pre-defined text. Eventually it will need to display sensor output, but for now I’d be happy with Hello World. I’m using an LCD 1602 that I’m nearly certain supports the Hitachi HD44780 driver (I got it in the Elegoo Most Complete Arduino Mega 2560 Starter Kit).

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [March 18, 2020, 11:52pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/10 "2020-03-18T23:52:40Z")

</div>

Ordered, thanks!

Next question: I need to add an LCD display to my weather node. At the moment it just needs to output pre-defined text. Eventually it will need to display sensor output, but for now I’d be happy with Hello World. I’m using an LCD 1602 that I’m nearly certain supports the Hitachi HD44780 driver (I got it in the Elegoo Most Complete Arduino Mega 2560 Starter Kit). Attached is a pic of my code.

 ![LCD_CodeScreenshot.jpg](https://canada1.discourse-cdn.com/sparkfun/original/3X/7/b/7b65fb13f058ceb735d45e1a571d2598ceff1a7e.jpeg)

Nothing mystical. Works fine on its own. Once I combine it with SparkFun’s Weather Shield sketch, which has a soil moisture sensor added and works fine either way, the LCD outputs gibberish. Currently it’s splashing “fff” for like a second on startup. In the past it’s displayed random assortments of question marks and such. The weather shield still works the same. The serial monitor outputs identically with or without the LCD. It’s been suggested that perhaps the issue is how power is distributed in the SF Weather Shield sketch. It’s also occurred to me that perhaps serial.begin or serial.println are interfering with lcd.begin or lcd.println, but I’m new enough to Arduino that I’m not sure. Do you have any suggestions before I spend hours beating my head against it?

---

<div class="post-metadata">

**Author:** ![TS-Brandon](https://avatars.discourse-cdn.com/v4/letter/t/cc9497/32.png) [@TS-Brandon](https://community.sparkfun.com/u/TS-Brandon)\
**Post date:** [March 19, 2020, 4:15pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/11 "2020-03-19T16:15:29Z")

</div>

Hello,

Are you using a LCD screen from the SparkFun product catalog?

Also, I can’t really get a good idea of what is going on within your code from the screenshot. Can you host the file somewhere else like GitHub and link to it?

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [March 19, 2020, 5:40pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/12 "2020-03-19T17:40:23Z")

</div>

I’m using an Elegoo LCD1602 display. It came in their most complete Arduino mega starter kit ( [https://smile.amazon.com/gp/product/B01 … UTF8&psc=1](https://smile.amazon.com/gp/product/B01EWNUUUA/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1) ). I’m looking into GitHub now. Thanks

---

<div class="post-metadata">

**Author:** ![TS-Chris](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/ts-chris/32/6057_2.png) [@TS-Chris](https://community.sparkfun.com/u/TS-Chris)\
**Post date:** [March 19, 2020, 5:51pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/13 "2020-03-19T17:51:47Z")

</div>

Combining code can get tricky and I’m wondering if the different sections of your sketch are conflicting with one another.

Unfortunately we can not offer support for a non SparkFun product, but we may have a LCD that’s easier to use. The LCD you’re using now is a parallel LCD and we carry a serial LCD that only needs 1 wire to communicate. (When in serial mode)

Our [[SerLCD](https://www.sparkfun.com/products/14072) might be easier to implement. You only need to send serially what you want to display.]([https://www.sparkfun.com/products/14072](https://www.sparkfun.com/products/14072))

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [March 19, 2020, 6:22pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/14 "2020-03-19T18:22:19Z")

</div>

You should be able to view the code here: [https://github.com/evanlavin/evanlavin.github.io](https://github.com/evanlavin/evanlavin.github.io)

It seems to be identical to SparkFun’s sample code for your corresponding module except for how the pins are assigned.

The larger sketch including the weather shield code is in there, too, except I commented out the second counter in the void loop.

---

<div class="post-metadata">

**Author:** ![TS-Brandon](https://avatars.discourse-cdn.com/v4/letter/t/cc9497/32.png) [@TS-Brandon](https://community.sparkfun.com/u/TS-Brandon)\
**Post date:** [March 19, 2020, 6:28pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/15 "2020-03-19T18:28:21Z")

</div>

The link you provided doesn’t link to your code unfortunately.

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [March 19, 2020, 6:29pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/16 "2020-03-19T18:29:14Z")

</div>

The code and module I’m using are identical to [[this](https://learn.sparkfun.com/tutorials/basic-character-lcd-hookup-guide) except I’m calling the pins directly as arguments instead of defining them as variables and then calling the variables. I wouldn’t think that would make a difference.]([https://learn.sparkfun.com/tutorials/basic-character-lcd-hookup-guide](https://learn.sparkfun.com/tutorials/basic-character-lcd-hookup-guide))

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [March 19, 2020, 6:30pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/17 "2020-03-19T18:30:07Z")

</div>

Does the link work at all, or is it broken?

---

<div class="post-metadata">

**Author:** ![TS-Brandon](https://avatars.discourse-cdn.com/v4/letter/t/cc9497/32.png) [@TS-Brandon](https://community.sparkfun.com/u/TS-Brandon)\
**Post date:** [March 19, 2020, 6:31pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/18 "2020-03-19T18:31:40Z")

</div>

It gives a 404 error.

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [March 19, 2020, 6:34pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/19 "2020-03-19T18:34:46Z")

</div>

Okay. Can you view the attachment here? It threw me an error message

---

<div class="post-metadata">

**Author:** ![evanlavin](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@evanlavin](https://community.sparkfun.com/u/evanlavin)\
**Post date:** [March 19, 2020, 6:35pm UTC](https://community.sparkfun.com/t/automated-moisture-sensor/37011/20 "2020-03-19T18:35:40Z")

</div>

Seriously, what kinds of files am I allowed to attach here?

[Next page](https://community.sparkfun.com/t/automated-moisture-sensor/37011.md?page=2)
