This project was inspired by wanting to create a sustainable way to analyze flow rates in irrigation pipes for agriculturists without needing to worry about changing the battery everyday. Having a reliable irrigation system that can consistently deliver water to crops, whether it be for farmers or agricultural researchers, is crucial for the wellbeing and health of the plants being grown. Having a proper working irrigation equipment monitoring system that can inform the user if there are any fluctuations in water pipe flow (meaning there could be a leak somewhere along the pipe) can be the difference between a successful harvest/experiment and a dry one. Most of these systems are powered using rechargeable solar powered batteries, but with this project, I wanted to introduce an water flow tracking system that uses a new sustainable form of power: a self powering system that recycles the water flowing through the irrigation pipes to recharge it's own battery.
How it WorksThe device works as follows:
1. Water flows through the pipe by connecting it to a water hose faucet outdoors.
2. The water reaches the F50 Hydroelectric Generator. As the generator turns, it then powers a 5V battery that is used to power the upcoming water flow sensor.
3. After passing through the hydroelectric generator, the water then reaches the YF-S201C water flow sensor which then takes data on the flow of the water through the pipe in mL/s. The data is collected and sent to be analyzed on Adafruit's iot logging interface using the Blues Wireless ESP32 compatible board.
4. The water then exits the makeshift sprinkler nozzle at the end of the pipe.
This was made by recycling a coffee pod (specifically a Nestle Nespresso pod) inserted into the PVC pipe at the end of the system to use as an irrigation nozzle. This proved to be an environmentally friendly solution to reusing resources to create a nozzle for watering plants. Normally these nozzles are disposed of after use, and I can only imagine all of the plastic waste that is caused as a result of this, since many people drink coffee. Finding ways, even as small as this, to find uses for materials that would otherwise be thrown away can help save the planet and reduce our carbon footprints, especially when these tactics are used to create tools that can help nourish the environment around us :)
Using the graphical data representation provided by Adafruit.iot, it would be easy to monitor whether there has been any inconsistencies or drops in water flow throughout the pipe. Using multiple of these water flow sensors scattered throughout the pipe, it would also be easier to determine which sector the leak may be in.
The actual board I am using to send the collected data to the cloud for analysis is the Blues Wireless Notecarrier AF with an Adafruit HUZZA32 board. To send the data over so it can be accessed by Adafruit.io from the cloud, I used MQTT, a messaging protocol for IoT. So the transfer of data goes like this:
water flow sensor data -> Notecard -> MQTT -> Adafruit.io
TestingThe initial test that was done was by connecting the pipe to the end of a gardening hose. But I did not have the proper connecting piece to connect the PVC to the hose so the connection was very unstable and the pressure of water going through was too strong so that water started leaking out the seams from the PVC connections. To prevent this from happening, I decided to move the initial testing indoors and used a water pump in a semi-filled bathtub to see how well the hydroelectric generator and water flow sensor operated.
Once initial testing was done, the cracks in the PVC connections were filled with plumbing putty so that they were more sealed and the next day I tested the contraption outdoors using the gardening hose again. The results were much better as the flow of water was more consistent without the leaks and we were able to get a consistent almost 5V of power from the hydroelectric generator. This proves that a system like this can be self sustaining by recycling the water already being using in the irrigation pipes to power a monitoring system.
Data CollectionWhen pairing it with the Blues Wireless module, there were admittedly some inconsistencies with our connection to the cloud so I couldn't get a nice steady stream of live data coming in through to the graphs in Adafruit.io, but I was able to see that the data is there and is being collected.
Notehub.ioOnce the data is collected using the Blues Wireless cloud service, Notehub, the data is then routed to the Adafruit.io cloud service which displays the data neatly in a revolutions/s graph called AdafruitFlowRev and a mL/s gauge called AdafruitFlowLiter.
JSONata was used to format the data before sending the MQTT message to Adafruit. The following expressions were used to format the data coming from the Notecard:
{"value": body.waterflowperlt}
{"value": body.waterflowperrev}
The code was made in Arduino and needed the inclusion of the Notecard library. This code made the conversions for calculating the milliliters/second that the water flow sensor was detecting. It then would try to establish a connection to the server by submitting requests to upload the data to the Notehub.
#include <Notecard.h>
//NoteCard product id. Please add your product id below.
#define myProductID "Enter your product id here"
//Create Notecard object instance.
Notecard notecard;
byte sensorPin = 14;
// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.5;
volatile long pulseCount;
long pulseCountperSec;
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
unsigned long oldTime;
unsigned long startTime;
unsigned long delayBetweenSamples = 2500;
char buf[200];
void initNoteCard()
{
Wire.begin();
notecard.begin(0x17,30,Wire);
J *req = notecard.newRequest("hub.set");
JAddStringToObject(req, "product", myProductID);
JAddStringToObject(req, "mode", "continuous");
notecard.sendRequest(req);
}
/*
Insterrupt Service Routine
*/
//void ICACHE_RAM_ATTR pulseCounter()
void IRAM_ATTR pulseCounter()
{
// Increment the pulse counter
pulseCount++;
}
void setup(){
Serial.begin(9600);
initNoteCard();
startTime = millis();
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, RISING);
}
void loop() {
if((millis() - oldTime) > 1000) // Only process counters once per second
{
// Disable the interrupt while calculating flow rate and sending the value to
// the host
detachInterrupt(digitalPinToInterrupt(sensorPin));
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres;
// Print the flow rate for this second in litres / minute
Serial.print("Flow rate: ");
Serial.print(int(flowRate)); // Print the integer part of the variable
Serial.print("L/min");
Serial.print("\t"); // Print tab space
// Print the cumulative total of litres flowed since starting
Serial.print("Output Liquid Quantity: ");
Serial.print(totalMilliLitres);
Serial.print("mL ");
Serial.print("Local Mili ");
Serial.print(flowMilliLitres);
Serial.println("mL ");
Serial.print("\t"); // Print tab space
Serial.print(totalMilliLitres/1000);
Serial.print("L");
Serial.print("\t"); // Print tab space
Serial.print(pulseCount);
Serial.print(" pulses");
pulseCountperSec = pulseCount;
pulseCount = 0;
// Enable the interrupt again now that we've finished sending output
attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, RISING);
}
if ((millis() - startTime > delayBetweenSamples) && pulseCountperSec > 0){
startTime = millis();
J *req = notecard.newRequest("note.add");
if (req != NULL) {
Serial.print("Enter JS");
Serial.print((char *)buf);
JAddBoolToObject(req, "sync", true);
J *body = JCreateObject();
if (body != NULL) {
sprintf(buf,"%d",pulseCountperSec);
JAddStringToObject(body, "waterflowperrev", (char *)buf);
sprintf(buf,"%d",flowMilliLitres);
JAddStringToObject(body, "waterflowperlt", (char *)buf);
JAddItemToObject(req, "body", body);
}
notecard.sendRequest(req);
pulseCountperSec = 0;
}
else{
Serial.print("req failed");
}
}
}
Future PlansFor the next step in this project, I would like to include a relay valve switch and design it so that when the system discovers a leak, with the decrease in electrical current provided by the hydroelectric generator, the valve will close, turning off the main water supply hose so as to conserve water. This would be done using a relay and communication for the opening and closing will happen using an ESP32-S2 with TFT.
Comments