Notice: By using this site, you agree to use of cookies. Close

Self playable game on smartphone

Connecting Android to servo motor via USB OTG


I recently put together a Lego phone holder that can be rotated in one direction (y-axe the longer side of phone). The end of the holder is attached to a servo motor. Servo motor is connected to Android smartphone with USB OTG via motor module. Motor module is controller that can control up to 24 servo motors and runs on 5 volts.


The module controller part has already burned its own protocol. It was a combination of rotation and speed separated by new line symbols.

Second part was Android application that sends messages via serial protocol to this servo-module. I used an example of USB serial communication with Arduino and rewrote it for my device.


For this exercise I chose a game that I made about year ago. It is a simple game that uses accelerometer to move the rocket through gates. Leaning device to sides allows you to control the position of the rocket. The goal is to run through as many gates as you can. The speed is increasing within entered gates.


My first idea was to detect the values of maximum rotation to both sides. Then to use this values and dynamically calculate all rotations of holder. But after few changes in my holder construction I realised that my configuration is a little bit different each time. So I created a calibration method that runs at start up and detects the limit values by itself. Then during the game the values are recalculated from these limits. For better understanding I recommend you to watch the video below.


The practical usage of "self playable holder" is literally none. But if you look at it as an exercise, it is a nice introduction to connecting an android to servo motor.