https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=roboholic84&logNo=220534816162
https://blog.daum.net/rockjjy99/2645
https://blog.naver.com/roboholic84/220540393392
액체가 흐르면 내장된 팬이 돌아가고, 그 돌아간 횟수와 빠르기를 측정하여
액체의 양, 펄스값, 속도를 측정할 수 있는 센서입니다.
5V 전압으로 사용할 수 있고, 출력값은 디지털 신호입니다.
액체 유량 센서의 원리
이 센서의 측정원리는 접선류 날개차 방식입니다.
유입구에서 물을 흘러보내면, 날개차를 거쳐 유출구로 빠져나옵니다.
그 과정에서 물의 양에 비례하여 날개차가 회전을 하게 되며,
물의 속도에 비례해 날개차의 회전속도가 변합니다.
즉, 회전횟수에 비례해 물의 양을 구할 수 있으며
회전속도에 비례해 물의 속도를 구할 수 있습니다.
이 센서의 초당 시그널 수를 구하는 공식은
초당 시그널 수 = 8.1 * 분당 유량 - 3 입니다. [ Hz = 8.1 * Flow rate(L/min) - 3 ]
이 공식을 이용하여 초당 유량을 구할 수 있습니다.
(초당 시그널 수-3)/8.1 = 분당 유량이며
(초당 시그널 수 - 3 ) / 486 = 초당 유량입니다.
유량 센서로 유량 측정하기
준비물 : 아두이노 우노, LCD , 유량 센서, 가변저항 1개 , 다량의 점프선, 외부 전원
#include "LiquidCrystal.h"
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 2
// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {
uint8_t x = digitalRead(FLOWSENSORPIN);
if (x == lastflowpinstate) {
lastflowratetimer++;
return; // nothing changed!
}
if (x == HIGH) {
//low to high transition!
pulses++;
}
lastflowpinstate = x;
flowrate = 1000.0;
flowrate /= lastflowratetimer; // in hertz
lastflowratetimer = 0;
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
}
}
void setup() {
Serial.begin(9600);
Serial.print("Flow sensor test!");
lcd.begin(16, 2);
pinMode(FLOWSENSORPIN, INPUT);
digitalWrite(FLOWSENSORPIN, HIGH);
lastflowpinstate = digitalRead(FLOWSENSORPIN);
useInterrupt(true);
}
void loop() // run over and over again
{
lcd.setCursor(0, 0);
lcd.print("Pulses:"); lcd.print(pulses, DEC);
lcd.print(" Hz:");
lcd.print(flowrate);
//lcd.print(flowrate);
Serial.print("Freq: "); Serial.println(flowrate);
Serial.print("Pulses: "); Serial.println(pulses, DEC);
// if a plastic sensor use the following calculation
// Sensor Frequency (Hz) = 7.5 * Q (Liters/min)
// Liters = Q * time elapsed (seconds) / 60 (seconds/minute)
// Liters = (Frequency (Pulses/second) / 7.5) * time elapsed (seconds) / 60
// Liters = Pulses / (7.5 * 60)
float liters = pulses;
liters /= 7.5;
liters /= 60.0;
/*
// if a brass sensor use the following calculation
float liters = pulses;
liters /= 8.1;
liters -= 6;
liters /= 60.0;
*/
Serial.print(liters); Serial.println(" Liters");
lcd.setCursor(0, 1);
lcd.print(liters); lcd.print(" Liters ");
delay(1000);
}
//소스 파일은 첨부하였습니다.https://blog.naver.com/roboholic84/220540393392
#include "LiquidCrystal.h"
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 2
// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {
uint8_t x = digitalRead(FLOWSENSORPIN);
if (x == lastflowpinstate) {
lastflowratetimer++;
return; // nothing changed!
}
if (x == HIGH) {
//low to high transition!
pulses++;
}
lastflowpinstate = x;
flowrate = 1000.0;
flowrate /= lastflowratetimer; // in hertz
lastflowratetimer = 0;
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
}
}
void setup() {
Serial.begin(9600);
Serial.print("Flow sensor test!");
lcd.begin(16, 2);
pinMode(FLOWSENSORPIN, INPUT);
digitalWrite(FLOWSENSORPIN, HIGH);
lastflowpinstate = digitalRead(FLOWSENSORPIN);
useInterrupt(true);
}
void loop() // run over and over again
{
lcd.setCursor(0, 0);
lcd.print("Pulses:"); lcd.print(pulses, DEC);
lcd.print(" Hz:");
lcd.print(flowrate);
//lcd.print(flowrate);
Serial.print("Freq: "); Serial.println(flowrate);
Serial.print("Pulses: "); Serial.println(pulses, DEC);
// if a plastic sensor use the following calculation
// Sensor Frequency (Hz) = 7.5 * Q (Liters/min)
// Liters = Q * time elapsed (seconds) / 60 (seconds/minute)
// Liters = (Frequency (Pulses/second) / 7.5) * time elapsed (seconds) / 60
// Liters = Pulses / (7.5 * 60)
float liters = pulses;
liters /= 7.5;
liters /= 60.0;
Serial.print(liters); Serial.println(" Liters");
lcd.setCursor(0, 1);
lcd.print(liters); lcd.print(" Liters ");
delay(1000);
}
'Sensor > 유량센서' 카테고리의 다른 글
How to use Water Flow Sensor / Meter with Arduino (0) | 2022.03.26 |
---|---|
Arduino Uno 로 YF-S201 액체 유량센서를 사용해서 유량 측정해 보기 (0) | 2022.03.13 |
How to use Water Flow Sensor / Meter with Arduino (0) | 2022.03.12 |
Reading Water Flow Rate from a flow meter. (0) | 2022.02.25 |
1 inch Brass Water Flow Sensor SEN-HZG1WA (0) | 2022.02.25 |