首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >霍尔效应传感器在泵上的波动状态

霍尔效应传感器在泵上的波动状态
EN

Stack Overflow用户
提问于 2022-01-10 03:57:05
回答 1查看 53关注 0票数 -1

我有一个霍尔效应传感器放置在液体泵的末端,通过地板加热循环液体。我想获得泵的状态(打开或关闭),然后通过串口消息将状态发送到OpenHab。问题是数字引脚的状态似乎随60 or电流和/或旋转泵叶轮而波动。根据具体情况,我正在读引脚,我可能得到一个高或低,即使泵是开着。这会向OpenHab发送虚假消息。

我知道我可以用带有AND门的OR门来构建一个“闩锁”电路,但我不想增加电子设备(加热系统中有14个泵)。

有办法稳定传感器值吗?

EN

回答 1

Stack Overflow用户

发布于 2022-01-10 03:57:05

我已经为泵霍尔传感器编写了锁存功能。我使用一个结构来保存传感器及其设置,并使用一个链接列表来保存所有传感器:

代码语言:javascript
复制
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;
};

从遍历链接列表的循环中调用的锁存代码:

代码语言:javascript
复制
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)才会触发。因此,泵磁场可以在不触发变化事件的情况下波动。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70647642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档