Open PragatiVerma18 opened 4 years ago
Hello @PragatiVerma18 @ramanaditya I'll like to make a contribution to the following:
My Solution: For this we will have to implement a finite state machine. For our particular problem, I would implement a machine with three states: IDLE, ARMED and ALARM, the ALARM state being the only one in which the buzzer is on. The transitions would be: (Say time for ALARM to sound is 15 seconds)
ARMED → ALARM when the level hits 100% ALARM → IDLE after 15 seconds spent in the ALARM state IDLE → ARMED when the level gets below 90%
Note that the only difference between IDLE and ARMED is that the IDLE state will not go into ALARM when the level reads 100%, as you have to go through the ARMED state before. The threshold at 90% percent (can be changed as desired, added to maintain any lag in working).
#define trigPin 8
#define echoPin 9
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int BUZZER = 10 ;
void setup(){
int duration,distance,percentage,heightTank;
Serial.begin (9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
lcd.begin(16,2);
lcd.print("HELLO");
pinMode(BUZZER,OUTPUT);
}
void loop(){
int duration,distance,percentage,heightTank,deviation;
// We can change the next 2 lines.
// The first one is the max. level of the water.
// The next one is how high the sensor is above that max. level.
heightTank=65;
deviation=4;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin,HIGH);
distance=(duration/2)/29.1;
percentage=100-(((distance-deviation)*100)/heightTank);
Serial.println(distance);
Serial.println(percentage);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Current tank");
//lcd.print(distance);
//lcd.print(" cm");
lcd.setCursor(0,1);
lcd.print("level: ");
lcd.print(percentage);
lcd.print(" %");
delay(1000);
digitalWrite(BUZZER,HIGH);
static unsigned long lastBuzzer = 0;
if(percentage > 99 && lastBuzzer == 0) {
lastBuzzer = millis();
}
if(percentage > 99) {
if(millis() - lastBuzzer < 15000L) {
digitalWrite(BUZZER,HIGH);
delay(100);
digitalWrite(BUZZER,LOW);
delay(100);
}
} else {
digitalWrite(BUZZER,LOW);
lastBuzzer = 0;
}
}
lastBuzzer is the last buzzer activation time (in ms). It's use to control that buzzing stop after 15 seconds. It's zero when the percentage is < 99; it's not zero when percentage >= 100.
The code is based on finite state machine where the state is implicitly encoded into the variables lastBuzzer
and percentage
. The implicit state is:
ARMED when lastBuzzer == 0
ALARM when percentage > 99 && millis() - lastBuzzer < 15000L
IDLE when percentage > 99 && millis() - lastBuzzer >= 15000L
The line lastBuzzer = 0
establishes the ARMED
state as soon as percentage ≤ 99
@ramanaditya @vinitshahdeo please look in this issue. Well, this is the hardware solution, I meant an alarm for the web app.
Hello @PragatiVerma18 thanks a lot for the clarification. Still, the same issue might arise in the case of Hardware. Can we modify this issue for Hardware and open one specific for App? "Add an alarm to indicate that the tank is about to overflow for the Hardware System" We can use the code in PR as the base code and while compiling the final code change the buzzer output to a signal to be transmitted as an alert. The importance of the code will help us to understand:
https://github.com/vinitshahdeo/Water-Monitoring-System/issues/54#issuecomment-593084628 @animeshsrivastava24 , this is not required as of now with hardware, on the webapp side we will be using notification to display the water level. Reasons why we aren't using it with hardware
Why we should use alarm
For now we are okay with the notification part later we can figure it out.
cc: @vinitshahdeo @PragatiVerma18
@ramanaditya Thanks a lot for the feedback.
Hello, I would like to work on this issue.
@IuliaElizaS , sure you can work on this issue.
Hi, I would like to work on this issue. Can you please assign me on this issue?
@IuliaElizaS please start working on this issue and keep me updated about the progress.
@PragatiVerma18 Hi, I've made a PR for this issues more than 2 weeks ago. It was aproved by @vinitshahdeo but not merged ... I don't know why... If i did something wrong during the PR, please tell me. It the first time I'm doing this.
Here is the link for the PR https://github.com/vinitshahdeo/Water-Monitoring-System/pull/203
Thank you
Is your feature request related to a problem? Please describe. An alarm would be a good feature to indicate and alert the owner of the tank that it is about to get filled and would be overflowing in a few minutes.
Describe the solution you'd like Add an alarm such that it rings when the water level approaches 100% or as required by the owner. It should stop ringing once the user sets it off or once the water level becomes steady.