Ashwini kumar sinha
Created August 6, 2019 © MIT

Smart City Water Management

system that collects the live data of water usage and wastage in each home and help to manage the city water distrubution

AdvancedFull instructions provided18 hours30
Smart City Water Management

Things used in this project

Hardware components

Flow Sensor, Straight-Through Flow Path
Flow Sensor, Straight-Through Flow Path
×1
Solenoid Valve, 2 Way
Solenoid Valve, 2 Way
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
Argon
Particle Argon
×1
Jumper wires (generic)
Jumper wires (generic)
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

connection

Code

simple code for getting total water consumed and waste by each home

C/C++
#include "application.h"
SYSTEM_MODE (AUTOMATIC);
SYSTEM_THREAD (ENABLED);

/* Interrupt Functions */
int led2=D13;
int LED = D7;
int sen1= D3;
int sen2=D4;
float calibrationFactor = 4.5;
float flowRate1;
float flowRate2;
unsigned long totalMilliLitres1;
unsigned long totalMilliLitres2;
unsigned long oldTime;
int flowMilliLitres1;
int flowMilliLitres2;
volatile int  flow_frequency1;
volatile int  flow_frequency2;
volatile bool led_state = LOW;
volatile bool led_state2 = LOW;


/* Setup is run once at the start (Power-On or Reset) of sketch */
void setup() 
{
    Serial.begin(9600);
    Serial1.begin(9600);
  pinMode(LED, OUTPUT);
   pinMode(led2, OUTPUT);/* Pin 13 is defined as Output */
  pinMode(sen1, INPUT_PULLUP);
  pinMode(sen2, INPUT_PULLUP);/* Interrupt pin */
  attachInterrupt(sen1, blink, FALLING);
  attachInterrupt(sen2, blink2, FALLING);
  
  
   flow_frequency1        = 0;
    flow_frequency2        = 0;
  flowRate1          = 0.0;
  flowRate2           = 0.0;
   flowMilliLitres1   = 0;
    flowMilliLitres2   = 0;
  totalMilliLitres1  = 0;
   totalMilliLitres2  = 0;
  oldTime           = 0;

  
}

/* Loop runs over and over after the startup function */
void loop()
{
/*
  digitalWrite(LED, led_state);
  digitalWrite(led2, led_state2);
  total1= (flow_frequency/4.5);
  total1= (flow_frequency2/4.5);
  Serial.print("freq");
  Serial.print(flow_frequency);
  Serial.print("freq2");
  Serial.print(flow_frequency2);
  
  Serial.print("total1");
   Serial.print(flow_frequency2);
     Serial.print("total1");
    Serial.print(flow_frequency2);
      Serial.println("kkkk");
  
    */
   if((millis() - oldTime) > 1000)    
  { 
    detachInterrupt(sen1);
         detachInterrupt(sen2);
    flowRate1 = ((1000.0 / (millis() - oldTime)) * flow_frequency1) / calibrationFactor;
    flowRate2 = ((1000.0 / (millis() - oldTime)) * flow_frequency2) / calibrationFactor;
    
    oldTime = millis();
    
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres1 = (flowRate1 / 60) * 1000;
    flowMilliLitres2 = (flowRate1 / 60) * 1000;
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres1 += flowMilliLitres1;
         totalMilliLitres2 += flowMilliLitres2;
    unsigned int frac;
    ////////////////////////
    // Print the flow rate for this second in litres / minute
    Serial.print("Flow rate1: ");
    Serial.print(flowRate1);  // Print the integer part of the variable
    Serial.print("L/min");
    /////////
    Serial.print("Flow rate2: ");
    Serial.print(flowRate2);  // Print the integer part of the variable
    Serial.print("L/min");
    // Print the number of litres flowed in this second
   ///////////////////////////////
    // Print the cumulative total of litres flowed since starting
    Serial.print(" total input Liquid Quantity: ");             // Output separator
    Serial.print(totalMilliLitres1);
    Serial.print("mL"); 
    //////////////////////////
    Serial.print(" total consumed Liquid Quantity: ");             // Output separator
    Serial.print(totalMilliLitres2);
    Serial.println("mL"); 
    ////////////////////////
///////hc 05
Serial1.print(String(flowRate1));
Serial1.print("l/m");
Serial1.print(":");
Serial1.print( String(totalMilliLitres1));
Serial1.print("L total");
Serial1.print(":");
Serial1.print(String(flowRate1));
Serial1.print("l/m");
Serial1.print(":");
Serial1.print( String(flowRate2));
Serial1.print("L total:");
Serial1.println(" ");
//////
 // Reset the pulse counter 
    flow_frequency1 = 0;
    flow_frequency2 = 0;
// Enable the interrupt again 
    attachInterrupt(sen1, blink, FALLING);
    attachInterrupt(sen2, blink2, FALLING);
  }
 
}

/* ISR */
void blink() {
  led_state = !led_state; 
  flow_frequency1++;
}
void blink2() {
  led_state2 = !led_state2; 
 flow_frequency2++; // Toggle state value of LED */
}

App for web DB water data upload

Java
No preview (download only).

mesh publish water consumption of city

C/C++
#include "application.h"
SYSTEM_MODE (AUTOMATIC);
SYSTEM_THREAD (ENABLED);

