Make A Arduino Candygrabber Machine


I’ve seen a lot of ways to communicate to Arduino over the net, but none of them could handle pushing back the messages from Arduino to the client(you) in real time and vice versa.

In this instructable you will learn how to connect to your Arduino and control it over the net, set up a video stream, and how to control stuff with your Arduino all in realtime. I’ll try to show you on a concrete example how this could be done, but the code I used and wrote is going to be generic so you can use it for your projects. Note that I haven’t discovered anything new but rather used code that I found lying around the net, built from it and changed it fit my needs.Candygrabber

In this example my Arduino is going to control a candy grabbing machine. Do you remember when you were a kid and went to the carnival and there where those machines in which you put money, and it let you play with the crane, grabbing stuffed toys and all kinds of things, then if you were skilled enough you could grab the toy, drop it in a hole and go home with new furry friend?
The candy grabber is a desktop version of this carnival machine.

So how should it work? The idea is that there is a Flash AIR app on my home computer that when a remote client connects to it starts the video broadcast. The communication between the client and the AIR app would be through a PHP socket because it can instantly push messages from one to the other. The socket will handle all the clients and the queuing. The Red5 server is used to handle the video broadcast, stream the video and send the Arduino commands from the client that is first in the queue to the AIR app (although it could do so much more… we’ll talk about that in a later step). Finally TinkerProxy is used to send commands from the AIR app to the Arduino that is connected to the same computer.

I’ll try to keep it online as long possible but my internet provider is a little quirky so if you can’t connect please come back later. Also my upload speed is quite slow so the video is relatively small but if your connection is faster you can easily adjust it to be bigger.

Seems complicated? Don’t worry, I’ll try to explain everything in detail on the next steps.

I decided if I win the MakerBot to give it away to my Arduino comunity that started in Croatia. I think that a afordable way to make parts is crutial to for the evolution of any kind of project, and as prototype fabrication in Croatia is absurdly expensive I think this would be of great help to all my friends.
Also I removed the 6 LEDs that were used for the light source. As I didn’t make a LED driver I fried them. 🙁 That’s the price for wanting to do something without first thinking how to get about it.
Of course the crapy chinese candygrabber mechanism broke down, so unfortunately the grabbing hand gets jamed and won’t go up or down except if I jank it out. The MakerBot would be wery usefull to fabricate the broken part 🙂

Step 1: What you’ll need

So here is the list of things you need for this project. Hardware:
1.Candy grabber toy(or anything you would like to control) – you can get them online for around 30$ if I’m not mistaken
2.Arduino / Arduino Mega – bought mine online. I used the Mega because it had more free pins when I connected the motor controller
3.Motor controller – you need some way to control the motors in the candygrabber. I use Adafruit Motor/Stepper/Servo Shield for Arduino 20$ ( )
5.IR LED – I scavenged mine from an old remote
6.Photointerupter – took my out of an old PS/2 ball mouse. (It’s used for the X and Y axis movement recognition of the mouse. Each axis has a one)
7.1kΩ resistors for the limit switches(4 pcs.)
8.670k Ω resistor for the Photointerupter
9.410 Ω resistor for the IR LED
10.Bunch of wires and jumper wires(they are practical as you can easily plug them in the Arduino pins).
11.Shrink tubeSkills and tools:
1.Soldering iron, solder, solder wick and soldering skills
3.Dremel tool
4.Hot glue gun
5.Multimeter – Trust me, if you don’t have one go and buy one. No seriously GO! If you’re familiar with programming think of it as a kind of debugger for your circuitry. I wouldn’t have finished this project if I didn’t have it. Try to find out which of the 20 something wires is for what, and you will know what I’m talking about.
6.A fair knowledge of programing in ActionScript 3 (Flash)Software:
1.Flash CS3 or higher
2.Some kind of Apache/PHP server installed on your computer(I use MAMP as it’s free and easy to setup and use) –
3.Red5 server – you need it to broadcast your video from the flash AIR and stream it to the flash client (free if you have your server, else hosting plans range from 30$ up, I used ). You can find out more at
4.NO-IP.ORG – as my service provider doesn’t give me a static IP so I have to use it to connect to the PHP socket on my computer(also free, need to register) –
5.TinkerProxy – so flash can communicate with Arduino – 

Here you can download all the source codes:

I had some bugs with the queue in the PHP socket – SOLVED
Added some sounds to the client flash so the user is notified when it’s his turn.
A few modifications to the , and classes – it timeouts when there are no more users. Also this way I addresed the issue of the changing IP(I don’t know why but my internet provider does that a few times a day) and you save bandwith.
Also I added  6 LEDs in the top cover to get rid of the annoying light reflection. 

Step 2: The candy grabber

You can try to build your own candy grabber but this is not the scope of this project. I’m focusing on connecting and controlling the toy.
So in order to connect the Arduino and the toy we have to open it up and take it’s guts out. Use a screwdriver and unscrew the bottom and top of the toy. Looking at the bottom you’ll see a bunch of wires connected to a PCB. Now the multimeter comes to play. Use it to find out which wire is for what. You can find a great tutorial on how to use a multimeter here ( ).

I made a diagram how the motor and the limit switches are connected(picture 12). The thing is that the joysticks(potentiometer) changes the polarity on the motor and limit switches as you push it from one side to the other(In fact I’m not completely sure that the joysticks are potentiometers because I couldn’t find any data sheets of this kind of potentiometer. If anybody knows what they are drop me a comment). Later will have to separate the motor from the switches by cutting the wires that go from the switches to the motor(picture 1). For now lets just find what is what.

Candygrabber circuit

Leave a Comment

Your email address will not be published. Required fields are marked *