Developers, Technology Evangelists, Bros.

Building an IoT Farm Monitoring Solution

Over the last 3 months, I’ve been busy building an IoT weather station for my father-in-law’s farm, Locust Hill Farm. We have always been fascinated by weather, and love watching storms. After acquiring the farm around 2009, we always wondered what the weather was like out there. It only takes about 30 minutes to drive out to the farm, but it would be nice to know if the crops needed water, what the temperature was, and how much rainfall there was.

After I finished writing The NativeScript Book, I had some time to dedicate to building a proper weather station for the farm. In this post, I’ll walk you through the various components of the weather station, how I approached the build, considerations I made along the way, and a variety of lessons learned. I’ll also provide an overview of the technical implementation: a Particle Electron, Azure IoT Hub, Azure Functions, and a mobile app written in NativeScript.

NativeScript Ambassador Program

In addition to our family’s interest in weather, my participation in the NativeScript Ambassador program forced me to start and finish this project.

The goal of the NativeScript Ambassador program is to bring a new group of developers up-to-speed with NativeScript, an open source framework for building truly native mobile apps
with Angular, TypeScript or JavaScript. I participated as a mentor, and felt compelled to build my own project. I’l share more about the mobile app in another post.

About Locust Hill Farm

Locust Hill Farm is a 238-acre farm located in La Grange, KY. My wife’s family bought it 2009, and was used to grow tobacco. We didn’t want to support the growth and sale of tobacco, so in 2010, we contracted with a tenant farmer to grow corn and soybean.

We have spent a lot of time on the farm since 2009, and the land is beautiful and filled with life: a small stream runs through the center of the property, a large beaver dam, several ponds stocked with fish, two old tobacco barns, and a large hill and plateau that overlooks the entire property.

It takes about 30 minutes to get there from our house, so it isn’t too far away, but far enough that we don’t stop in casually.

Weather Monitoring

One of our challenges at the farm is knowing the current and historical weather conditions. For the past year, I had been looking for a fun side project, and after almost 10 years of wondering about the weather, I knew I needed to build a weather monitoring station.

Before deciding on how I was going to collect weather data at the farm, I had a few obstacles to overcome.

First, we have limited electricity at the farm. The only power in inside a barn. Placing a weather station inside of the barn isn’t a good option, and I didn’t want to run an all-weather extension cord out to a field – I can see a tractor tearing apart the wire in the spring. So, I knew I needed to build a station that ran off of a battery and/or solar.

Second, we have no internet at the farm. There’s pretty good cellular coverage, but no wired internet. So, the solution needed to involve some sort of cellular data connection.

Third is durability. Let’s face it – being outdoors in the elements is hard on electronics. Whatever I put together should be weather-proof.

The Solution

After some research, I decided to base my weather station on top of the Particle platform. Particle is a low-price IoT hardware and software platform.

For as little as $19, you can purchase a small hardware device with built-in WiFi, cloud connectivity, and a web-based IDE environment. I had used a Particle Photon (the WiFi hardware module) previously, so I felt comfortable with the platform. But, for this project, I needed something with cellular capabilities, so I bought a Particle Electron.


The Particle Electon is based on the same microcontroller as the Photon, but is also cellular-connected. It comes with a SIM card, cellular data plan, supports 2G and 3G networks, and is compatible with many global cellular providers. When I activated my Electron, data plans started at $2.99/month for up to 2 MB of data per month. Each additional MB of data was $0.99.

In addition to the Particle Electron, I decided to use the SparkFun Photon Weather Shield.

The SparkFun Photon Weather Shield is a great add-on board that includes on-board sensors for temperature, barometric pressure, and relative humidity. It also has connections for a Weather Meter, SparkFun Soil Moisture Sensor, and a Waterproof Temperature Sensor. The weather shield was the perfect addition to my project because of all these features. At first I was worried that it may not work because it was designed specifically for the Particle Photon. The Electron has more pins and is longer, but after testing, I found the Electron fit on to the weather shield. Even though several pins hung over the edge of the weather shield connector, it wasn’t an issue because the pins of the Photon is the same as the Electron (for the pins used by the weather shield),


I needed to ensure the electronics of my solution were weatherproof, protected from the sun, wind, and rain. I decided to start with a SparkFun Big Red Box Enclosure. This enclosure is great because there’s enough room inside for a variety of components, and it’s waterproof. You’ll notice I said “start with” this enclosure because it does a great job of keeping everything inside dry. But, that’s also the problem: it’s a sealed box.

I wanted to incorporate the various sensors (weather meter, soil temperature, soil moisture, etc.), so I needed a waterproof way of running the cables through the box. After a little searching online, I found a good combination of cable glands and weatherproof quick-disconnecting cables at Adafruit.


With the cable glands, I could drill holes into the side of the Big Red Box and thread the quick-disconnect cables through. Once tightened, the entire system would be weatherproof. The quick-disconnects also had an extra benefit of allowing me to disconnect the external sensors and electrical components. I didn’t need to use the quick-disconnects, but it felt like the right thing to do so I could easily transport, setup, tear down, and troubleshoot. In the end, I’m glad I spent the time and money to use the quick-disconnects.

