I'm new to raspberry pi. I was wondering if it was possible to connect an android phone to raspberry pi so that Rpi can read the data from the phone's sensors. It could be a direct USB connection. Ideally I would like to use the phone for its 3g connectivity, gps and accelerometer. I'm going for this method, as the individual hardware meant for Rpi is quite expensive, and I have android phones just lying around.

  • You will need a dedicated app on the android phone. You will have to do it over TCP. For direct USB connection see this thread
    – GuySoft
    Commented Jun 7, 2013 at 17:23

2 Answers 2


If you install python on your phone it will help you accesses the sensors, i use qpython on my android tablet, the module that you want to use is androidhelper, it will contain the tools to read the sensors.


But this link is all of the documentation that i have managed to find.

Another way would be to write a program using java that could read the sensors, this method will most likely give you the most options but it will be the most challenging.


You can try using this app. It sends data from the sensors in UDP. It would only give you the information from the Accelerometer from the list you wanted.

Sensor id:
3 - Accelerometer (m/s^2)
4 - Gyroscope (rad/s)
5 - Magnetometer (micro-Tesla uT)

Example UDP packet: 890.71558, 3, 0.076, 9.809, 0.565, 4, -0.559, 0.032, -0.134, 5, -21.660,-36.960,-28.140

Timestamp [sec], sensorid, x, y, z, sensorid, x, y, z, sensorid, x, y, z

There is a sample program in the description:

import socket, traceback

host = ''
port = 5555

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind((host, port))

while 1:
        message, address = s.recvfrom(8192)
        print message
    except (KeyboardInterrupt, SystemExit):

The pi can run this program, since its python with only standard libraries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.