مقياس تدفق الماء و التحكم بالكمية باستخدام الاردوينو

متوسط

image_pdf

تحديد عدد نبضات لتر واحد من الماء

 مواصفات المنتج أن 450 نبضة للتر واحد من الماء لكن للوصول لقراءة دقيقة سنقوم بعملية الوزن ،عن طريق أخذ قراءة عدد النبضات عند تمرير لتر واحد من الماء

الكود البرمجي 

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13); //Pines arduino to lcd

//-------Pins-----//
int Relay = 1; //Solenoid valve open/close
int start_stop = 2; //Start/Stop button
const int sensor_pulse = 16; //Sensor pulse
int rst_cnt = 3; // Reset counter button
//---------Storage debounce function-----//
boolean currentstart_stop = LOW; 
boolean laststart_stop =LOW; 
boolean lastsensor_pulse = LOW;
boolean currentsensor_pulse = LOW;
boolean lastrst_cnt = LOW;
boolean currentrst_cnt = LOW;
boolean RelayState = LOW; 

int counter = 0;

void setup() {
pinMode(Relay, OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(5, 0);
lcd.print("COUNTER");
lcd.setCursor(0, 1);
lcd.print("PULSES");

}
//----Debouncing function----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(5);
current = digitalRead(pin);
}
return current;
}

void loop() { 
currentstart_stop = debounce(laststart_stop, start_stop); //Debounce for Start/Stop Button
currentsensor_pulse = debounce(lastsensor_pulse, sensor_pulse); //Debounce for Sensor pulse Button
currentrst_cnt = debounce(lastrst_cnt, rst_cnt); //Debounce for reset counter Button

//-----Start/Stop toggle function----//
if (currentstart_stop == HIGH && laststart_stop == LOW){

if (RelayState == HIGH){ //Toggle the state of the Relay
digitalWrite(Relay, LOW);
RelayState = LOW;


} 
else{
digitalWrite(Relay, HIGH);
RelayState = HIGH;
}
}

laststart_stop = currentstart_stop;

if (lastsensor_pulse== LOW && currentsensor_pulse == HIGH){
counter=counter+ 1;
}
lastsensor_pulse = currentsensor_pulse;

lcd.setCursor(7, 1);
lcd.print(counter);

if(RelayState == LOW){ //Reset counter while sistem is not running
if (currentrst_cnt == HIGH && lastrst_cnt == LOW){//Reset Counter
lcd.setCursor(6, 1); // Clear CNT area
lcd.print(" ");
counter= 0; 

}
lastrst_cnt = currentrst_cnt; 
}

}// end void loop

شرح الكود البرمجي 

استدعاء مكتبة الشاشة الكرستالية، و تعريف المنافذ للشاشة

 #include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13); //Pines arduino to lcd

تعريف منافذ الحساس تم توصيله مع منفذ A2= 16، و تسمية المتغير sensor_pulse، كذلك تعريف منفذ مفتاح التحكم بتشغيل النظام و هو المنفذ رقم 3 و منفذ مفتاح التحكم بتصفير العداد و هو المنفذ رقم 2

//-------Pins-----//
int Relay = 17; //Solenoid valve open/close
int start_stop = 2; //Start/Stop button
const int sensor_pulse = 16; //Sensor pulse
int rst_cnt = 3; // Reset counter button

تعين الحالة الابتدائية للمتغرات

boolean currentstart_stop = LOW; 
boolean laststart_stop =LOW; 
boolean lastsensor_pulse = LOW;
boolean currentsensor_pulse = LOW;
boolean lastrst_cnt = LOW;
boolean currentrst_cnt = LOW;
boolean RelayState = LOW; 

int counter = 0;

في دالة void setup نقوم بتهيئة الشاشة وتعريف منافذ الادخال و الاخراج

void setup() {
pinMode(Relay, OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(5, 0);
lcd.print("COUNTER");
lcd.setCursor(0, 1);
lcd.print("PULSES");

}
//----Debouncing function----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(5);
current = digitalRead(pin);
}
return current;
}

في دالة void loop يتم حساب عدد النبضات و عرضها على الشاشة الكرستالية

void loop() { 
currentstart_stop = debounce(laststart_stop, start_stop); //Debounce for Start/Stop Button
currentsensor_pulse = debounce(lastsensor_pulse, sensor_pulse); //Debounce for Sensor pulse Button
currentrst_cnt = debounce(lastrst_cnt, rst_cnt); //Debounce for reset counter Button

//-----Start/Stop toggle function----//
if (currentstart_stop == HIGH && laststart_stop == LOW){

if (RelayState == HIGH){ //Toggle the state of the Relay
digitalWrite(Relay, LOW);
RelayState = LOW;


} 
else{
digitalWrite(Relay, HIGH);
RelayState = HIGH;
}
}

laststart_stop = currentstart_stop;
if (lastsensor_pulse== LOW && currentsensor_pulse == HIGH){
counter=counter+ 1;
}
lastsensor_pulse = currentsensor_pulse;
lcd.setCursor(7, 1);
lcd.print(counter);
if(RelayState == LOW){ //Reset counter while sistem is not running
if (currentrst_cnt == HIGH && lastrst_cnt == LOW){//Reset Counter
lcd.setCursor(6, 1); // Clear CNT area
lcd.print(" ");
counter= 0; 
}
lastrst_cnt = currentrst_cnt; 
}
}// end void loop

قم بحفض القيمة لكل لتر من الماء ليتم تعديلها في الشفرة البرمجية للمشروع

X
Product added to the cart