# Share Octave applications - Fall detection

**URL:** <https://forum.sierrawireless.com/t/share-octave-applications-fall-detection/20585>\
**Category:** Octave App Sample\
**Created:** [June 10, 2020, 8:38am UTC](https://forum.sierrawireless.com/t/share-octave-applications-fall-detection/20585 "2020-06-10T08:38:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![haulnette](https://avatars.discourse-cdn.com/v4/letter/h/ac91a4/32.png) [@haulnette](https://forum.sierrawireless.com/u/haulnette)\
**Post date:** [June 10, 2020, 8:38am UTC](https://forum.sierrawireless.com/t/share-octave-applications-fall-detection/20585/1 "2020-06-10T08:38:33Z")

</div>

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](https://mangoh.io/mangoh-yellow-resources-getting-started)

**Octave concepts used**

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

- 1 Resource

- 2 Virtual Resources

- 2 Observations

- 1 Edge action

**Implementation**

**1. Resource**

Enable the imu/accel resource:

- imu/accel/enable: true  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/sierrawireless/original/2X/3/3ad891cf61c34f800e67bfe9448715e4d3014285.png)

**2. Virtual resources:**

Set the name shock\_state, the type: Boolean and the value: false:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/sierrawireless/original/2X/a/a3d461d0247fd626f7120896f4a214d0a5aec3d0.png)

Repeat the same action for the beenSent ressource:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/sierrawireless/original/2X/f/fe5a479e3f2d36d915b44eb826c6da90e5ec0aae.png)

You can see the 2 virtual resources have been created:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/sierrawireless/original/2X/4/4a0d04a04d9631e18f079d5e95cdd2ce736bcebc.png)

**3. Observations**

 ![image](https://us1.discourse-cdn.com/flex025/uploads/sierrawireless/original/2X/4/4ca0deb9fdec445b769b1df8d7aff109ca6fa24d.png)  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/sierrawireless/original/2X/4/459eea567d25760b47874f704d55bc80b7a1199a.png)

**4. Edge action**

 ![image](https://us1.discourse-cdn.com/flex025/uploads/sierrawireless/original/2X/9/9eb9a80df23059269f8474180a27dfa519bd74c1.png)

```
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…))
