广告招募

当前位置:全球装备网 > 技术中心 > 所有分类

Arduino与霍尔水流量传感器编程实例

2025年05月21日 13:02:58      来源:山东信准电子科技有限公司 >> 进入该公司展台      阅读量:20

分享:

此实例来源于网络,我司不负责解释和答疑,敬请谅解。



Image

Once you have it wired up you will need to upload the following code to your Seeeduino. Once it is uploaded and you have some fluid flowing through the Water Flow Sensor, you can open the serial monitor and it will display the flow rate, refreshing every second. 

Here is the code

// reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com
// Code adapted by Charles Gantt from PC Fan RPM code written by Crenn
// http:/ http://

volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                               
int hallsensor = 2;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls 

  NbTopsFan++;  //This function measures the rising and falling edge of the 

hall effect sensors signal

// The setup() method runs once, when the sketch starts
void setup() //

  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  Serial.begin(9600); //This is the setup function where the serial port is 

initialised,
  attachInterrupt(0, rpm, RISING); //and the interrupt is attached

// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()    
{
  NbTopsFan = 0;   //Set NbTops to 0 ready for calculations
  sei();      //Enables interrupts
  delay (1000);   //Wait 1 second
  cli();      //Disable interrupts
  Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate 

in L/hour 
  Serial.print (Calc, DEC); //Prints the number calculated above
  Serial.print (" L/hourrn"); //Prints "L/hour" and returns a  new line
}


版权与免责声明:
1.凡本网注明"来源:全球装备网"的所有作品,版权均属于全球装备网,转载请必须注明全球装备网。违反者本网将追究相关法律责任。
2.企业发布的公司新闻、技术文章、资料下载等内容,如涉及侵权、违规遭投诉的,一律由发布企业自行承担责任,本网有权删除内容并追溯责任。
3.本网转载并注明自其它来源的作品,目的在于传递更多信息,并不代表本网赞同其观点或证实其内容的真实性,不承担此类作品侵权行为的直接责任及连带责任。其他媒体、网站或个人从本网转载时,必须保留本网注明的作品来源,并自负版权等法律责任。 4.如涉及作品内容、版权等问题,请在作品发表之日起一周内与本网联系。