Share Octave applications - Fall detection

Hi there,

I am sharing a simple app, “Fall detection” using a mangOH Yellow and its accelerometer sensor to detect any fall. When the accelerometer detects a value above 3 for the X, Y or Z position, it is considered as a “fall”. Accelerometer’s values are sent to cloud (just the ones at the fall moment), a shock state variable is saved in the device and the red light and the buzzer are enabled when a fall is detected.

Feel free to try it and comment below!

Prerequisites

Before starting, make sure you already followed the getting started with mangOH Yellow and Octave: https://mangoh.io/mangoh-yellow-resources-getting-started

Octave concepts used

In this application, I am using the following Octave components:

  • 1 Resource

    • imu/accel
  • 2 Virtual Resources

    • shock_state/value
    • beenSent/value
  • 2 Observations

    • accel_value (send to an Edge action): sends events to Fall Detection action
    • shock_state (send to the device storage): store the shock state in the device
  • 1 Edge action

    • Fall Detection: switch on the red light and the buzzer depending on the mangOH position

Implementation

1. Resource

Enable the imu/accel resource:

2. Virtual resources:

Set the name shock_state, the type: Boolean and the value: false:

Repeat the same action for the beenSent ressource:

You can see the 2 virtual resources have been created:

3. Observations


4. Edge action

function(event) {

    var mouvX = event.value.x > 3;

    var mouvY = event.value.y > 3;

    var mouvZ = event.value.z > 3;

    var beenSent = Datahub.read('/virtual/beenSent/value', 0).value;

    var shockState = Datahub.read('/virtual/shock_state/value', 0).value;

    if (mouvX || mouvY || mouvZ) {

        if (beenSent === false){

            return {

                "cl://": [{

                    "Shock_state": true,

                    "Fall_values": event.value

                }],

                "dh://virtual/beenSent/value": [true],

                "dh://virtual/shock_state/value": [true]

            }

        }

        else{

            if (shockState === true){

                return{

                    "dh://leds/tri/red/enable": [true],

                    "dh://buzzer/enable": [true],

                    "dh://buzzer/percent": [20],

                    "dh://buzzer/period": [2],

                    "dh://virtual/shock_state/value": [false]

                }

            }

        }

    }

    else {

        if (beenSent === true){

            return {

                "dh://leds/tri/red/enable": [false],

                "dh://buzzer/enable": [false],

                "dh://virtual/beenSent/value": [false]

            }

        }

    }

}

Make sure to enable your edge action and check the Streams for accelerometer values while you are moving the mangOH Yellow.

Does this simple app run well for you? Let me know in the comments! Enhancements proposals are welcome too!

Feel free to share your own app in a new topic! (please mention what device your Octave app is using (mangOH red, mangOH Yellow, FX30, etc…))

2 Likes