Arduino Candygrabber

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.
Arduino 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 relativly 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 tube

Skills and tools:
1.Soldering iron, solder, soder 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)

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 dosn’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.

Arduino Candygrabber circuit
Power it up, insert a coin and push the first joystick ether way and hold it. Now start probing the wires in pairs for voltage. Start with the ones closest to the joystick. Take note that when it reaches the limit switch for the particular axis it will cut the power to the motor. If you are probing the X axis find it’s limit switches(picture 8 & 9). On the PCB the switch wires should be close to the joystick(picture 7). There should be three wires for the 2 switches of the axis. One is +5V and the other two GND. When you find the corresponding switch wires turn the toy off and start probing the wires for continuity. Start with two wires and then press the limit switch for the corresponding axis from the top. If you loose the continuity that’s one of your switches. Label it as SWITCH_1 . Labeling things will make it much easier later. Now continue and find the opposite switch and label it as SWITCH_2.
Now repeat the process for the other axis labeling the wires SWITCH_3, SWITCH_4.
The last motor that controls the up-down motion of the grabbing hand doesn’t have a limit switch so you just have to find 2 wires of the motor.

Major Components in Project

1.Candy grabber toy

2.Arduino / Arduino Mega

3.Motor controller


For more detail: Arduino Candygrabber

This Post / Project can also be found using search terms:

  • Arduino Candy Grabber
  • arduino limit switch
  • arduino switch
  • i2c arduino data grabber
Clip to Evernote

Leave a Comment

(Spamcheck Enabled)

Read previous post:
Arduino Hardware PWM for stepper motor drives
Arduino Hardware PWM for stepper motor drives

With our new project, JustAddSharks, we are very keen to support the development of open source control software for laser...

Scroll to top