Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 根据频率值计算风速_Performance_Arduino_Frequency - Fatal编程技术网

Performance 根据频率值计算风速

Performance 根据频率值计算风速,performance,arduino,frequency,Performance,Arduino,Frequency,我有NRG#40风速传感器,输出频率与风速成线性关系 输出信号范围从0 Hz到125 Hz 0 Hz平均值=0.35 m/s和125 Hz=96 m/s,传递函数为 米/秒=(赫兹x 0.765)+0.35 如何将此传感器与Arduino mega接口 之前我连接了Adafruit(产品ID:1733),它的输出电压不是频率与风速成线性关系 Adafruit的代码是: //Setup Variables const int sensorPin = A0; //Defines the pin

我有NRG#40风速传感器,输出频率与风速成线性关系 输出信号范围从0 Hz到125 Hz 0 Hz平均值=0.35 m/s和125 Hz=96 m/s,传递函数为 米/秒=(赫兹x 0.765)+0.35 如何将此传感器与Arduino mega接口 之前我连接了Adafruit(产品ID:1733),它的输出电压不是频率与风速成线性关系 Adafruit的代码是:

 //Setup Variables

const int sensorPin = A0; //Defines the pin that the anemometer output is connected to
int sensorValue = 0; //Variable stores the value direct from the analog pin
float sensorVoltage = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float windSpeed = 0; // Wind speed in meters per second (m/s)

float voltageConversionConstant = .004882814; //This constant maps the value provided from the analog read function, which ranges from 0 to 1023, to actual voltage, which ranges from 0V to 5V
int sensorDelay = 1000; //Delay between sensor readings, measured in milliseconds (ms)

//Anemometer Technical Variables
//The following variables correspond to the anemometer sold by Adafruit, but could be modified to fit other anemometers.

float voltageMin = .4; // Mininum output voltage from anemometer in mV.
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage

float voltageMax = 2.0; // Maximum output voltage from anemometer in mV.
float windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltage



void setup() 
{              
  Serial.begin(9600);  //Start the serial connection
}


void loop() 
{
sensorValue = analogRead(sensorPin); //Get a value between 0 and 1023 from the analog pin connected to the anemometer

sensorVoltage = sensorValue * voltageConversionConstant; //Convert sensor value to actual voltage

//Convert voltage value to wind speed using range of max and min voltages and wind speed for the anemometer
if (sensorVoltage <= voltageMin){
 windSpeed = 0; //Check if voltage is below minimum value. If so, set wind speed to zero.
}else {
  windSpeed = (sensorVoltage - voltageMin)*windSpeedMax/(voltageMax - voltageMin); //For voltages above minimum value, use the linear relationship to calculate wind speed.
}

 //Print voltage and windspeed to serial
  Serial.print("Voltage: ");
  Serial.print(sensorVoltage);
  Serial.print("\t"); 
  Serial.print("Wind speed: ");
  Serial.println(windSpeed); 

 delay(sensorDelay);
}

如果使用Arduino UNO或Nano,一种简单的方法是将传感器连接到引脚D2或D3,该引脚可用作中断引脚。 然后创建一个函数或ISR,每次传感器脉冲时都会调用该函数。然后将新创建的函数连接到中断引脚。 所以它看起来像这样

byte sensorPin = 2;
double pulses = 0;
double wSpeed = 0;
long updateTimer = 0;
int updateDuration = 3000;

void setup() {
  Serial.begin(115200);
  pinMode(sensorPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(sensorPin), sensorISR, FALLING);
}

void loop() {
  long now = millis();
  if(updateTimer < now) {
    updateTimer = now + updateDuration;
    wSpeed = ((pulses/(updateDuration/1000)) * 0.765) + 0.35;
    pulses = 0;
    Serial.println("Windspeed is:" + String(wSpeed));
  }
}

void sensorISR() {
  pulses++;
}
字节传感器pin=2;
双脉冲=0;
双wSpeed=0;
长UpdateTime=0;
int updateDuration=3000;
无效设置(){
序列号开始(115200);
引脚模式(传感器引脚、输入\上拉);
连接中断(数字插针中断(传感器插针)、传感器ISR、下降);
}
void循环(){
long now=millis();
if(updateTimer
ISR功能的唯一任务是为每个脉冲增加脉冲变量。然后每秒钟你就可以计算出频率和速度。如果你像上面那样等3秒钟,你会有一个更好的分辨率,但是你必须在等式中考虑额外的时间


我没有测试这个代码。

谢谢你,先生,实际上我需要记录每10分钟的平均风速0 HZ=0.365 m/s 125 HZ=96 m/s根据这个方程计算的其他风速m/s=(HZ x 0.765)+0.35信号类型是方波arduino的类型是arduino mega代码在mega上也应该有效。您可以将“updateDuration”变量更改为键入“long”而不是“int”,并将值更改为600000以获得过去10分钟的平均值