【发布时间】:2019-10-01 07:38:55
【问题描述】:
我正在使用 Arduino UNO 来记录 CNY70 的传感器数据。我使用的代码如下所示。编写此代码以记录 10 秒的值并在此之后停止。
#include <EEPROM.h>
const int chipSelect = 2;
unsigned int y1 = 0;
unsigned long y = 0;
String data = "";
void setup()
{
Serial.begin(230400);
delay(10);
}
void loop()
{
while (y < 10000000)
{
if (y1 > 372) //start recording only after 372 microseconds
{
y = micros();
data += y;
data += ",";
data += analogRead(A0);
Serial.println(data);
data = " "; //clear data after printing the value
}
y1 = micros() - y;
}
}
这些值是从串行监视器复制的。一些记录显示一个或两个记录值突然跳跃,因此,数据图表看起来像是被“击中”了。这些数字是: Jump in value of the sensor data Zoomed image of the sensor data
这些突然的值不会在每次运行代码时出现,但它们会在每 7-12 次运行时出现一次。这些突然跳跃的原因是什么?实验条件没有突然变化。如何防止 Arduino 记录和存储这种突然的值?
【问题讨论】:
标签: arduino arduino-uno android-sensors proximitysensor