Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( Correct this code Node MCU for water level detection ) #define BLYNK _ TEMPLATE _ ID TMPL 6 h 1 0 qEPlA #define

(Correct this code Node MCU for water level detection )
#define BLYNK_TEMPLATE_ID "TMPL6h10qEPlA"
#define BLYNK_TEMPLATE_NAME "water level"
#define BLYNK_AUTH_TOKEN "aQLXsDLKNKzBjMs55sRXvJyImkA0UdGl"
#include
#include
#define BLYNK_PRINT Serial
#include
#include
LiquidCrystal_I2C lcd(0x27,16,2);
const int lowWaterLevelThreshold =2; // Adjust this value based on your requirements
char auth[]= "aQLXsDLKNKzBjMs55sRXvJyImkA0UdGl";
char ssid[]= "Islington-College";
char pass[]="I$LiNGT0N2023";
BlynkTimer timer;
bool pinValue =0;
// Define pins for ultrasonic
int const trigPin = D3;
int const echoPin = D4;
// Define pins for buzzer
int const buzzPin = D6;
// Define pins for motor
int const motorPin = D5;
// Define pins for bulb
int const bulbPin = D7;
int waterLevel =0; // Initial water level
int yourMotionThreshold =20; // Adjust this value based on your sensor and environment
void setup(){
lcd.init();
lcd.begin(16,2); // Adjust the numbers based on your LCD specifications
lcd.backlight();
Wire.begin(D2, D1);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzPin, OUTPUT);
pinMode(motorPin, OUTPUT);
pinMode(bulbPin, OUTPUT);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(10L, Wlevel);
digitalWrite(motorPin, HIGH);
digitalWrite(bulbPin, HIGH); // Assuming bulb is off initially
}
void loop(){
Blynk.run();
timer.run();
// Duration will be the input pulse width, and distance will be the distance to the obstacle in centimeters
int duration, distance;
// Output pulse with 1ms width on trigPin
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the pulse input in echo pin
duration = pulseIn(echoPin, HIGH);
// Distance is half the duration divided by 29.1(from datasheet)
distance =(duration /2)/29.1;
// If distance is less than 0.5 meters and more than 0(0 or less means over the range)
if (distance <=60 && distance >=0){
digitalWrite(buzzPin, HIGH); // Buzz
lcd.setCursor(3,0);
lcd.print("Tank Full");
pinMode(motorPin, LOW);
digitalWrite(bulbPin, HIGH); // Assuming bulb should be ON when tank is full
} else {
digitalWrite(buzzPin, HIGH);
pinMode(motorPin, LOW);
lcd.setCursor(3,0);
lcd.print("Hydro Sync");
digitalWrite(bulbPin, LOW); // Assuming bulb should be OFF when the tank is not full
// Check if water level is low and turn on the motor
if (waterLevel < lowWaterLevelThreshold){
pinMode(motorPin, LOW);
} else {
pinMode(motorPin, HIGH);
}
}
delay(500); // Delay for stability
}
void Wlevel(){
digitalWrite(trigPin, LOW);
delayMicroseconds(4);
digitalWrite(trigPin, HIGH);
delayMicroseconds(6);
digitalWrite(trigPin, LOW);
long t = pulseIn(echoPin, HIGH);
long cm = t /29/2;
const int IncrementThreshold =5;
// Update water level based on motion detection
if (cm < yourMotionThreshold){
waterLevel++; // Increment water level
} else {
// Optionally, set a specific threshold for decrementing the water level
const int decrementThreshold =5;
if (cm > decrementThreshold && waterLevel >0){
waterLevel--; // Decrement water level
}
}
// Update Blynk with the new water level
Blynk.virtualWrite(V1, waterLevel);
Serial.println(waterLevel); // Print water level to Serial Monitor
lcd.setCursor(0,0);
lcd.print("Water Level: ");
lcd.print(waterLevel); // Display water level on LCD
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions