Is it possible to use Android phone sensors?


I’ve seen projects that use hardware (like HMC5883L) directly connected to Photon for sensor purpose. I’d like to create a compass that could use Android phone sensor (magnetometer) instead. Is it it possible to make android phone sensor activate photon output?

Are you asking if you can use your phone’s built-in magnetometer as an input to your code on the Photon? If that’s the case, then directly using the magnetometer on the Photon isn’t really possible. You could write an App on the phone that sends data to the Particle cloud, then read that data on the Photon. What is the use case you’re envisioning?

That’s what I was thinking. I need to write an App. For beginning I would like to make it very simple. The App gets connected to the cloud. Lets say my compass points to the North. The data is sent to the cloud by publishing event from mobile device. Photon is subscribed to events published by App in the cloud. I cannot find any examples of such kind of projects. Maybe technically it’s not possible or very complicated to implement it.

It’s neither impossible nor overly complicated. It’s just not all that common of a use case. Look into the Particle Android SDK to get you started with the app. Your app will either publish events or set cloud variables using the SDK. On the Photon side, you’ll write functions to respond to cloud events or read cloud variables.

If you have a Gen3 device you can load Rickkas BLE Serial UART library and then use Adafruits Bluefruit App and stream your phones sensor data to the Particle Gen3 device over Bluetooth pretty easily.

If @laimonas is intending to write his own Android app anyhow a custom BLE service/characteristic is probably the better choice for speedy interaction.
There even are standardised characteristics for compass and accelerometer data.

1 Like

Bluetooth definitely make sense. However I was given a task try to solve problem using Photon WiFi connection. Compass would not require something very speedy. Even refresh rate once per second would be fine.

If you don’t need encrypted transmission UDP or TCPClient would be another route which wouldn’t require a cloud connection and cut out some latency.