Академический Документы
Профессиональный Документы
Культура Документы
Effective water management involves supplying water according to the real requirement, and thus
measuring water is very essential step in water management systems. There are many water flow
measurement techniques as well as different types of water flow meters used to measure the volume
of water flow in pipelines but these all are too costly. This article describes ideas for design and
development of low cost automatic water flow meters, with the help of readily-available and low-
cost water flow sensors.
Software Preparation
The Arduino Sketch (code) uses the external interrupt (int 0) on Arduino’s digital pin 2 (D2). This is
used to read the output pulses coming from the water flow sensor. When Arduino detects the pulse,
it immediately triggers the pulseCounter() function. This function then counts the total number of
pulses detected (wanna know more about interrupts? http://playground.arduino.cc/Main/AVR).
/*
YF‐ S201 Water Flow Sensor
Water Flow Sensor output processed to read in litres/hour
Adaptation Courtesy: www.hobbytronics.co.uk
*/
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
flow_frequency++;
}
void setup()
{
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
Serial.begin(9600);
attachInterrupt(0, flow, RISING); // Setup Interrupt
sei(); // Enable interrupts
currentTime = millis();
cloopTime = currentTime;
}
void loop ()
{
currentTime = millis();
// Every second, calculate and print litres/hour
if(currentTime >= (cloopTime + 1000))
{
cloopTime = currentTime; // Updates cloopTime
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/
hour
flow_frequency = 0; // Reset Counter
Serial.print(l_hour, DEC); // Print litres/hour
Serial.println(" L/hour");
}
}
Flow sensors typically output a series of pulses proportional to the instantaneous flow rate which
means that to interpret them it is necessary to implement a simple frequency counter. Since this
project uses a water flow sensor containing a Hall-Effect sensor that outputs a pulse rate
proportional to flow rate, so not only is it a useful project in its own right but it also demonstrates a
very useful technique that you can use in a wide range of projects that need to measure the rate at
which something happens (an electronic wind instrument, for example).
In other words:
Really it was an awkward midnight experiment. We (me and my lab engineer diya missy) rolled up
our sleeves and started the process with wet-hands. At first we made a simple construction
comprised a rubber tube, plastic funnel, water flow sensor, and water bottles. Next we connected the
water flow sensor’s output to the Arduino board (filled with the sketch) and allowed water flow
through the water flow sensor at a steady rate of about 1 Litre/minute. Besides the Arduino’s serial
monitor, we also used our DSO to measure pulse output from the water flow sensor. In that crude
experiement, serial monitor displayed a rate of 56 Litre/hour (in lieu of the expected 60 Litre/hour
rate)!
Since this experiment is now at the halfway mark, you can expect inspiring updates in due time.
Meanwhile, refer all related projects on pulse/frequency counting with microcontrollers, published
in this website to keep your interest alive. An example
link: https://www.electroschematics.com/10494/arduino-optical-position-rotary-encoder/
ự án tự động bật tắt máy bơm nước - Sử dụng
module relay và siêu âm
Bui Thang gửi vào Thứ hai, 25 Tháng 7, 2016 - 08:42
Từ bài viết Dự án bật tắt máy bơm nước - Tự bơm nước khi hết nước - Sử dụng module
relay và siêu âm, mình có 1 hướng mới cho Project này để tiết kiệm chi phí, phù hợp ứng
dụng thực tế hơn nữa: dùng LED để hiển thị mực nước còn lại, thêm nút bật tắt máy bơm
bằng tay để có thể bật tắt máy bơm bất kỳ lúc nào
I. Sơ đồ
Sơ đồ mạch của mình tương tự bài viết Dự án bật tắt máy bơm nước - Tự bơm nước khi hết nước -
Sử dụng module relay và siêu âm, các bạn tham khảo thêm nhé.
Mình chỉ thêm phần hiển thị mực nước bằng LED và nút bấm để bật tắt bằng tay.
Mình cũng mới chỉ mô phỏng trên Proteus (do chưa có thời gian làm mạch thật). Sơ đồ mạch như
sau:
II. Lập trình
// Project bật tắt máy bơm tự động sử dụng HC-SR04, by Bùi Văn Thắng -
Tastywin@gmail.com
// Hiển thị mực nước bằng LED
// Có nút bật tắt máy bơm bằng tay
// Tham khảo các nguồn khác nhau trên arduino.vn
byte ledPin[] = {A5,A4,A3,A2,A1,A0}; // Mảng lưu vị trí các chân đèn LED
byte pinCount; // Khai báo biến pinCount dùng cho việc lưu tổng số chân LED
byte muc_nuoc = 2;
int moc_tren = 780; // Thay đổi theo thực tế
int moc_duoi = 330; // Thay đổi theo thực tế
bool relay_status = 0; // Trạng thái relay: 0 là tắt, 1 là bật
void setup()
{
Serial.begin(9600); // giao tiếp Serial với baudrate 9600
pinMode(trig,OUTPUT); // chân trig sẽ phát tín hiệu
pinMode(echo,INPUT); // chân echo sẽ nhận tín hiệu
pinMode(relay,OUTPUT);
void loop()
{
unsigned long duration; // biến đo thời gian
int distance; // biến lưu khoảng cách
// thiet lap muc nuoc su dung xuong moc_tren thi tu dong bat relay
if (distance > moc_tren)
{
digitalWrite (relay, HIGH);
relay_status = 1;
}
// thiet lap muc nuoc len den moc_duoi thi tu dong tat relay
if (distance < moc_duoi)
{
digitalWrite (relay, LOW);
relay_status = 0;
}
bat_led();
void tat_led() {
for (byte i = 0;i < pinCount; i++) {
digitalWrite(ledPin[i],LOW); // Tắt đèn
}
}
void bat_led() {
for (byte i=0; i < muc_nuoc; i++) {
digitalWrite(ledPin[i],HIGH); //Bật đèn
}
}
void bat_tat_relay() {
relay_status = !relay_status; // Đảo trạng thái relay
digitalWrite(relay,relay_status); // Xuất giá trị của relay
}
III. Thành quả
Bài viết của mình chưa được kiểm nghiệm thực tế, nhưng cũng mong là truyền được cảm hứng đến
các bạn cho việc ứng dụng vào thực tế.
Khi hết nước tự động bơm, khi nước đầy tự động tắt bơm (về khoảng cách mình để trong mạch là
theo mô phỏng trên Proteus nhé, các bạn căn chỉnh ở thực tế và đưa vào giá trị chính xác)
Trạng thái mực nước được chỉ thị theo 6 LED (có thể mở rộng thêm nhiều LED tùy ý)
Khi ở mực nước thấp (chỉ còn 2 LED đỏ chỉ thị), 2 đèn LED đỏ sẽ nhấp nháy để cảnh báo
Có thể dùng Button để Bật hay Tắt máy bơm bất kỳ lúc nào