motion-sensor

maksimbaturin/hc-sr505-motion-sensor/motion-sensor

The node is designed to work with the miniature HC-SR505 motion sensor. It allows detecting movement of people and animals within the sensor's range.
motion-sensor
@/motion-sensor
The node is designed to work with the miniature HC-SR505 motion sensor. It allows detecting movement of people and animals within the sensor's range.
INport
digital pin number of Arduino connected to the sensor's OUT pin
UPDpulse
update pin (triggers reading from the sensor)
motion-sensor
IN
OUT
UPD
OUTboolean
boolean value: true - motion detected false - no motion detected
To use the node in your project you should have the maksimbaturin/hc-sr505-motion-sensor library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPD

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    if (!isInputDirty<input_UPD>(ctx))
        return;
    
    auto pin = (int)getValue<input_IN>(ctx);
    pinMode(pin, INPUT);
    
    bool motionDetected = digitalRead(pin) == HIGH;
    emitValue<output_OUT>(ctx, motionDetected);
}