Wireless Sensor Network for Agriculture and Smart Greenhouse
by Neutrino-1 in Circuits > Wireless
4959 Views, 81 Favorites, 0 Comments
Wireless Sensor Network for Agriculture and Smart Greenhouse
For a long time, I wanted to create something that was both environmentally conscious and interesting, such as wireless devices. So I'm combining these two interests to develop a wireless sensor network for environmental and energy monitoring. My primary goal is to use this in a large-scale agricultural field or greenhouse, where I can successfully monitor several metrics such as crop health, temperature, humidity, soil health, and the energy consumption of the equipment used in this environment. By acquiring this information, we can optimise the usage of available resources, resulting in energy savings. While the concept appears simple, the project's problem is selecting the appropriate components to keep costs low and make it scalable. So, throughout this project, we will not only focus on the features but also on how to manufacture them in tens or thousands of units.
Supplies
This is the list of products that can help you do this project with ease
(Affiliate Link)
- 3d printer: https://amzn.to/3trVWKw
- printer upgrades: https://amzn.to/3hbK3Ga
- Black filament: https://amzn.to/3orgpiA
- Glue gun:https://amzn.to/2WiuKUa
- Screws: https://amzn.to/3vdF1zj
- drill: https://amzn.to/3yYFA0S
- jigsaw: https://amzn.to/3zweaRD
- Isopropyl alcohol: https://amzn.to/3BdokHS
- NPK sensor : https://amzn.to/3OOriIS
For a more detailed BOM for the PCB, please visit this link.
Brainstorming
In this step, I put all the ideas I have related to the project on a whiteboard and spent quite a few hours.
Even though most of these ideas are possible, it’s really hard to implement all of them at once because of time and cost constraints. So, I have shortlisted some of them that will go into the final project. I have discussed more detail about my design process and why I chose these features in the video.
Features Shortlisting
The next step was to shortlist all the features and select only some of them that are cost-effective and suitable for large-scale manufacturing.
After some research and cross-checking some pre-existing products, these are the features I settled on:
Core feature for the slave node:
- A processor to read the sensor data
- A Wireless protocol to send the data wirelessly
Core feature for the Master node:
- Same Wireless protocol that’s implemented on the slave to read the data
- An interface to process the sensor data and send it to a cloud platform
I have also shortlisted more features that go into the WSN, considering the cost and the time required to implement them.
Additional slave features:
- Battery to power the slave.
- Have an inbuilt RS485, as many industrial and agriculture sensors use them by default.
- Since I’m planning to use the system both indoors and outdoors, I will add many ways to power the slave and also charge the battery, either by DC jack, USB C, or by using a terminal block.
- Then, finally, having an adjustable boost converter to convert the battery voltage to the required voltage for various sensors.
Additional Master Features:
- Make sure it can handle a wide range of inputs because most industrial devices and even outdoor devices run on 12 volts to 24 volts.
- A robust power protection system to avoid fluctuation, overcurrent, transient voltage, and reverse current protection.
- Have an option for local processing, possibly with a Raspberry Pi Zero. So, let's include a 2A buck converter for power.
- I will include a RS485 drive to communicate with other host devices on site, like a PLC or other industrial host system.
Now, for both slave and master, I want to expose some of the GPIO pins for external circuits like controlling servos or stepper motors. Which can be used to control irrigation system, solar panel direction, etc. Finally, let’s include an RGB LED as an indicator instead of having some small fancy display to keep it cost-effective.
With features shortlisted, let's start by finding the components that we'll need to get these features from paper to reality!
Component Selection
Choosing components for projects like this (having more than one unit) can be very tedious and expensive! So, we need to choose effectively, which reduces both of these parameters. One of the best ways to select the components is to choose a similar component that can fit both our master and slave nodes. Later, find the parts that're required to add more features to the individual nodes.
Wireless Protocol and Wireless Component Selection
Starting with the wireless communication protocol, as I intend to use this system both indoors and outdoors, LORA is the best option. It requires less power and can transmit data over long distances, making it ideal for our battery-powered slave module. Here, LORA is simply a wireless protocol, and many manufacturers produce this LORA-based IC and modules. So, we need to narrow down our choices for the LoRa module or IC that will be used in our circuit.
First, I need to find a LORA module that’s legal to use in India. In this case, I need to search for the radio frequency around 865-867 MHz Then I need to find a module that I can easily source and that's also cost-effective at the same time. So, finally, after some research, I settled on the RFM96 LORA module, which satisfied all the requirements.
Microcontroller Selection
Once the LORA is selected, I need to find a suitable microcontroller to fetch the data from the sensor and send it through the LORA.
In this case, I chose the esp32C3 mini and esp32H2 (esp32c6 is also compatible)
I know there are other more energy-efficient and cheaper microcontrollers. But these ICs were chosen for two reasons. First, they are drop-in replacements for each other, which means you can replace one with the other and they would still work. So, in the long run, this can help me if I end up having some supply chain issues. Secondly, the C3 mini comes with built-in Wi-Fi and Bluetooth support, which can be utilized when deciding to use the slave module as an independent device, where it can still send the data directly to the cloud using the WiFi.
As for the H2 mini, it supports additional protocols like Matter, Zigbee, and Thread. This means the same slave node can support multiple protocols at the same time, allowing it to integrate with other smart devices that are installed in the existing system.
For instance, if you have UV smart lights or other industrial equipments that supports protocols like zigbee, thread, or matter installed in your greenhouse, you can control them by receiving commands from the master node via LORA, interpreting them in slave, and controlling the lights with zigbee or thread.
RS485 Selection
Next, for the RS485 protocol, I wanted to use something that’s very robust and easy to procure. The MAX485 IC is a very popular IC that is used in a lot of industrial devices, so I did a little more research on this particular IC and performed some tests on various modules based on it. Which really helped me decide the best circuit to build around MAX485.
Then there are a few common components I choose, like the 0805 capacitor, 0805 resistors, and AMS1117/MCP linear regulator to keep the system stable, and a WS2812B RGB led for indication. With these, we have selected the components that can be used for both the master and the slave nodes.
Now, we need to find the remaining components for the salve and master individually.
Slave Component : Battery
For the battery, I did a very rough calculation on how much power the system might consume during sleep and while transmitting. With the current component selection and a 2200 mAh battery, the slave should at least last between 3 and 4 days!
Slave Component : Battery Management Circuit
However, changing the battery very often isn’t very practical. That’s the reason we have solar panels on our feature list. Usually, it's a little complicated to have both a solar-based charger and an external charger together. But I came across an Adafruit circuit based on the BQ24074 IC that is simple and easy to use. This IC allows the maximum power from the solar panel to reach the battery without using maximum power point tracking. At the same time, it gives a wide range of input options to charge the battery and use the circuit with external power simultaneously.
You can read more about circuits directly from Adafruit.
Slave Component : SMPS
Finally, to finish the component selection for the slave, I will use the MT3609 SMP circuit to generate a variable power supply for various sensors. As most industrial sensors can easily vary from 5V to 24V.
Master Component : 5 Volt 2 a Supply
Since we need the complete system to run on industrial supply, we need to find a way to take in a wide range of input from 12 to 24 volts and also produce a 5 volt, 2 A, to power external devices (like the Raspberry Pi). For this, I chose LM2596s-5, just because I have used them in the past, low-cost and very easy to procure. Along with this, I also chose an appropriate DC-Jack, terminal block to handle this current rating.
Schematic Design!
Both our slave and master have similar core components, so I started with a base circuit that is common for both and later replicated these for the slave and master individually.
Here's a video explaining how the circuit was designed around the selected component:
Above pictures are the final version of what the master and slave nodes look like and based on circuit, these are the BOM files that've been generated.
PCB Layout Design
Once the schematic design is done, we can move on to the PCB layout design.
To keep things simple, I had to make different sections on the PCB to handle power, the RF section and the sensor communication. At the same time, there are a set of basic guidelines that I had to follow to get the most out of this design. You can check out the basic guidelines at this link.
Here's a video explaining how I selected the footprint and the strategy behind completing a PCB for large-scale manufacturing:
PCB Testing
As soon as I received the PCB, I did various quality checks on the PCB, including the silk layer, solder mask, and other parameters. This is to assure me that I can trust the manufacturer for large-scale manufacturing. Here's a detailed video on all the tests I perform on the PCB to decide if they are the best or not.
PCB Assembly
I got the major components from Digikey, like the Lora, esp32c3, and esp32h2 mini. The rest I either locally sourced or I already had in my maker bag. Most of the assembly was straight-forward, except for the esp32c3/esp32H2 mini. They don’t have castellated holes similar to the RFM Lora module, which I didn’t realise would be a big challenge to solder without a hot plate 🥲.
I had to sacrifice a few of the esp32c3 to learn to solder them using a hot air gun, but eventually I could get them soldered properly. Once I got the hang of soldering the esp32c3, the rest of the soldering and assembly process was pretty easy!
I did have a hiccup with the slave node; the Bq24074 did not arrive on time before the contest. So I just left the connection for those pins and soldered the rest of the board. The board currently won’t support solar charging, but you can always power the board with USB-C when you want the slave in a battery-less situation.
Code
To test the hardware and get the basic functionality of the PCB. I’m writing the code completely in Arduino IDE, and these are the features that I’m implementing in the code:
Slave Node
- Get NPK sensor values over RS485
- Send NPK values over LORA
- Randomly SET RGB value
- Send RGB value over LORA
Master Node
- Receive NPK values over LORA
- Receive RGB values over LORA
- Read RSSI value of slave
- Read the energy meter value over RS485/MODBUS
- Send energy meter reading and NPK value to cloud
- Set the received RGB value
- Set the brightness of RGB based on RSSI value
Note 1: Currently, this code is not concentrating much on battery optimization for the slave. The slave module sends the data over LORA every 15 seconds for demo purposes, but in deployment, the slave module would go to sleep for an hour after sending the data each time.
Note 2: To make the Lora work with esp32c3, you need to modify the Lora library by Sandeepmistry. In the Lora.cpp file, replace _spi.begin() with _spi.begin(0,10,1,3).
Note 3: The code can be uploaded via FTDI or the CP2102 module via the given pinout on both the slave and master nodes. Just make sure to put the device in flash mode by temporarily connecting the GPIO9 pin to GND. If you have any issues uploading the code, make sure to connect a 10k resistor between GPIO8 and 3.3v as well.
Required Library:
- https://github.com/sensidev/arduino-modbus-master
- https://github.com/sandeepmistry/arduino-LoRa
- https://github.com/knolleary/pubsubclient
- https://github.com/arduino-libraries/Arduino_JSON
- https://github.com/adafruit/Adafruit_NeoPixel
- https://github.com/plerup/espsoftwareserial
You can find the final code here.
Cloud Setup
There are tons of cloud platforms to choose from for IoT, but it gets very expensive very soon as we try to scale up. Therefore, I want to build a custom cloud platform that I can scale effortlessly and keep cost-efficient. To build this custom IoT platform, I chose Digital Ocean (running an Ubuntu server) and Node Red.
Here, I'm not sharing the URL due to security reasons and the high cost of server maintenance if I get a huge influx of traffic.
If you would like to create a similar platform, Digital Ocean has an excellent article explaining the setup of MQTT and Node Red. (THIS IS NOT SPONSORED; genuinely, the platform is easy to setup!)
Dashboard Setup
Once you have the cloud and node-red setup ready, you need to install node-red-dashboard and import this flow.
Note: You need to update the Mqtt username and password after importing the flow.
If you have done this setup correctly and visited "Your Cloud IP:1880/ui " you should see the dashboards.
3D Printed Parts
Once the electronics and cloud setup was done, I designed the case for this project using an online cloud-based CAD application called OnShape. Here, Just to experiment with the 3d printed models, I have designed the case in two different ways. The master node case focuses more on the functionality of the case, while the slave node case focuses more on the form factor and appearance.
I sliced the model using a Prusa for ender 3v2 3D printer. Unfortunately, I wasn’t able to use ABS material for the case; currently, both cases were printed in orange PLA at 210C (Nozzle) and 65c (Bed) with a layer height of 0.24mm. The total time to print all four parts is around 6–8 hours.
You can download the STL models for this case here
Final Assembly - Master
The final assembly was very smooth, the case is designed to easily fit the PCB and it has good tolerance on the holes and the spacing around the PCB.
Also, the assembly is very straight forward and doesn't required any complex methodologies. The 3d printed part is installed with heat inserts, so it's just mater of fact of using M3 screw to fasten the PCB and 3d printed part together.
Final Assembly - Slave
Note: Since there is no BQ24074 IC, there is no way to manage the battery. To prevent the battery from over discharging, I have added a slide switch to completely disconnect the battery from the circuit when not in use.
Final Setup for Reading
Slave Node NPK Setup
This setup works both indoor and outdoor condition, for this particular demo I have setup the slave and the master node inside my room.
Where the NPK sensor is placed on a pot to read the live Nitrogen, Phosphorus and potassium value. Along with that the Slave also generates a random RGB colour which will be mapped to each reading of the NPK sensor. This way, we can see if the master node received the recent data successfully without checking the cloud platform.
Master Node EM Setup
Now for the master setup, I have connected a Industrial grade, RS485 enabled energy meter. Which will simulate the energy meter used in industries or other harsh environments. Once the master node receive the data from the slave, it will also request the energy meter to provide current, voltage and frequency of the live supply (it can also produce wattage, since currently the energy meter isn’t connected to any load it will always read zero).
Once it has all the data in hand, it will transfer the data to the custom built cloud platform via MQTT for further processing.
We can watch all this in real time using the Node Red Dashboard.
Node RED Dashboard
If you have done this setup correctly and visited "Your Cloud IP:1880/ui " you should see the dashboards updating live every 30 seconds.
Conclusion
In this particular project, I was able to achieve all the milestone I had with set in the beginning of the project and most of them worked perfectly as I expected! Well... expect for the battery management circuit but apart from that there are few more optimizations I can do in terms of component selection, PCB design and Case design to reduce the overall cost of the device and make it more efficient. So, make sure to subscribe to the PCB CUPID YouTube channel for more update on this project!
If you would like to learn how to design PCBs like this, make sure to check out my YouTube video playlist: