STUDENT SUBMIT A COMPLETE DRAFT OF FYP
PROPOSAL REPORT TO SUPERVISOR
Date: 13/5/2019 (Monday) –
31/5/2019 (Friday)
In this week I make a connection wiring to water
level sensor and connect it to the Arduino.
coding
to control the water level
// include libraries
// no libraries required
/********************************/
int sensorPin = A0;
// select the input pin (must be analog) for the water level sensor
module
int GreenPin = 8;
// select the pin for the green LED
//int BluePin = 7;
// select the pin for the blue LED
//int RedPin = 6;
// select the pin for the red LED
int sensorValue = 0; // variable to store the value
coming from the sensor
int speakerPin = 7;
// select the pin for the piezo buzzer
/********************************/
void setup() {
Serial.begin(9600); // initialize serial communications at 9600 bps
pinMode(GreenPin, OUTPUT); //
declare the GreenPin as an OUTPUT
//
pinMode(BluePin, OUTPUT); // declare the
BluePin as an OUTPUT
//pinMode(RedPin, OUTPUT); //
declare the RedPin as an OUTPUT
pinMode(speakerPin,
OUTPUT); // declare the speakerPin as an OUTPUT
}
void loop() {
sensorValue =
analogRead(sensorPin); // read the value from the sensor
// send the
message about water level to serial monitor
if
(sensorValue <= 0) {
Serial.println(“Water level: 0mm – SAVE”);
}
else if
(sensorValue > 0 && sensorValue <= 223) {
Serial.println(“Water lvl:0-5mm”);
}
else if
(sensorValue > 223 && sensorValue <= 251) {
Serial.println(“Water lvl: 5-10mm”);
}
else if (sensorValue
> 251 && sensorValue <= 277) {
Serial.println(“Water lvl: 10-15mm”);
digitalWrite(GreenPin, LOW); //
turn the green LED on
}
else if
(sensorValue > 277 && sensorValue <= 294) {
Serial.println(“Water lvl: 15-20mm”);
digitalWrite(GreenPin,
LOW);
}
else if
(sensorValue > 294 && sensorValue <= 311) {
Serial.println(“Water lvl: 20-25mm”);
digitalWrite(GreenPin, LOW); //
turn the green LED off
//digitalWrite(BluePin, HIGH); //
turn the blue LED on
}
else if (sensorValue
> 311 && sensorValue <= 314) {
Serial.println(“Water lvl: 25-30mm”);
digitalWrite(GreenPin, LOW);
}
else if
(sensorValue > 314 && sensorValue <= 323) {
Serial.println(“Water lvl: 30-35mm”);
digitalWrite(GreenPin, LOW);
digitalWrite(speakerPin, LOW);
}
else if
(sensorValue > 323) {
digitalWrite(GreenPin, HIGH); //
turn the blue LED off
digitalWrite(speakerPin, HIGH); // turn the piezo buzzer on
delay(500);
digitalWrite(speakerPin, LOW);
//digitalWrite(RedPin, HIGH); //
turn the red LED on
Serial.println(“Water lvl: 35-40mm – Alarm! Alarm!”);
}
delay(1000);
// delay 1 second
// take the
sensor out of water slowly or fast or if the water level is going down
// reset the
system when sensor out off the water and dry
//digitalWrite(RedPin, LOW);// turn the red LED off
digitalWrite(speakerPin, LOW);// turn the speakerPin off
//digitalWrite(BluePin, LOW); //
turn the blue LED off
digitalWrite(GreenPin, LOW); //
turn the green LED off
}
As
u can see from the figure above shows that the water level sensor detect the
water and if the water level reaches maximum level it will activate the alarm.


No comments:
Post a Comment