DIY Android Ball Maze - An Introduction to the Android ADK

FeaturedContest Winner
Picture of DIY Android Ball Maze - An Introduction to the Android ADK
Maze 003.jpg
Maze 005.jpg
Maze 006.jpg
Maze 009.jpg
Maze 010.jpg
Maze 014.jpg
Maze 016.jpg
Maze 017.jpg
Maze 018.jpg
Maze 020.jpg
If you're reading this article you're probably like me: I go through phases where I get so engrossed in a project (which most others would see as trivial), so focused on the goal that sleep and food are afterthoughts, I put my body through a gauntlet to appease some primitive urge of mine to CREATE.

Such was the beginnings of this project. I attended Google I/O 2011 and managed to get my hands on an Android ADK demo board. ADK is the Accessory Development Kit , an Arduino-based interface board whereby you can connect your compatible Android device (2.3.4 and any device from 3.1 onwards) to virtually any hardware and use the phone to control a device, or vice-versa.  It's called the Android Open Accessory platform, and it's totally cool.

To introduce the concept to the Google’s keynote speech they produced a regular ball maze toy , familiar to many, which was controlled by a Motorola Xoom tablet.  This Instructable is kind of two instructables in one: first, I'll be illustrating the steps required to set up the ADK from scratch and then I'll be reproducing Google's ball maze on a Nexus One phone to demonstrate a simple use of the ADK board (I'll keep the massive bowling-ball version for another Instructable). 

So continuing with my story: I grew up with a ball maze, my parents had one as far back as I can remember. A little while after I got home from Google I/O I found the maze at my parents’ house and shortly thereafter I discovered I had everything I needed to make my very own Googley maze controlled by my Nexus One.

[Lights on, cue primitive one-tracked mind]

The goal was set: I had one night to make this from scratch, hardware and software. I'd never written a real-world Android app before (not that this is very real-world yet...), but I was convinced that it couldn't be too hard. I worked from 7pm to about 5am, though I probably could have done it in 2-4 hours if I had an Instructable like this to start with - being my first ever Android project, much of that time was reading!

Only the Nexus One (Gingerbread 2.3.4) has been tested with the code I'm supplying, but it should work with little to no modifications on a stock up-to-date Nexus S and possibly also Android 3.1 tablets.  As of writing, I am unaware of any other supported devices or Android versions.

So dig through grandma’s game closet for that old ball maze, grab your Nexus, break out your Google ADK board if you went to Google I/O (or get a compatible one from the suppliers listed here ) and start building!

The idea is relatively simple: monitor the phone’s accelerometer, and translate the three-dimensional acceleration vector (ie. which way is "down") into a coordinates on a two-dimensional plane - one dimension for each servo or axis of rotation on the maze.  This is mapped to two absolute positions between 0-255 for positioning the servo arms. These values are passed to the ADK board which acts as the servo controller and controls the tilt on the maze. 

In other words, you can now play the ball maze game by using your phone as a remote controller!
Remove these adsRemove these ads by Signing Up
JUGG3R3 years ago
nice project,im just curious if there's a way that you could control it through wireless connection
pcdevltd (author)  JUGG3R3 years ago
AFAIK they are going to support bluetooth connections between phone and ADK board soon but it is not implemented yet. Not sure about wifi though.
Hi pcdevltd,

It is really Great project ,,,, I see you are appropriate one to tell me about good and small idea for subject on university,,, We can use on it jest Arduino and any sensor to built a nice application which wight 20% from final mark ,,, so please if you have an ides from your experience which smart and good tell me ,, it is really important ,,,

Than you,,,
pcdevltd (author)  MTechnology3 years ago
Coming up with ideas is one of the best parts of making any project - but I can't help you on that sorry - it depends on what hardware, software and other limitations you have, and also depends on what your university course expects you to do (When I was at university I learned that the "right" answer is most often the one that satisfies the lecturer/professor's expectations, not necessarily the one that you think is best, sadly). Good luck and post a link here when you are done!
JUGG3R pcdevltd3 years ago
BTW is there a code in here for the arduino or is it all the codes are for the android phone. Good day to you pcdev
pcdevltd (author)  JUGG3R3 years ago
I have not included the Arduino code, I was simply using the supplied DemoKit firmware (see this link, also posted in the instructable: The step titled "Installing the firmware to the ADK board" loads the ADK board with the demokit "sketch" (firmware). For this project I have not modified the firmware, but as I mentioned to Maheera if you are not using the Google ADK board then you will almost certainly have to update this code as well. I can't help with regular Arduino boards, I only have experience with the Google ADK board. Good luck!
JUGG3R pcdevltd3 years ago
i think arduino mega 2560 is compatible with the google adk board..thanks for this great project you have atleast i wont start from scratch..keep up the good work :)
pcdevltd (author)  JUGG3R3 years ago
Not directly compatible, see links I just posted above.
JUGG3R pcdevltd3 years ago
thanks for the links
Maheera3 years ago
(removed by author or community request)
pcdevltd (author)  Maheera3 years ago
Hi Maheera,

