Sie sind auf Seite 1von 7

/*

* This code was created by Mike Kasiita17/U/15760 on


8/05/2019
*

*/

#include <LiquidCrystal.h>

#include <Key.h>

#include <Keypad.h>

#include <SoftwareSerial.h>

SoftwareSerial mySerial(11, 3);

const byte ROWS = 4; //four rows

const byte COLS = 3; //three columns

char keys[ROWS][COLS] = {

{'1','2','3'},

{'4','5','6'},

{'7','8','9'},

{'*','0','#'}

};

byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {6, 5, 4}; //connect to the column pinouts of the keypad

LiquidCrystal lcd(A0,A1,A2,A3,A4,A5 );

Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

//=================================variables for flow


sensor===================================

int X;

int Y;

float TIME = 0;
float FREQUENCY = 0;

float WATER = 0;

float TOTAL = 0;

float LS = 0;

const int input = 2;

//==============================variables for the


motor======================================

const int pwm = 11 ; // initializing pin 2 as pwm

const int in_1 = 12 ;

const int in_2 = 13 ;

// for providing logic to L293D to choose the direction of the motor

char keycount =0;

char code [4]; //Hold pressed keys

void setup()

mySerial.begin(9600); // Setting the baud rate of GSM Module

lcd.begin(16,2); // set up the LCD's number of columns and rows:

lcd . print ("AUTOMATIC WATER :");

lcd.setCursor(0,1);

lcd . print ("METERING SYSTEM :");

delay(4000);

lcd.clear();

lcd . print ("ENTER PSWD:"); // Print a customkey to the LCD.

lcd . setCursor (0,1); //Move coursor to second Line

lcd . cursor (); // Turn on the cursor

//==============================setting motor pins===============================

pinMode(pwm, OUTPUT) ; // set pwm as output


pinMode(in_1, OUTPUT) ; // logic pin set as output

pinMode(in_2, OUTPUT) ; // logic pin set as output

digitalWrite(in_1,HIGH);

//==================================loops the program


forever================================================

void loop()

char customKey = customKeypad.getKey ();

if ( customKey && ( keycount <4) && ( customKey !='*') && ( customKey !='#')){

lcd . print ('*'); //lcd.print(customKey); //To display entered keys

code [ keycount ]= customKey ;

keycount ++;

if( customKey == '*') //Check Password and Unlock

if(( code [0]=='1') && ( code [1]=='2') && ( code [2]=='3') && ( code [3]=='4'))

//Match the password. Default password is “1234”

// for clock wise motion of motor, in_1 = High, in_2 = low

openValve();

delay(2000);

waterFlow();

if( customKey == '#') //Cancel/Lock Key is pressed clear display and lock

{
Lock (); //Lock and clear display

SendMessage();

pswd();

//===================================================================================
==========

// LOCK and Update Display

//===================================================================================
==========

void pswd(){

lcd.clear();

lcd.print("ENTER PSWD:");

lcd . setCursor (0,1);

keycount =0;

//===================================================================================
=========

//function for closing the gate valve to stop water from flowing

//===================================================================================
===========

void Lock ()

{ digitalWrite(in_1,HIGH) ;

digitalWrite(in_2,LOW) ;

delay(1000);

lcd . setCursor (0,1);

lcd . print (" VALVE CLOSED ");

lcd . setCursor (0,1);

lcd . print (" "); //Clear Password

lcd . setCursor (0,1);


//delay (5000);

//===================================================================================
============

//function for openning the gate valve to allow water to flow

//===================================================================================
=============

void openValve(){

lcd.clear();

lcd.setCursor(0,0);

lcd . print ("VALVE OPENING ");

digitalWrite(in_1,LOW) ;

digitalWrite(in_2,HIGH) ;

delay(1000);

//===================================================================================
================

//function for calculating water flow rate

//===================================================================================
=================

void waterFlow(){

int count;

lcd.clear();

lcd.setCursor(0,0);

lcd.print("VOL. :0.00");

lcd.setCursor(0,1);

lcd.print("TOTAL:");

lcd.print( TOTAL);
lcd.print("L");

//delay (3000);

X = pulseIn(input, HIGH);

Y = pulseIn(input, LOW);

TIME = X + Y;

FREQUENCY = 1000000/TIME;

WATER = FREQUENCY/12;

LS = WATER;

if(FREQUENCY >= 0)

if(isinf(FREQUENCY))

lcd.clear();

lcd.setCursor(0,0);

lcd.print("VOL. :0.00");

lcd.setCursor(0,1);

lcd.print("TOTAL:");

lcd.print( TOTAL);

lcd.print("L");

else

TOTAL = TOTAL + LS;

lcd.println(FREQUENCY);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("VOL.: ");

lcd.print(WATER);
lcd.print(" L/M");

lcd.setCursor(0,1);

lcd.print("TOTAL:");

lcd.print( TOTAL);

lcd.print("L");

delay(3000);

TOTAL++;

//==================================================================================

//function for sending the text message to the phone

//===================================================================================
======

void SendMessage()

waterFlow();

mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode

delay(1000); // Delay of 1000 milli seconds or 1 second

mySerial.println("AT+CMGS=\"+256751126760\"\r"); // Replace x with mobile number

delay(1000);

mySerial.print("Volume of water= ");

mySerial.print(TOTAL);

mySerial.println("litres");

delay(100);

mySerial.println((char)26);// ASCII code of CTRL+Z

delay(1000);

Das könnte Ihnen auch gefallen