Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
Ashwini kumar sinha
Created August 5, 2020 © MIT

Urban Water Quality Minitor

connected helium network device that monitors the water quality management system that keep track on quality and quantity of water

IntermediateShowcase (no instructions)8 hours549
Urban Water Quality Minitor

Things used in this project

Hardware components

Helium Developer Kit
Helium Developer Kit
×1
Flow Sensor, Pulsed Output
Flow Sensor, Pulsed Output
×1

Story

Read more

Code

Raw code Code

Arduino
#include "LoRaWAN.h"

const char *devEui = "FILL_ME_IN";
const char *appEui = "FILL_ME_IN";
const char *appKey = "FILL_ME_IN";
//////////////////////
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
int flows =0;
String str;
///////////////////////////
// Max Payload 53 Bytes for DR 1
//////////////////////////////////////
String payload[] = "Hello, World!";
char cstr[16];
////////////////////////////////
void flow () // Interrupt function
{
   flow_frequency++;
}
void setup( void )
{
    Serial.begin(9600);
    
    pinMode(flowsensor, INPUT);
   digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
   attachInterrupt(0, flow, RISING); // Setup Interrupt
   //sei(); // Enable interrupts
   currentTime = millis();
   cloopTime = currentTime;
   
    // US Region
    LoRaWAN.begin(US915);
    // Helium SubBand
    LoRaWAN.setSubBand(2);
    // Disable Adaptive Data Rate
    LoRaWAN.setADR(false);
    // Set Data Rate 1 - Max Payload 53 Bytes
    LoRaWAN.setDataRate(1);
    // Device IDs and Key
    LoRaWAN.joinOTAA(appEui, appKey, devEui);

    Serial.println("JOIN( )");
}

void loop( void )
{

 currentTime = millis();
   // Every second, calculate and print litres/hour
   if(currentTime >= (cloopTime + 1000))
   {
      cloopTime = currentTime; // Updates cloopTime
      // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
      l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
      flow_frequency = 0; 
      flows=l_hour;
      // Reset Counter
        }
  
    if (LoRaWAN.joined() && !LoRaWAN.busy())
    {
        Serial.print("TRANSMIT( ");
        Serial.print("TimeOnAir: ");
        Serial.print(LoRaWAN.getTimeOnAir());
        Serial.print(", NextTxTime: ");
        Serial.print(LoRaWAN.getNextTxTime());
        Serial.print(", MaxPayloadSize: ");
        Serial.print(LoRaWAN.getMaxPayloadSize());
        Serial.print(", DR: ");
        Serial.print(LoRaWAN.getDataRate());
        Serial.print(", TxPower: ");
        Serial.print(LoRaWAN.getTxPower(), 1);
        Serial.print("dbm, UpLinkCounter: ");
        Serial.print(LoRaWAN.getUpLinkCounter());
        Serial.print(", DownLinkCounter: ");
        Serial.print(LoRaWAN.getDownLinkCounter());
        Serial.println(" )");

        // Send Packet
       
          
          str = String(flows);
           str.toCharArray(cstr,16);
        LoRaWAN.sendPacket(1, cstr, sizeof(cstr));
    }

    delay(20000); //20 Seconds
}

Credits

Ashwini kumar sinha

Ashwini kumar sinha

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

Comments