/* Interrupt Functions */
int led2=D13;
int LED = D7;
int sen1= D3;
int sen2=D4;
float calibrationFactor = 4.5;
float flowRate1;
float flowRate2;
unsigned long totalMilliLitres1;
unsigned long totalMilliLitres2;
unsigned long oldTime;
int flowMilliLitres1;
int flowMilliLitres2;
volatile int  flow_frequency1;
volatile int  flow_frequency2;
volatile bool led_state = LOW;
volatile bool led_state2 = LOW;


/* Setup is run once at the start (Power-On or Reset) of sketch */
void setup() 
{
    Serial.begin(9600);
    Serial1.begin(9600);
  pinMode(LED, OUTPUT);
   pinMode(led2, OUTPUT);/* Pin 13 is defined as Output */
  pinMode(sen1, INPUT_PULLUP);
  pinMode(sen2, INPUT_PULLUP);/* Interrupt pin */
  attachInterrupt(sen1, blink, FALLING);
  attachInterrupt(sen2, blink2, FALLING);
  
  
   flow_frequency1        = 0;
    flow_frequency2        = 0;
  flowRate1          = 0.0;
  flowRate2           = 0.0;
   flowMilliLitres1   = 0;
    flowMilliLitres2   = 0;
  totalMilliLitres1  = 0;
   totalMilliLitres2  = 0;
  oldTime           = 0;

  
}

/* Loop runs over and over after the startup function */
void loop()
{
/*
  digitalWrite(LED, led_state);
  digitalWrite(led2, led_state2);
  total1= (flow_frequency/4.5);
  total1= (flow_frequency2/4.5);
  Serial.print("freq");
  Serial.print(flow_frequency);
  Serial.print("freq2");
  Serial.print(flow_frequency2);
  
  Serial.print("total1");
   Serial.print(flow_frequency2);
     Serial.print("total1");
    Serial.print(flow_frequency2);
      Serial.println("kkkk");
  
    */
   if((millis() - oldTime) > 1000)    
  { 
    detachInterrupt(sen1);
         detachInterrupt(sen2);
    flowRate1 = ((1000.0 / (millis() - oldTime)) * flow_frequency1) / calibrationFactor;
    flowRate2 = ((1000.0 / (millis() - oldTime)) * flow_frequency2) / calibrationFactor;
    
    oldTime = millis();
    
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres1 = (flowRate1 / 60) * 1000;
    flowMilliLitres2 = (flowRate1 / 60) * 1000;
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres1 += flowMilliLitres1;
         totalMilliLitres2 += flowMilliLitres2;
    
    ////////////////////////
    // Print the flow rate for this second in litres / minute
    Serial.print("Flow rate1: ");
    Serial.print(flowRate1);  // Print the integer part of the variable
    Serial.print("L/min");
    /////////
    Serial.print("Flow rate2: ");
    Serial.print(flowRate2);  // Print the integer part of the variable
    Serial.print("L/min");
    
    // Print the number of litres flowed in this second
   ///////////////////////////////
    // Print the cumulative total of litres flowed since starting
    Serial.print(" total input Liquid Quantity: ");             // Output separator
    Serial.print(totalMilliLitres1);
    Serial.print("mL"); 
     Mesh.publish("home 1 water consumption in ml", String(totalMilliLitres1));
     Mesh.publish("home 1", String(totalMilliLitres2));
      Particle.publish("home 1 water consumption in ml/min",  String(totalMilliLitres1)+"ml");
      
    //////////////////////////
    Serial.print(" total consumed Liquid Quantity: ");             // Output separator
    Serial.print(totalMilliLitres2);
    Serial.println("mL"); 
    ////////////////////////
///////hc 05
Serial1.print(String(flowRate1));
Serial1.print("l/m");
Serial1.print(":");
Serial1.print( String(totalMilliLitres1));
Serial1.print("L total");
Serial1.print(":");
Serial1.print(String(flowRate1));
Serial1.print("l/m");
Serial1.print(":");
Serial1.print( String(flowRate2));
Serial1.print("L total:");
Serial1.println(" ");
//////
 // Reset the pulse counter 
    flow_frequency1 = 0;
    flow_frequency2 = 0;
// Enable the interrupt again 
    attachInterrupt(sen1, blink, FALLING);
    attachInterrupt(sen2, blink2, FALLING);
  }
 
}

/* ISR */
void blink() {
  led_state = !led_state; 
  flow_frequency1++;
}
void blink2() {
  led_state2 = !led_state2; 
 flow_frequency2++; // Toggle state value of LED */
}

code for subuscribe mesh

C Header File
#include "application.h"
SYSTEM_MODE (AUTOMATIC);
SYSTEM_THREAD (ENABLED);

String new_data;
 int data_int;
void watermeter(const char *event, const char *data){
    String new_data = String(data);
     data_int = new_data.toInt();
}

void setup() {
    Serial.begin(9600);
    Serial1.begin(9600);
    //Mesh.subscribe("distance",watermeter);
    Particle.subscribe("water consumption",watermeter);
    
}

void loop() {
        Serial.print("water consumption ");
    Serial.print(String(new_data));  // Print the integer part of the variable
    Serial.print("L/min");
 
    Particle.publish("home 1 water consumption in ml/min",  String(new_data)+"ml"); 
}

Credits

Ashwini kumar sinha

Ashwini kumar sinha

29 projects • 71 followers
Ashwini kumar sinha a Robotic lover and electronics hobbyist. Works at EFY-I

Comments