我有一个霍尔效应传感器放置在液体泵的末端,通过地板加热循环液体。我想获得泵的状态(打开或关闭),然后通过串口消息将状态发送到OpenHab。问题是数字引脚的状态似乎随60 or电流和/或旋转泵叶轮而波动。根据具体情况,我正在读引脚,我可能得到一个高或低,即使泵是开着。这会向OpenHab发送虚假消息。
我知道我可以用带有AND门的OR门来构建一个“闩锁”电路,但我不想增加电子设备(加热系统中有14个泵)。
有办法稳定传感器值吗?
发布于 2022-01-10 03:57:05
我已经为泵霍尔传感器编写了锁存功能。我使用一个结构来保存传感器及其设置,并使用一个链接列表来保存所有传感器:
struct s_PumpSensor
{
/**
* Name of the sensor
*/
char *name;
/**
* The arduino pin number to read the information from
*/
int pin;
/**
* The pump state
*/
bool pumpOn;
/**
* How long to wait to ensure the pump is off
*/
unsigned long offTimer;
/**
* The next one in line, or null
*/
s_PumpSensor *next;
};从遍历链接列表的循环中调用的锁存代码:
void checkPumpSensor(s_PumpSensor *theSensor, unsigned long currentTime)
{
bool pumpIsOn;
bool isChange = false;
pumpIsOn = (digitalRead(theSensor->pin) == LOW) ? true : false;
if (theSensor->pumpOn == pumpIsOn)
theSensor->offTimer = currentTime;
else if (pumpIsOn)
isChange = true;
// Wait for 2 seconds before believing the sensor change to off
if ((currentTime - theSensor->offTimer) > 2000)
isChange = true;
if (isChange)
{
theSensor->pumpOn = pumpIsOn;
// send the state change to OpenHab
Serial.print("Pump:");
Serial.print(theSensor->name);
Serial.print(":");
Serial.println(theSensor->pumpOn ? "On" : "OFF");
}
}如果传感器没有改变,那么关闭计时器将被重置。传感器的旧状态只有在泵关闭并且现在打开,或者关闭时间已经过期时才会更新。
只有当泵关闭超过2秒时,行if ((currentTime - theSensor->offTimer) > 2000)才会触发。因此,泵磁场可以在不触发变化事件的情况下波动。
https://stackoverflow.com/questions/70647642
复制相似问题