Unfortunately I'm extremely busy at the moment so it would be hard for me to really help out much - there's a huge amount of information in this instructable so I think you should be fine though. All source code is there (although being my first real Android project it is a bit messy and may not be set up correctly!) There are also plenty of tutorials and forums for Android development on the web - and they will be able to give you much more assistance on that side of things than I can.

I am interested though, what is the assignment that you have, and what do you plan to do? Depending on your major, a straight copy of my project seems a little simplistic for fourth year students (if you are CS students that is - no offense, but with my VERY rusty Java skills and having never programmed for Android before I completed the environment setup and coding all in a matter of a few hours)

If you want a bit of a challenge, you could try building a program based on my code (or the original DemoKit code, or write from scratch) that could complete the ball maze by itself, given a video feed of the maze from overhead. Now THAT would be a killer project for a group of 4th year students :) If this sounds like you, I also recommend you sign up for the free online Stanford AI and/or Machine Learning classes (google it), started just this week (you may or may not be able to still sign up officially, but I think they are releasing the videos free). I'm taking the courses (just a small part of the reason I'm so busy), and hope to do just what I've described with what I learn.

Good luck whatever you decide.
(removed by author or community request)
pcdevltd (author)  Maheera3 years ago
Hi Maheera, I assume your Galaxy S is running stock GS firmware, in other words I think it's on Android version 2.2 (Check under Settings > About Phone > Android Version). If that's the case then none of the Android Open Accessory stuff will work on the phone - Google only backported the AOA code down to Android version 2.3.4 and later versions on Android 2.x, and I understand that the only hardware that is officially supported on that version is the Nexus One and Nexus S. Other vendors with phones on Android 2.3.4 and later may have the same code incorporated, but you'd have to test that yourself. I only have a Nexus One (planning to upgrade to a Galaxy S2 or Galaxy Nexus shortly), so I can't test anything else for you.

So first check the version of Android that you have, if it is prior to 2.3.4 then you're out of luck. If it is non-stock 2.3.4 or later (eg. CyanogenMod or other 3rd party images) then you MAY be able to get it going but I really don't know. The only other option is to find a Nexus One, Nexus S, Android 3.1 or later tablet, or a device running Android 4.0 "Ice Cream Sandwich" to use instead. Sorry if that wasn't clear in the instructable.
(removed by author or community request)
pcdevltd (author)  Maheera3 years ago
2.3.3 is not high enough, it needs 2.3.4 or later - and even if you have 2.3.4 or later, unless the company that developed the firmware for your phone incorporated the AOA platform API, you may still not be able to use it. Can you add a screenshot/photo of the Settings > About Phone screen so I can see what you're running?
(removed by author or community request)
pcdevltd (author)  Maheera3 years ago
Hi Maheera, I really don't know if you have what you need to make this work in the short time you have left to do it. I don't think you can just use any Arduino board, did you get one of the ones listed on the site? (See the list at the top). If not, it will not work without some tweaking, and I can't help you with making the changes you need to make (I believe it involves soldering, reprogramming and making manual connections to servos). Then there's the problem of your phone - you NEED 2.3.4 or later, earlier versions will NOT work. And finally if you're not using exactly the same hardware as I'm using (Nexus One, Google ADK) then I can almost guarantee that RealMaze won't work exactly how I've written. If that's the case then I'm sorry, but there's nothing more I can help you with. I really don't have time to help you, especially leading up to Christmas, unless you and I have exactly the same hardware.
(removed by author or community request)
pcdevltd (author)  Maheera3 years ago
Hi Maheera,

The box connectors are just so you can easily connect and disconnect them without altering the standard 3-pin socket that comes on most servos. They have no effect whatsoever on the operation. If you prefer to hard-wire them that's fine.

