Sumit Kumar
Published © GPL3+

Water Bank Powered by IoT

Monitor your daily water usage, donate water for remote areas, crop plantation using IoT.

BeginnerWork in progress14 hours1,186

Things used in this project

Hardware components

Argon
Particle Argon
×1
Gravity: Digital 5A Relay Module
DFRobot Gravity: Digital 5A Relay Module
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
Rocker Switch, Non Illuminated
Rocker Switch, Non Illuminated
×1
Battery, 3.7 V
Battery, 3.7 V
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
MIT App Inventor
MIT App Inventor
Firebase
Google Firebase

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Soldering iron (generic)
Soldering iron (generic)
Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter

Story

Read more

Schematics

Diagrams

Code

Water Bank

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>
#include <SparkJson.h>
#include <LiquidCrystal_I2C_Spark.h>

#define DHTPIN 2    
#define DHTTYPE DHT11	

void flow();

LiquidCrystal_I2C *lcd;
DHT dht(DHTPIN, DHTTYPE);
unsigned long previousMillis = 0;
int flowSensor = D4;
int pump = D5;

float dPoint = 0.0;
float hIndex = 0.0;
float temp = 0.0;
float humid = 0.0;
const int sensorMin = 0; 
const int sensorMax = 1024; 
// water flow meter variables
volatile int count; //measuring the rising edges of the signal
double volume = 0.0;
float donateAmount = 0.0;

void setup()
{
  Particle.subscribe("hook-response/Database", myHandler, MY_DEVICES);
  Particle.subscribe("hook-response/Read", dataRead, MY_DEVICES);
  Serial.begin(9600);
  dht.begin();
  pinMode(flowSensor, INPUT); //initializes digital pin 5 as an input
  attachInterrupt(D5, Flow, RISING); //and the interrupt is attached on Pin 5
  pinMode(pump,OUTPUT);
  lcd = new LiquidCrystal_I2C(0x27, 16, 2);
  lcd->init();
  lcd->backlight();
  lcd->clear();
  lcd->print("*** Welcome ***");
  previousMillis = millis();
  Particle.publish("Read", "", PRIVATE);
}

void myHandler(const char *event, const char *data) {
  // Handle the integration response
}

void loop() 
{ 
   interrupts();    
   count = 0;      
   delay (1000);      //Wait 1 second
   noInterrupts();
   volume = (count * 2.25);        //Take counted pulses in the last second and multiply by 2.25mL 
   volume = volume / 1000;       //Convert mL to Liters, giving you Liters 
   Serial.println(volume);    
   if(volume==donateAmount)
   {
      digitalWrite(pump,LOW);
      resetWaterAmt();
   }
   if(millis()-previousMillis>600000)
   {
       publishData();
       Particle.publish("Read", "", PRIVATE); // only after every hour you have option to donate
   }
  
}
void resetWaterAmt()
{
    donateAmount = 0;
    char buf[128];
	snprintf(buf, sizeof(buf), "{\"sendL\":%.2f}", donateAmount);
	Serial.printlnf("publishing %s", buf);
	Particle.publish("Database", buf, PRIVATE);
	delay(3000);
}

void Flow ()     //This is the function that the interupt calls 
{ 
    count++;  //This function measures the rising and falling edge of the hall effect sensors signal
}


void readDht()
{
    // Wait a few seconds between measurements.
	delay(2000);
	float h = dht.getHumidity();
    float t = dht.getTempCelcius();                                  // Read temperature as Celsius
	float f = dht.getTempFarenheit();                                // Read temperature as Farenheit
  
	if (isnan(h) || isnan(t) || isnan(f))                            // Check if any reads failed and exit early (to try again).
	{
		Serial.println("Failed to read from DHT sensor!");
		return;
	}

	float hi = dht.getHeatIndex();                                   // Compute heat index
	float dp = dht.getDewPoint();
	float k = dht.getTempKelvin();
	
	humid = h;
	temp = t;
	dPoint = dp;
	hIndex =hi;
}

// unfortunately my rain sensor is not working but code would be like this 
void rainSensor()
{
  int sensorReading = analogRead(A5);
  int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
  lcd->setCursor(0,0);
  switch (range)
    {
      case 0:
       
        lcd->print("RAINING");
        break;

      case 1:
        lcd->print("RAIN WARNING");
        break;

      case 2:
        lcd->print("NOT RAINING");
        break;
    }
  delay(1000); 
}

void dataRead(const char *event, const char *data) 
{
    StaticJsonBuffer<255> jsonBuffer;
    char *mutableCopy = strdup(data);
    JsonObject& root = jsonBuffer.parseObject(mutableCopy);
    free(mutableCopy);
    donateAmount = atof(root["sendL"]);
    if(donateAmount>0)
    digitalWrite(pump,HIGH);
}

void publishData() 
{
	char buf[256];
	snprintf(buf, sizeof(buf), "{\"temp\":%.2f,\"humid\":%.2f,\"dp\":%.2f,\"hi\":%.2f}",
	temp, humid, dPoint, hIndex);
	Serial.printlnf("publishing %s", buf);
	Particle.publish("Database", buf, PRIVATE);
	delay(3000);
}
        

App setup files

Credits

Sumit Kumar

Sumit Kumar

32 projects • 97 followers
19 y/o. My daily routine involves dealing with electronics, code, distributed storage and cloud APIs.

Comments