The last thing I used for weatherproofing was a combination of heat shrink and liquid electrical tape.


I used the heat shrink as the first layer of weatherproofing all of my cable joints. So, whenever I connected an electrical component to the quick-disconnects (inside and out), I wrapped it in heat shrink. After the heat shrink was applied, I used several coats of liquid electrical tape to completely seal wires.

Powering the Solution

The Particle Electron comes equipped with a 3.7VDC 2000mAh LiPo battery (see the datasheet for more info), and it has a built-in capability to charge the battery when excess power is supplied to the Electron. I wanted to use the battery and the charging feature because it just worked, so I sought out a solar panel that output the right amount of electricity to power and charge the Electron with a limited amount of sunlight. At peak, the Electron can consume between 800mA to 1800mA, but on average 180mA. It’s recommended to power the the Electron with a power supply that’s rated between 3.3VDC and 12VDC, but you shouldn’t exceed more than 10W, so I needed to find the right solar panel that balanced the Electron’s maximum and some minimums to power and charge the Electron.

SparkFun offers a 6W solar panel that fit the right profile while not costing too much money. The 6W panel outputs 6V and 1025mA at peak capacity, so I didn’t need to to worry about overloading my Electron.

After some testing, I found the solar 6W panel provided ~3.5V of power with ample current to charge my battery on an overcast day. I could have gone with a smaller 4W panel, but I wanted to make sure that the battery would charge quickly.

Full Parts List and Cost

I purchased most of the materials for this project over several different orders. My estimated cost for the project was $200 in hardware, but I got a little carried away…with some help from a couple of gifted items, this project was a little more manageable.

Adding everything up, with shipping, handling, etc. bring the project to just about $400. Now, I also took this as an opportunity to buy a heat gun (I’ve always wanted one) and buy extra spare wire that I didn’t have.

Assembling the Project

Before I get into my build, I need to throw out a disclaimer: I’m not proficient in electronics. I’m a hobbyist, at best. And on my bad days, I’m just a hack. This project stretched my capabilities, and my skills around wire stripping, soldering, and general planning of how things should be assembled improved significantly. I tried capturing pictures throughout the entire process, but fell behind. I’ve tried to include appropriate pictures when possible.

Big Red Box

I started the assembly with the Big Red Box by drilling holes. The cable glands needed 1/2″ holes drilled. Here, I had to plan ahead and knew that I wanted 5 holes drilled: one each for the soil temperature probe, soil moisture probe, solar panel, rain gauge, and anemometer (wind speed & direction). When the holes were drilled, I inserted the cable glands and tightened them down.

I also inserted one half of the quick-disconnect cables into the cable glands, then tightened the compression fitting. Below, you can see the 5 cables and cable glands connected.

Solar panel

The first component I connected was the solar panel. The solar panel came with a DC barrel jack (below), and the weather shield also had an optional DC barrel jack connector that could be soldered on.

I decided to use this initially, but later found out that the Electron could be powered by the weather shield barrel jack, but it wouldn’t charge the battery. So, I later removed the barrel jack connector and spliced on a micro USB connector.

I don’t think plugging a solar panel directly into the Electron is a good idea because the power isn’t regulated, but I was willing to take the chance because the max output of the solar panel was far below the maximum input threshold of the Electron.

Working with the solar panel and the quick-disconnects was also my first extensive soldering I had done since college electronics. I’m not “proud” of the work I did, but it works. The quick-disconnect cable wires were really small, and I knew they needed to to touch each other, so I placed heat shrink wrap around each individual wire, and heat shrink wrap around the group of smaller wires.

It’s not particularly pretty, and I’m sure there’s a better (and more generally-accepted) way of doing this, but it worked. If you have any suggestions on how to do this better, please let me know.

I also learned that by twisting the wires together and applying a bit of solder to my soldering iron, I could transfers a small amount of solder on to the wires easily. This seems to work better than trying to heat the wires and melt the solder on to them.

Soil temperature

The next sensor I connected to the quick-disconnect cables was the soil temperature sensor. Connecting it went pretty fast.

Inside the big Red Box, I extended the length of the quick-disconnect and attached the extension wires directly to the soil temperature connection points of the weather shield. In retrospect, I wish I had done this different and used a screw terminal:

Connecting the internal wires of the soil temperature sensor, I spliced the external cable to the other end of the quick-disconnect, added heat shrink wrap, and applied several coats of liquid electrical tape.



Soil moisture

After connecting the soil temperature sensor, I began working on the soil moisture sensor.

This sensor was unique because it wasn’t weatherproof because it didn’t come with any housing or weatherproof covering over the red PCB. Ideally, I would have liked to create some sort of vacuum seal with plastic around the red PCB, but I wasn’t about to buy a vacuum sealer for this project. So, I embarked on building my own waterproof enclosure. I was inspired by another project online to use PVC tubing and a hot glue gun, but I couldn’t find the link a few weeks later. If I find it, I’ll be sure to share here.

The PVC housing consists of several threaded end caps, threaded adapters, and a short length of PVC pipe. At the sensor end, I used my Dremel to make two small holes for the sensor to slip through.


