smart water distribution system

A smart water distribution system is a hydraulic infrastructure that conveys water from the source to the end-user. when someone illegally tries to open the valve theft will be detected and a message will be sent to the water supply company. After reading so many articles on the internet I was not quite satisfied that’s why I have decided to write in detail on Arduino-based smart distribution system for water.

Working of water distribution system using Arduino

Here we have made an Arduino-based water theft system using P18C as the main controller GSM module and other sensors.

Components used:

  • P18C microcontroller
  • GSM Module
  • Variable resistors                                     
  • Motors
  • Flow sensor
  • Connecting wires            
  • SIM card
  • Mobile Phone

The distribution system is the solution to the modern era. When a consumer will try to theft, an alert will be sent to the water supply company through GSM. we have to use the water level sensor at the beginning of the canal and the end of our fields. we subtract the value of the water level sensor at the end of our field from the water level sensor at the beginning of the canal.

you may like to read

GSM Based Smart Energy Meter

 

circuit diagram:

The image below is the circuit diagram of the Smart water theft system.

                                                       smart water distribution system

How to Measure Current using ACS712

Results

The image below is the simulation-based result of water distribution using Arduino

smart water distribution system
smart irrigation system
                                                       Results of  the water distribution system

Coding (water distribution system using microcontroller and GSM)

                // Defining the variables //
//........................//
#define AD_canal_0 0
#define AD_canal_1 1
#define AD_canal_2 2
#define AD_canal_3 3
#define Threshold 30
unsigned int AD_value_C0;
unsigned int AD_value_C1;
unsigned int AD_value_C2;
unsigned int AD_value_C3;
void Close_all_gate();
int Flow_Freq(void);
int frequency;
char freq[5];

//........................//
// main software
void main() {

  TRISA |=(1<<0)|(1<<1)|(1<<2)|(1<<3);              // PORTA0-3 -->(AN0-3) as inputs
  TRISD &=~(1<<7)&~(1<<6)&(~1<<5)&~(1<<4);          // PORTD7-4 as outputs for servo Motors
  UART1_Init(9600);                                 // initializing UART with 9600 baud
  delay_ms(1000);                                   // Time for GSM to process the command
  Close_all_gate();                                 // Initially,Closing all the gates
  Delay_ms(2000);
// endless loop
  while(1) {
    AD_value_C0 = ADC_Read(AD_canal_0);            // Get 10-bit results of AD conversion
    AD_value_C1 = ADC_Read(AD_canal_1);            // Get 10-bit results of AD conversion
    AD_value_C2 = ADC_Read(AD_canal_2);            // Get 10-bit results of AD conversion
    AD_value_C3 = ADC_Read(AD_canal_3);            // Get 10-bit results of AD conversion
    frequency =Flow_Freq();
    if(frequency<50)
    {
      UART1_Write_Text("Theft Detected");
      UART1_Write('\r\n');
      Delay_ms(2000);
    }

           //checking for field 0
   //----------------------------------//
   if(AD_value_C0>700)
   {
         // need water for field. Open the gate
         PORTD|=(1<<7);
         Delay_us(2000);
         PORTD&=~(1<<7);
         Delay_ms(19);
         UART1_Write_Text("Gate 1 Open");
         UART1_Write('\r\n');
   }
   else if((AD_value_C0>100)&(AD_value_C0<500))
   {
         // no need water. closing the gate
         PORTD|=(1<<7);
         Delay_us(1000);
         PORTD&=~(1<<7);
         Delay_ms(19);
         UART1_Write_Text("Gate 1 Close");
         UART1_Write('\r\n');
   }
   else ;
   //----------------------------------//


            //checking for field 1
   //----------------------------------//
   if(AD_value_C1>700)
   {
         // need water for field. Open the gate
         PORTD|=(1<<6);
         Delay_us(2000);
         PORTD&=~(1<<6);
         Delay_ms(19);
         UART1_Write_Text("Gate 2 Open");
         UART1_Write('\r\n');
   }
   else if((AD_value_C1>100)&(AD_value_C1<500))
   {
         // no need water. closing the gate
         PORTD|=(1<<6);
         Delay_us(1000);
         PORTD&=~(1<<6);
         Delay_ms(19);
         UART1_Write_Text("Gate 2 Close");
         UART1_Write('\r\n');
   }
   else ;
   //----------------------------------//


               //checking for field 2
   //----------------------------------//
   if(AD_value_C2>700)
   {
         // need water for field. Open the gate
         PORTD|=(1<<5);
         Delay_us(2000);
         PORTD&=~(1<<5);
         Delay_ms(19);
         UART1_Write_Text("Gate 3 Open");
         UART1_Write('\r\n');
   }
   else if((AD_value_C2>100)&(AD_value_C2<500))
   {
         // no need water. closing the gate
         PORTD|=(1<<5);
         Delay_us(1000);
         PORTD&=~(1<<5);
         Delay_ms(19);
         UART1_Write_Text("Gate 3 Close");
         UART1_Write('\r\n');
   }
   else ;
   //----------------------------------//


               //checking for field 3
   //----------------------------------//
   if(AD_value_C3>700)
   {
         // need water for field. Open the gate
         PORTD|=(1<<4);
         Delay_us(2000);
         PORTD&=~(1<<4);
         Delay_ms(19);
         UART1_Write_Text("Gate 4 Open");
         UART1_Write('\r\n');
   }
   else if((AD_value_C3>100)&(AD_value_C3<500))
   {
         // no need water. closing the gate
         PORTD|=(1<<4);
         Delay_us(1000);
         PORTD&=~(1<<4);
         Delay_ms(19);
         UART1_Write_Text("Gate 4 Close");
         UART1_Write('\r\n');

   }
   else ;
   //----------------------------------//

  }
}


void Close_all_gate()
{
//gate 1
      PORTD|=(1<<7);
      Delay_us(1000);
      PORTD&=~(1<<7);
      Delay_ms(19);
//gate 2
      PORTD|=(1<<6);
      Delay_us(1000);
      PORTD&=~(1<<6);
      Delay_ms(19);
//gate 3
      PORTD|=(1<<5);
      Delay_us(1000);
      PORTD&=~(1<<5);
      Delay_ms(19);
//gate 4
      PORTD|=(1<<4);
      Delay_us(1000);
      PORTD&=~(1<<4);
      Delay_ms(19);
}
// Checking the water Flow
int Flow_Freq(void)
{
int c=0,i=0,z=0;
TMR1L=0;
TMR1H=0;
T1CON= 0B00000011;
Delay_ms(1000);
T1CON= 0B00000010;
c= TMR1L;
i= TMR1H * 256;
z= c+i;
return z;
}

After reading this article “Smart Water Distribution System” you will be able to make
your project. We have tried to cover each aspect of the Arduino-based water theft
system and will look for more and try to add those in the next update. Have you found
anything interesting? Let us know in the comments section below.



By inham

Inhamullah Jadoon is an Electrical Engineer and Co Founder of geekyengineers.com. He has vast amount of experience in the field of Engineering and in assisting Engineers on Software and Hardware issues.

Leave a Reply

Your email address will not be published. Required fields are marked *