|
KiCADKicad
|
|
|
arduino IDEArduino
|
|
|
Node-Rednodered
|
|
|
OnShapeOnShape
|
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 gathering this information, we can make the best use of available resources, resulting in energy savings. While the concept may appear simple, the challenge of the project lies in selecting the proper components to keep the cost low and make this project scalable. So, throughout this project, we'll not only focus on the features but also deeply think about how we can manufacture them in 10's or 1000's of quantities.
Brainstorming
Here, 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 below:
Shortlisting Features:
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 help in getting these features from paper to reality!
Common Component Selection for both the Master and Slave 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.
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 Selection
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!
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.
SMP Circuit:
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 Selection:
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:
Below is the final version of what the master and slave nodes look like:
Master Node Circuit:
Slave Node Circuit - 1:
Slave Node Circuit (Battery/Power Management):
Based on the above circuit for slave and master, 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 Design for Master Node:
PCB Design for Slave Node:
PCB Assembly
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.
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!
Master Node PCB:
Slave Node PCB:
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.
Unsoldered Power Management
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 example 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!)
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 below dashboards.
Node Red DashBoard (Sensor Tab):
Node Red DashBoard (Energy Meter Tab):
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.
Master Node Case:
Slave Node Case:
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.
Master Case:
Slave Case:
Final Assembly
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.
Master Node Assembly - 1
Master Node Assembly - 2
Master Node Assembly - 3
Slave Node Assembly - 1
Note: Since there is no BQ24074 IC, there is no way to manage the battery, to prevent battery from over discharge I have added a slide switch to completely disconnect the battery from circuit when not in use.
Slave Node Assembly - 2
Slave Node Assembly - 3
Working Setup & Explanation
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.
Slave Node NPK Setup
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
Working video :
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 optimization 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 like to learn how to design PCB like this make sure to check out my YouTube video playlist:
How to Start a open source project : link
Beginners Guide to KiCad : link
Beginners Guide to easyEDA : link
Beginners Guide to Kicad + Git : link
Wireless Sensor Network for Agriculture and Smart Greenhouse
*PCBWay community is a sharing platform. We are not responsible for any design issues and parameter issues (board thickness, surface finish, etc.) you choose.
- Comments(5)
- Likes(11)
- Marc Wilson Sep 01,2024
- Kenji Aug 18,2024
- rtandon Jan 29,2024
- Engineer Jan 27,2024
- Yashcher Yashcher Jan 19,2024
- Engineer Jan 17,2024
- Engineer Jan 16,2024
- Engineer Jan 16,2024
- Anjali Jan 16,2024
- Engineer Jan 16,2024
- Srinivasan M Jan 09,2024
- 12 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
-
9design
-
9usability
-
7creativity
-
5content
-
9design
-
9usability
-
9creativity
-
6content
-
10design
-
10usability
-
10creativity
-
10content
-
10design
-
10usability
-
10creativity
-
10content
-
10design
-
10usability
-
10creativity
-
10content
-
10design
-
10usability
-
10creativity
-
10content
-
10design
-
10usability
-
10creativity
-
10content
-
10design
-
10usability
-
10creativity
-
10content
-
10design
-
10usability
-
10creativity
-
10content
-
10design
-
10usability
-
10creativity
-
10content
-
10design
-
10usability
-
10creativity
-
10content
-
10design
-
10usability
-
10creativity
-
10content
More by Srinivasan M
- Wireless Sensor Network for Agriculture and Smart Greenhouse For a long time, I wanted to create something that was both environmentally conscious and interestin...
- Smart thermometer v2 using esp-01f In one of the previous projects, I built a simple thermometer with ATTINY 85 which can last for 140d...
-
-
-
kmMiniSchield MIDI I/O - IN/OUT/THROUGH MIDI extension for kmMidiMini
113 0 0 -
DIY Laser Power Meter with Arduino
162 0 2 -
-
-
Box & Bolt, 3D Printed Cardboard Crafting Tools
156 0 2 -
-
A DIY Soldering Station Perfect for Learning (Floppy Soldering Station 3.0)
559 0 2