After slipping the sensor into place, I soldered wires to it and used a hot glue gun to seal the gaps between the sensor and the end cap. This provided a waterproof seal.

On the other end, I drilled a 1/2″ hole for another cable gland, ran wire through the gland and connected it to a quick-disconnect.

I glued the threaded adapters to the PVC pipe and screwed on the end caps.

I didn’t glue the threaded ends together because I wanted to access the component in the future.

In retrospect, this sensor felt rushed and sloppy. Clearly amateur. I’d like to modify it when I build a second unit, but I’m not sure how I could do this different. If you have any suggestions, please let me know.

In shopping for the PVC housing, I also let my boys loose in the Home Depot PVC aisle where they proceeded to build what they called a “marble run.”

I’m certain our local Home Depot instituted a new corporate policy after our visit.

Weather meters

After connecting the soil moisture sensor, I moved on to the weather meters. The weather meters contained 3 sensors: wind speed, wind direction, and a rain gauge. The wind speed and direction sensors were connected over 2 RJ-11 cables.

Of all the splicing and soldering I did, this was the most painful because RJ-11 wires are thin. Really thin. Really, really thin. Again, this is probably where a seasoned electrician would have told me, “Oh, you don’t need to do that. To weatherproof that type of connection, you should do X…”


Final look

With all of the wiring finished, I placed the Electron inside the Big Red Box with the weather shield and connected all the quick disconnects.


There’s a bit of tidying up that could be done to managing the cables better, but overall, I was satisfied. With the cover on, it was time to get it outside for a test run with the solar panel.


You’ll notice that I used a white paint marker to draw several circles around each of the quick-disconnects. This was a late addition to the project after I connected the wrong sensor to a quick-disconnect several times. I’m certain the paint will wear off after a few months, so I’m still looking for a more permanent solution.

Deploying to the Backyard

My first test run was in our backyard, where I did an initial stress test on the solar panel and the weatherproofing. I wanted to be sure that I could withstand a reasonably windy day,  thunderstorm, extreme heat (95 degree F), and direct sunlight.

As a temporary solution, I attached the weather meters to a hanging basket hook with zip ties. Later, I went on to use a 5′ barbed wire fence post as the base.

The field tests in the backyard went really well. I was most worried by the power consumption of the Electron, but I found that it used approximately 5-7% of it’s overall battery life each day, but an hour of direct sunlight was able to recharge the battery fully. The power consumption is due to the way the unit was programmed: every 15 minutes I wake the unit up, take sensor readings, transmit it to the cloud, then go to sleep. I don’t want to dive into the details of that process here, so look for a post explaining the code, cloud connectivity, and integration into Azure coming soon.

Deploying to the farm

After field testing the station in my backyard for 2 weeks, it was time to deploy to the farm. It was a beautiful, sunny day, and about 85 degrees F in the sun. We packed everything (and everyone) up in the car, and headed out.


After calibrating the soil moisture sensor to the farm’s soil (more on this in a later post), I installed a barbed wire fence post and attached the weather meters, solar panel, Big Red Box, soil moisture, and soil temperature sensor.


Once the wind direction sensor was calibrated to point towards the North, I made sure everything was transmitting data to the cloud, then sealed it up.

Final thoughts

This was an incredibly fun project, and took me ~2 months to build out (hardware & software). I’ll have several additional posts about the Electron code I wrote, the Particle cloud integration with Azure, other Azure components (IoT Hub and Functions), and the companion mobile app written in NativeScript. Stay tuned.

I’ve left out a lot of detail, but would love to share more if you’re interested, so let me know.


4 comments for “Building an IoT Farm Monitoring Solution

  1. Avatar
    September 7, 2017 at 2:04 am

    I have almost the same setup, but I used the regular ol’ Photon, which recently has went crazy. Issues I ran into before the actual Photon started acting up was the battery going dead if there happened to be multiple rainy or very cloudy days. I was using a 6v solar panel with a similar 3.7v lipo 2000mah. If I had too, I would of switched to a 9v or 12v battery with higher amperage, with the matching solar panel and regulator with USB output. You could even run a small fan to keep your sensors from creating additional heat. Get a radiation shield too.
    As far as code, The code off of the spark website “works”, but has issues with reporting wind speed properly (will not go above a certain speed (around 20mph), I added in more wind directions that were missing from the original code. I am resurrecting my weather station that has been down for a month, and would like to see the code you have. Mine is currently Frankenstein’d from here and there.

  2. Avatar
    July 17, 2018 at 4:15 am

    Hi Mike,
    A really helpful write-up. Would like to know more about how I can get in touch with you. Had a few doubts, just wanted to clarify.
    A mail id would be great.

  3. Avatar
    July 25, 2018 at 12:21 pm

    Hi Mike! Please help me. I’ve try to clone your build, but the values of the humidity sensor is not valid, values between -6,00% and -5,81%. The values of the temperature is ok.
    In my build, i use the previous version Weather Shield, wich utilize the HTU21D sensor. Any idea what is causing the problem? I think not of the sensor, otherwise it would be incorrect temperature values.
    Thank you very much!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.