Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions SABIB/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env
.env.local
.env.development.localw
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
21 changes: 21 additions & 0 deletions SABIB/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Saad AIDDI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
69 changes: 69 additions & 0 deletions SABIB/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# SABIB: Smart Water Flow Monitoring and Leak Detection System
## Save Today, Secure Tomorrow

## Abstract

### Background and Problem Statement
Water scarcity is a pressing issue in the Souss Massa region of Morocco, impacting agriculture, daily life, and community sustainability. Current water usage practices are inefficient due to the lack of real-time monitoring, leading to resource wastage and heightened strain on limited water supplies.

### Impact and Proposed Solution
SABIB aims to address this challenge with an innovative solution: a smart water flow monitoring and leak detection system. By providing real-time insights into water consumption and detecting leaks, SABIB empowers individuals and businesses to implement sustainable water management practices, conserving resources and reducing costs.

### Project Outcomes and Deliverables
- **Smart Water Flow Measurement Device**: A hardware device capable of monitoring water flow and consumption.
- **Leak Detection Model**: AI-powered leak detection to identify anomalies in water usage patterns.
- **Dashboard**: A user-friendly interface displaying real-time water usage data and alerts.
- **Documentation**: Detailed project documentation, including setup instructions and technical details.

---

## Instructions

### Prerequisites
- Hardware: ESP32, flow sensor, electrovalve, LEDs, and necessary connectors.
- Software: Arduino IDE, Python 3.x, and required libraries (listed in `requirements.txt`).
- Accounts: ThingSpeak API for data visualization.

### Hardware Setup
1. Connect the flow sensor to the ESP32's GPIO pin.
2. Wire the electrovalve to the designated pin.
3. Connect the LEDs to GPIO pins for status indicators.
4. Power the ESP32 and verify connections.

### Software Setup
1. Clone the repository:
```bash
git clone https://github.com/your-repo/sabib.git
```
2. Install Python dependencies:
```bash
pip install -r requirements.txt
```
3. Flash the ESP32 with the provided esp32_code.ino.
```bash
SABIB_esp.ino
```

4. Run the leak detection model:
```bash
python leak_detection_model.py
```


### Pitch Vedio : [here](https://drive.google.com/file/d/11e1IZ-wIoxZ3nnoahPDl8tspk21IvXmd/view?usp=drive_link)

### Presentation Slides: [here](https://www.canva.com/design/DAGX92HWk6c/DPwoumVbXRVd3yMPsINIjA/edit?utm_content=DAGX92HWk6c&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton)

### AI Model: [here](https://colab.research.google.com/drive/1jgHgSA4g-mV0_C_Nvm_oYHGf4ks6og2C?usp=sharing)

### Prototype
![alt text](image-1.png)


### Screenshot
![alt text](screencapture-sabib-team-2024-05-16-15_22_46.png)



### LICENSE
[LICENSE](LICENSE)
113 changes: 113 additions & 0 deletions SABIB/SABIB_esp.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include <WiFi.h>

const char* ssid = ""; // Enter your Wi-Fi SSID here
const char* password = ""; // Enter your Wi-Fi password here
const char* server = "api.thingspeak.com";
const char* apiKey = ""; // Enter your ThingSpeak API key here
const int sensorPin = 2; // Define your sensor pin here
const int valvePin = 25; // Pin connected to the electrovalve
const int buttonPin = 26; // Pin connected to the button
const int greenPin = 5; // Pin connected to the LED green on
const int redPin = 16; // pin for redpin connected to in 16
volatile long pulse;
bool valveState = LOW;
bool greenState = HIGH; // State of the green led low
bool redState = LOW; // Set thge state of red pin high
bool wifiConnected = false;
const float maxFlowRate = 2.0; // Maximum flow rate in liters per minute
const float pulsesPerLiter = 300; // Number of pulses per liter from the flow sensor

void setup() {
pinMode(sensorPin, INPUT);
pinMode(valvePin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // Assuming the button is connected to ground when pressed
pinMode(greenPin, OUTPUT); // Set the green LED pin as output
pinMode(redPin, OUTPUT); // Set the red LED pin as output
Serial.begin(115200);
attachInterrupt(digitalPinToInterrupt(sensorPin), increase, RISING);
}

void loop() {
static bool lastButtonState = HIGH;
bool currentButtonState = digitalRead(buttonPin);

// Check for a button state change from released to pressed
if (lastButtonState == HIGH && currentButtonState == LOW) {
// Button has been pressed, toggle the state of the valve and LED
valveState = !valveState;

// switch the to opposite if high go low if low go high
greenState = !greenState;

// set the state of red pin to opposite of green led
redState = !greenState;

// Update the pins based on the new states
digitalWrite(valvePin, valveState);
digitalWrite(greenPin, greenState);
digitalWrite(redPin, redState);

// Add a small delay to debounce the button
delay(50);
}

// Update the last button state for the next loop iteration
lastButtonState = currentButtonState;

if (!wifiConnected){
connectToWiFi();
}

// If connected to Wi-Fi, send data to ThingSpeak
if (wifiConnected) {
WiFiClient client;

// Read the pulse count and reset it
long pulseCount = pulse;
pulse = 0;

// Convert pulse count to flow rate
float flowRate = pulseCount / pulsesPerLiter; // Calculate flow rate in liters

// Print flow rate to Serial monitor for visualization
Serial.print("Flow Rate: ");
Serial.print(flowRate);
Serial.println(" L/min");

// Prepare the URL for the ThingSpeak update
String url = "/update?api_key=";
url += apiKey;!
url += "&field1=";
url += String(flowRate);

if (client.connect(server, 80)) {
// Send the HTTP request
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + server + "\r\n" +
"Connection: close\r\n\r\n");

// Wait for the response
while (client.available()) {
String line = client.readStringUntil('\r');
}
client.stop();
}

}
}

void increase() {
pulse++; // Increment pulse when sensor event occurs
}

void connectToWiFi() {
WiFi.begin(ssid, password);
int attemptCount = 0;
while (WiFi.status() != WL_CONNECTED && attemptCount < 10) {
delay(500);
attemptCount++;
}
if (WiFi.status() == WL_CONNECTED) {
wifiConnected = true;
}
}
Binary file added SABIB/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SABIB/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions SABIB/notebook/link.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://colab.research.google.com/drive/1jgHgSA4g-mV0_C_Nvm_oYHGf4ks6og2C?usp=sharing
Loading