OrientationSensor Pitch movement (or how to use Accelerometer to detect movement)

I want to detect the movement of a cell phone.
To do this I use OrientationSensor reading the Pitch values.
If I only read the first digit of Pitch, if it changes in value the cell phone has been moved.
If I read the first 2 digits of Pitch, if it changes in value, the cell phone has been moved, but the sensitivity has increased.
If I read 3 digits (or more than 3) the sensor becomes too sensitive for my purpose.
I ask for advice:
How can I manage the pitch values to decrease the sensitivity?
Can you recommend another method for detecting movement and amplitude of movement?
Testpitch_01.aia (9.0 KB)

You might try an Accelerometer instead of an Orientation sensor. Do something similar to Taifun’s example How to trigger something if device is facing down

or you can use an use an If block (similar to Taifun’s accelerometer usage) with the Orientation sensor to monitor the pitch range . If this is possible at all, the following advice might help you Programming Your App to Make Decisions

1 Like

Maybe I can’t explain myself for my bad English.
I need to understand how much a person (who has a cell) moves (not to be confused with moving).
For example, a person is supine on the ground, has a cell phone in the front pocket of his shirt.
The person can be in one of these conditions: 1) not breathing - 2) breathing heavily - 3) moving trying to get up.
How can I establish ranges for these values?

I do understand.

How can I establish ranges for these values? Only by experimenting and finding values for the range that are appropriate.

I expect you are going to have a lot of difficulty.

  • for not breathing, the values will exhibit no changes over a period of time
  • for breathing heavily, the values will exhibit changes
  • for moving trying to get up will exhibit changes similar to breathing heavily.
    Regarding these, you can set the sensitivity to 1,2,or 3 with AS and see what works best and what values trigger a change. You got to experiment.

What values will work may or may not be dependent on you Android hardware orientation sensor or accelerometer. (Which ever you work with)

Here is some advice from the documentation about what ranges to expect
AccelerometerSensor

Sensitivity
Specifies the sensitivity of the accelerometer. Valid values are: 1 (weak), 2 (moderate), and 3 (strong).

XAccel
Returns the acceleration in the X-dimension in SI units (m/s²). The sensor must be enabled to return meaningful values.

YAccel
Returns the acceleration in the Y-dimension in SI units (m/s²). The sensor must be enabled to return meaningful values.

ZAccel
Returns the acceleration in the Z-dimension in SI units (m/s²). The sensor must be enabled to return meaningful values. This measures the force of gravity so probably useless for your purposes

OrientationSensor

Magnitude
Returns a number between 0 and 1 indicating how much the device is tilted. It gives the magnitude of the force that would be felt by a ball rolling on the surface of the device. For the angle of tilt, use Angle .

Pitch
Returns the pitch angle of the device. To return meaningful values the sensor must be enabled.

Roll
Returns the roll angle of the device. To return meaningful values the sensor must be enabled.

What will work for you? Sorry, I have no idea.

How can I establish ranges for these values? … lay down with the Android on your chest and have some on record the values he/she sees for each activity and use those values seems logical. Hold your breath for the not breathing scenario. Once again, you need to experiment.

What do you discover? You might wish to share your experience of what values ‘work’ here in the forum.

This is what I did.
I have estimated that (probably) the pitch value is the least sensitive.
How can I increase the range between the 3 values?
can you offer me other solutions?
For the 3 ranges, maybe this is a mathematical problem?
How can I establish ranges for these values?Testpitch_02.aia (9.4 KB)

  • Consider using the accelerometer instead of the orientation sensor. I believe the orientation sensor is inappropriate to use successfully in your medical app.
  • Do not use Labels as variables. The advice below points to information showing how to use variables in your app
  • Instead of removing decimal point with replace text blocks, use the Math round function
  • Learn to use conditional statements; so a correct value is compared to a range of values. Read this Programming Your App to Make Decisions . You did not read the advice earlier in the highlighted blue links. When you click on them, moderators know whether they have been read or not.
  • Post images of your Blocks.
  • Do continue to experiment with the Orientation sensor but seriously consider using the Accelerometer for your app. Here are links to tutorials about the orientation sensor. and Similar stuff for the Accelerometer

It might be time to take a time out and read the following information:
Here are some resources to help you learn to use the AI2 tools. A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFiles

How to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .

Also look here App inventor español. Offline. Tutorial. Ejemplos. Instalación. Códigos. Juegos. Curso gratis de App inventor. and here Tutorial Index | imagnity for more tutorials.

Shaking how to change sensitivity.
I made this app, but the low sensitivity is not low enough.
How to make it more sensitive?shaking_04.aia (8.0 KB)

1 Like

What does that mean Antonio?

  • set Sensitivity to 1, it means the sensor requires a very large movement to respond
  • set Sensitivity to 2, it means the sensor requires a good jolt to respond
  • set Sensitivity to 3, it means the sensor requires a small shake to respond.

If you use the Accelerometer.Shaking Block, these are the ONLY sensitivity adjustments available.

So, what should you do? Perhaps something like this:

AccelChanged

might be what would work for you. Experiment.

1 Like

Maybe I solved it with GyroscopeSensor1
Comments are welcome.
giroscopio_01.aia (4.2 KB)

1 Like

If the Gyroscope allows you to create your app; wonderful. Only you know what you expect your app to do. :wink: Use the tools that allow you to make your app do what is necessary. If you can not get the Orientation or Accelerometer sensors to provide your required response, certainly use the Gyroscope.

A possible issue is only some Android hardware comes with the Gyroscope. Older devices do not have that toy.

1 Like

Do you regret the news about the Gyroscope, do you know or remember which Android version became available?

1 Like

Google " list of devices having an android gyroscope ’ and 'gyroscope became available in android ’ I have an new Android 8.1 tablet and it does not have a gyroscope.

1 Like

If anyone can be useful, this is the App that detects the movement and its intensity using the gyroscope
giroscopio_04.aia (6.9 KB)

2 Likes

Since accelerometer shows fixed values for different phone tilts/positions, And, the values for phone movement is also shown together, how can we differentiate both readings? I mean, How can I know/differentiate the 'phone movement' reading from 'Phone tilt' readings? Is there any option to differentiate both?

For my project, I don't bother the phone positions/tilts. I want to know only the phone movements. Is there any possibility for that?