Smart water Distribution System

0
577
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.

Working and Explanation

Here we have made a smart 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 smart water 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 at 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 distribution system.

smart water distribution system

Results

smart water distribution system
smart irrigation system
Results of the smart 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;
}

Leave a Reply