外霍尔水流量传感器0.3-10L/min 3.6-26.4V
生活随笔
收集整理的這篇文章主要介紹了
外霍尔水流量传感器0.3-10L/min 3.6-26.4V
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
紅正,黑伏,黃接D2 (3.6-26.4V)
根據已知的1升的脈沖數計算
#define io_shuiLiu_chuanGanQi 12 long xianZai_Millis = 0; //現在時間 long yiQian_Millis = 0; //以前時間 long timeMillis=0; int jianGe_time = 1000; //間隔時間 volatile byte maiCong_jiShu=0; //脈沖計數 byte pulse1Sec = 0; //脈沖1秒 float liuLiang=0.0; //流量 unsigned int liuLiang_haoSheng=0; //流量毫升 unsigned long liuLiang_haoSheng_zongJi=0; //總計毫升 int maiChong_meiSheng=1319; //每升總共多少脈沖,銅的1L=553HZ±10%void IRAM_ATTR maiCong_jiShuer() {maiCong_jiShu++; }void setup() {Serial.begin(9600);pinMode(io_shuiLiu_chuanGanQi, INPUT);attachInterrupt(digitalPinToInterrupt(io_shuiLiu_chuanGanQi), maiCong_jiShuer, FALLING); }void loop() {xianZai_Millis = millis();timeMillis=xianZai_Millis-yiQian_Millis;if (timeMillis>jianGe_time){ pulse1Sec = maiCong_jiShu;maiCong_jiShu = 0;liuLiang = 1000.0/timeMillis*pulse1Sec/maiChong_meiSheng*60;//L/min yiQian_Millis = millis();liuLiang_haoSheng = liuLiang/60*1000;//mLliuLiang_haoSheng_zongJi += liuLiang_haoSheng; // Print the flow rate for this second in litres / minuteSerial.print("Flow rate: ");Serial.print(liuLiang,1); // Print the integer part of the variableSerial.print("L/min");Serial.print("\t"); // Print tab spaceSerial.print("Output Liquid Quantity: ");Serial.print(liuLiang_haoSheng_zongJi);Serial.print("mL / ");Serial.print(liuLiang_haoSheng_zongJi / 1000);Serial.println("L"); } }中斷測量上升沿測量方式:
volatile int shangShengYan; //測量信號的上升沿 float jiSuan; int io_shuiLiu_chuanGanQi = 2; //傳感器的針腳位置 void rpm () //這是interupt調用的函數 { shangShengYan++; //此功能測量霍爾效應傳感器信號的上升沿和下降沿 } void setup() { pinMode(io_shuiLiu_chuanGanQi, INPUT); //將數字管腳2初始化為輸入Serial.begin(9600); //串口波特率attachInterrupt(io_shuiLiu_chuanGanQi, rpm, RISING); //中斷被附加 } void loop () {shangShengYan = 0; //將NbTops設置為0,以便進行計算sei(); //啟用中斷delay (1000); //等待一秒cli(); //禁用中斷jiSuan = (shangShengYan * 60 / 24); //(脈沖頻率x 60)/7.5Q,=流速(L/小時)Serial.print (jiSuan, 2); //打印上面計算的數字Serial.println (" L/h"); Serial.print (jiSuan/60); //打印上面計算的數字Serial.println (" L/s"); }測量高電平和低電平的時間和,算頻率的計算方式:
const int input = 2; unsigned long X; unsigned long Y; float TIME = 0; float PinLv = 0; float WATER = 0; float TOTAL = 0; float LS = 0; void setup() {Serial.begin(9600);pinMode(input, INPUT); } void loop() {X = abs(pulseIn(input, HIGH));Y = abs(pulseIn(input, LOW));TIME = X + Y;PinLv = 1000000 / TIME;// WATER = PinLv / 7.5;// LS = WATER / 60;// TOTAL = TOTAL + LS;Serial.print(PinLv);//升每小時Serial.println("Hz");Serial.print(PinLv/22*60); Serial.println("L/H");//升每分鐘Serial.print(PinLv/22);Serial.println("L/S");delay(100); }總結
以上是生活随笔為你收集整理的外霍尔水流量传感器0.3-10L/min 3.6-26.4V的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图像视频降噪的现在与未来
- 下一篇: 制作Jexus的Docker镜像