As to whether you can connect them directly onto the PWM outputs on the Arduino board, you'll have to check the Arduino documentation on this, I really don't know. My ADK board has dedicated pins for servos. I THINK that you probably need to:
- check that the ports can supply enough current to the servos (even small servos can draw a lot of current when they move quickly), you wouldn't want to burn out the Arduino board.
- check that the servos are supplied a PWM voltage in the correct range (the standard Arduino 5v may not be enough),
- check that the Arduino sketch (firmware) is correctly calibrated to supply the right range of pulses to the servo, so that the servos are not damaged.

Disclaimer - I really have no idea. Like I said previously, if you don't have exactly the same hardware then recreating what I've done is going to involve a lot of work, much of which I can't help with because I've never done it before (only going from what I've read).

Good luck and Merry Christmas!
(removed by author or community request)
JUGG3R Maheera3 years ago
good day,
is this the code for retrieving data from the phone's accelerometer?
pcdevltd (author)  JUGG3R3 years ago
No, no, no, no, no.... you don't understand Maheera (or JUGG3R). The above code is NOT Demokit.apk (APK is what you install on the Android device). This code is from the file called demokit.pde and needs to be comiled and installed to the Arduino board, it is NOT for the APK. Arduino firmware is also regularly known as a "sketch" (because it's a bit of code drawn up to achieve something with the Arduino board). This code needs to be compiled and installed using the Arduino software, following the instructions here: HOWEVER, this is the code that you will have to change - check the pin numbers of the servo output (your code got a bit mangled by the instructables comment system, so I'm not sure if it's all there, but look for the lines that look like #define SERVO1 2 --- the "2" refers to the PWM output pin number. BUT, I don't know how to connect servos to this pin and ground (since servos have 3 pins, not 2, and they all need to be connected). Please look on the Arduino website for more info, I really can't help with that. Additionally, my understanding is that even though the ADK board is based on the Mega 2560, they are NOT identical, and there may be other things you need to do, please google it for info, perhaps also read these articles:

Once you have the above sketch compiled and installed onto the board, you need to test it, and I would recommend starting with the Demokit Android code (rather than trying to do the accelerometer thing first). Follow the instructions in the instructable for installing Eclipse, the APIs, etc, etc. and getting the Demokit code compiled and installed on the device. Without this you can't easily test the Arduino board.

@JUGG3R: The accelerometer code is in the Eclipse project attached to this instructable, see step 5.

I'll ask you again, do you have the right Android hardware? Do you have either a Nexus One, Nexus S, Galaxy Nexus or Android tablet with Android 3.1 or higher? If not, I can almost guarantee that Demokit will not work, unless you have already got it working, or have an assurance from the manufacturer that it works. I can't help you on getting it working on any device other than these.
JUGG3R pcdevltd3 years ago
i know its not the demokit.apk..i think the version of the arduino software used in this code is version .22 since its file type is pde..
i think the correct syntax would be:
int servoPin=2;
Servo myservo1;
void setup()
myservo1.attach(servoPin); (this will attach the servo to pin 2)

pcdevltd (author)  Maheera3 years ago
See my reply to JUGG3R
JUGG3R3 years ago
too bad i cant install the demokit with my samsung galaxy s 2(2.3.5) currently working for the wired one to run successfully before going to a wireless one
pcdevltd (author) 3 years ago
Thanks for the comments everyone! Don't forget to come back and vote for me in the three competitions - Toy, Microcontroller and Make it Move - thanks for your support!
nagutron3 years ago
Here's a video of the massive one at Google I/O you mentioned, using a bowling ball! Great job.
pcdevltd (author)  nagutron3 years ago
Thanks, yes the article also links to a video of it - it was a very cool demonstration of the Android Open Accessory platform, and a very Googley thing to do. I really look forward to seeing what other people build with it, the possibilities really are endless.
micha3l873 years ago
awesome job!
john.graves3 years ago
I've seen Paul's setup in person and it does work--but you still need to have the reflexes needed to run the maze. I never made it past the first hole. The puzzle tilts in slightly jittery steps, but it is very responsive to tilting the phone.
pcdevltd (author)  john.graves3 years ago
Thanks John! Yes, it is a little jittery. Reasons include: springs may be a bit soft (could probably be shortened to firm them up), there is no software damping which would make a huge difference, and the maze surface is not completely flat particularly near the start, the most travelled part (from 30 years of use!). To be honest, it's not the type of game you play for an hour at a time like you might on the original, but I've made it to hole 12, so it is definitely playable.
wilgubeast3 years ago
Super-awesome. I've been waiting for the trickle of ADK projects to begin. You set the bar really, really high. Nice work.
zazenergy3 years ago
Paul, this is awesome! Thank you so much for sharing this wonderful project!