# Mobile orientation and accelerometer

**URL:** <https://forum.babylonjs.com/t/mobile-orientation-and-accelerometer/10473>\
**Category:** Questions\
**Created:** [May 1, 2020, 3:48pm UTC](https://forum.babylonjs.com/t/mobile-orientation-and-accelerometer/10473 "2020-05-01T15:48:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FBa](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@FBa](https://forum.babylonjs.com/u/FBa)\
**Post date:** [May 1, 2020, 3:48pm UTC](https://forum.babylonjs.com/t/mobile-orientation-and-accelerometer/10473/1 "2020-05-01T15:48:43Z")

</div>

Is BabylonJS compatible with any possibility of detecting the mobile phone’s orientation and accelerometer to control, let’s say, a box? Tilting the phone to the left makes the box goes left, etc…?

---

<div class="post-metadata">

**Author:** ![syntheticmagus](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/syntheticmagus/32/395_2.png) [@syntheticmagus](https://forum.babylonjs.com/u/syntheticmagus)\
**Post date:** [May 1, 2020, 5:11pm UTC](https://forum.babylonjs.com/t/mobile-orientation-and-accelerometer/10473/2 "2020-05-01T17:11:45Z")

</div>

Hi FBa,

Sure! Babylon already provides a [`DeviceOrientationCamera`](https://doc.babylonjs.com/babylon101/cameras#device-orientation-camera), which uses IMU data from the browser data to control the camera. Here’s the code that listens to that input; you should just be able to listen to the same input and repurpose it to control anything you want. Good luck!

> <https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/Inputs/freeCameraDeviceOrientationInput.ts#L170-L177>

---

<div class="post-metadata">

**Author:** ![FBa](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@FBa](https://forum.babylonjs.com/u/FBa)\
**Post date:** [May 1, 2020, 7:04pm UTC](https://forum.babylonjs.com/t/mobile-orientation-and-accelerometer/10473/3 "2020-05-01T19:04:25Z")

</div>

Thanks. I am trying to copy one from the demo and see if it works. [https://raw.githubusercontent.com/lucastwong/cameratest/master/trial](https://raw.githubusercontent.com/lucastwong/cameratest/master/trial)  
Does it work?

---

<div class="post-metadata">

**Author:** ![syntheticmagus](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/syntheticmagus/32/395_2.png) [@syntheticmagus](https://forum.babylonjs.com/u/syntheticmagus)\
**Post date:** [May 1, 2020, 7:50pm UTC](https://forum.babylonjs.com/t/mobile-orientation-and-accelerometer/10473/4 "2020-05-01T19:50:29Z")

</div>

The device I’m on right now doesn’t have an IMU, so I wouldn’t be able to evaluate it at the moment. You should just be able to try it on your phone or tablet, though. However, I think you might need to make the file an HTML file so that the browser knows what to do with it; right now, it just opens as plaintext. 🙂

---

<div class="post-metadata">

**Author:** ![FBa](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@FBa](https://forum.babylonjs.com/u/FBa)\
**Post date:** [May 1, 2020, 8:02pm UTC](https://forum.babylonjs.com/t/mobile-orientation-and-accelerometer/10473/5 "2020-05-01T20:02:47Z")

</div>

It’s now on my github page as an index.html

[https://lucastwong2.github.io/](https://lucastwong2.github.io/)

My phone hasn’t responded to the movement. Please let me know if you have a chance to test it out. Thank you so much!
