Created
May 31, 2017 10:20
-
-
Save prasant1010/08d77c4c58be8f96a7fff06e0bd59248 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); | |
byte sensorPin[] = {0,1,2,3,4,5,6,7}; | |
byte ledPin[] = {17,16,15,14}; // number of leds = numbers of sensors | |
const byte sensors = 8; | |
const byte leds=4; | |
int motor = A4; | |
int buzzer = A5; | |
void setup() | |
{ | |
for(int i = 0; i< sensors; i++) //initialize all sensor pins to input pin | |
{ | |
pinMode(sensorPin[i], INPUT); | |
} | |
for(int i = 0; i< leds; i++) //initialize all led pins to output pins | |
{ | |
pinMode(ledPin[i], OUTPUT); | |
} | |
pinMode(motor, OUTPUT); //initialize motor pin to output pin | |
lcd.begin(20, 4); //initializing 20x4 LCD | |
lcd.clear(); //clear LCD first | |
lcd.print("ELECTRONIFY.ORG"); // display string electronify.org | |
} | |
void loop() | |
{ | |
int level = 0; | |
for(int i = 0; i < sensors; i++) | |
{ | |
if(digitalRead(sensorPin[i]) == HIGH) | |
{ | |
digitalWrite(ledPin[i/2], HIGH); | |
level = i+1; | |
} else | |
{ | |
digitalWrite(ledPin[i/2], LOW); | |
} | |
} | |
lcd.setCursor(0,1); | |
lcd.print("WATER LEVEL MEASURE"); | |
lcd.setCursor(0,2); | |
switch(level) { | |
case 1: | |
lcd.print("LEVEL 1"); | |
digitalWrite(motor, HIGH); | |
break; | |
case 2: | |
lcd.print("LEVEL 2"); | |
digitalWrite(motor, HIGH); | |
break; | |
case 3: | |
lcd.print("LEVEL 3 "); | |
digitalWrite(motor, HIGH); | |
break; | |
case 4: | |
lcd.print("LEVEL 4 "); | |
digitalWrite(motor, LOW); | |
break; | |
case 5: | |
lcd.print("LEVEL 5 "); | |
digitalWrite(motor, LOW); | |
break; | |
case 6: | |
lcd.print("LEVEL 6 "); | |
digitalWrite(motor, LOW); | |
break; | |
case 7: | |
lcd.print("LEVEL 7 "); | |
digitalWrite(motor, LOW); | |
break; | |
case 8: | |
lcd.print("LEVEL 8 "); | |
digitalWrite(motor, LOW); | |
lcd.setCursor(0,3); | |
lcd.print("WARNING : OVERFLOW"); | |
for(int j = 0; j< 255; j++) | |
{ | |
analogWrite(buzzer, j); | |
delay(10); | |
} | |
break; | |
default: | |
lcd.print("NO WATER"); | |
digitalWrite(motor, HIGH); | |
break; | |
} | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment