Picture of 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.

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 :-)
blackcamo5 months ago

Ah Arduino projects are so fun!

And Arduino is cheap now...


BigRon2 years ago
Hey odvratno.zgodan. I wanted to say: hvala ti za dokumentaciju tog projekta! A great tutorial but do you know if there is a way to realize it with a eg. RaspberryPi instead of a full fledged computer? Do you have some tips which way would be best to get it working with a raspberrypi? So I could use html/php and the GPIO Ports from the Raspberry and a Webcam to get the stream out? I think I do not need any Flash or Red5!?

Hvala i pozdrav!
DIY-Guy2 years ago
Oh WOW! This is exceptional.
Did I miss where to buy commercial coin slot mechanisms to make this a money maker?
Oh my gosh. That is awesome!
ammyent2 years ago
G8 Work
niksen3 years ago

Thanks for awesome and detailed tutorial.

I think i'm already finished, but smth is not working:


i'm trying to run everything on Windows 7, Adobe Air app shows each status: Connected.

But not on client side.

This screen from server (on wich Air app is running and arduino connected) http://clip2net.com/s/1xb7j

From screen you see that i'm receiving some errors in command promt:
"Notice: Undefined index: queuePosition in socketShell.php on line 214"

This message i get when i run client.swf on other machine. RED5 - connected, Shared obejct: connected, SocketConnection - nothing.

Please take a look on a screen below https://skitch.com/neskin/gh3aa/client

Thanks in advance!
odvratno.zgodan (author)  niksen3 years ago
It seems that the PHP socket isn't working properly. As a result the Shared object isn't going to work properly. It's because the PHP socket works as a queue and tells which client to connect to the AIR app. There could be a few causes and ways to debug the app:
1. I'm not sure which server you installed. On my mac I installed MAMP but I had to enable socket connections. I'm not sure anymore how to do it but you can google it.
2. Do you have a video feed in the AIR app and client? The Red5 connection should handle the video. The video is captured with the AIR app --> sent to the Red5 server --> Client
3. If the sliders don't work it is probably cause the socket connection doesn't work. Remember that the socket connection handles the clients queue. So if it doesn't work your sliders won't work.
4. I checked the PHP code at line 236. Not sure why the error occurred here. I use a low tech solution to debug my code. On the beginning of every IF statement put ECHO "something" and replace the text "something" with different text so when you run the code you can find out at which line exactly the error occurred.
5. Where do you host the socket connection? Locally? Did you put the cross-domain policy files in the root folder of your php server?

To summarize, to me it seems that the error is located somewhere in the SocketConnection.php . I'm not sure where and why as this is the same file that I used for the project and it worked for me. If you'll have anymore questions do not hesitate to contact me. Also I would love to see you project, so if it's possible send me a link or pic.

Good luck,
ococa2524 years ago
hi there,
I'm testing this project out locally on MAMP, all status's are read 'connected' . the video streaming works, the arduino connection works. however i keep getting this area,

Error: Error #2134: Cannot create SharedObject.
at flash.net::SharedObject$/getRemote()
at com.Red5Link::Red5SharedObject/startSharedObject()[/Users/camoconnell/Documents/folder/Source/com/Red5Link/Red5SharedObject.as:140]

which means the client sliders aren't working. Have you experienced this problem with remote SharedObjects?

in the air app i call;
xmlSocketAppController.sharedObject=new Array("rtmp://camoconnell.local","motors",sharedStatusTxt);

and the client;
xmlSocketController.sharedObject=new Array("rtmp://camoconnell.local","motors",sharedStatusTxt);

thanks cam
odvratno.zgodan (author)  ococa2524 years ago
I haven't had this error before. It seems by the error message that the error is located in the in the class Red5Link. Do the sliders in the client document work or are they unresponsive in both the client and AIR app? In which document the error occurs?
If you don't find the bug in the class, could you send a url where I can check your progress? When I get home from work I'll take a closer look.

Thanks for your reply,

the error is located in the class Red5SharedObject.as on the line where getRemote() method is being called. I get it when i run the ArduinoAir.swf.


The client sliders are moving but they have no effect on the AIR app sliders. I guess its because the sharedObject aren't being shared..

I wonder if it has anything to do with where the files are housed in the directories. the socketShell.php is running on my local MAMP server;

the Client.swf is running on my local red5 server;

and the air app is being published to local folder, not on any local server.

im testing it locally on MAMP & Red5 servers, are you able to view it remotely?

thanks again,
odvratno.zgodan (author)  ococa2524 years ago
I can't view it remotely. You could set up no-ip.org and then I could view it.
When I tested my files the Client.swf was located on my MAMP server not Red5. Try that.
Could you post the whole code for the Client.swf? Have you changed it any way from what you have downloaded from the instructable?
Wehrdo4 years ago
Really cool! I could see lots of uses for this. Are there any free online servers, so you wouldn't have to pay $30 for the hosting plan?

P.S. I got one of the black things with a star on the end. :)
ococa252 Wehrdo4 years ago
hey odvratno, amazing project! bravo

I found a portal site which rates free hosting;
however no red5

I'm already paying monthly for reseller hosting, & my hosting provider won't upload red5 citing potential load issues.

if anyone has a solution pls post it!! i had thought of maybe ustream or skype API as a long shot instead.

- if needed, how would i install red5 locally? for use with MAMP. and Would other computers sharing the same WLAN be able to connect?

odvratno.zgodan (author)  Wehrdo4 years ago
I couldn't find any free hosting plans with red5. You can install it on your computer though. If you find any free hosting please let me know.
9ale74 years ago
never seen this on the newsletter!, definitely worth to be mentioned

LOVE it :)
Uh, why can't I get my prize?
Cool! Will vote.
Spydamonky4 years ago
This and the Portal turret are my favorite i'ables EVER!!!
im using the arduino uno and the code knob to turn a servo it works fine im gessing
Adam Manick4 years ago
This is really cool! Are you going to fix the grabber motor or are you going to leave it as it is? Really cool instructable though.
odvratno.zgodan (author)  Adam Manick4 years ago
Hi, I'm glad that you like it. I already tried to fix the grabber but the gears already wore out so they slip and get stuck. The only thing that I can do is jank it out. Sorry :(
I'm thinking of scaling up the project. Of course the makerbot could help me a lot :)
Cool. I’ll vote for you
Robot Lover4 years ago
I played it a ton! this is so much fun, i tried to get all of the canisters, but the thing that you drop it into was overflowing with them. 5*
I actually own one of these candy grabbers. I got it awhile back and have not done anything with it. What a great idea!
suuun4 years ago
Awesome, I played while u was smoking :-D
SHIFT!4 years ago
Oooohh, THE CLAW!
tamberg4 years ago
Hi odvranto,

cool project! For a simple and scalable way to push data directly to an Intenret-connected Arduino you might want to check our project http://yaler.org/ and http://www.instructables.com/id/Arduino-Web-LED/

odvratno.zgodan (author)  tamberg4 years ago
Wow! Thats so cool and so simple to use. But I couldn't have integrated a queue in it(though I'm not shure), and the video streaming through justin.tv is delayed a few seconds. Using flash and red5 I get a resonable delay on the video and controls, so I opted for it because I'm Flash developer and was curious of red5.
That said, if I saw this instructable before I would have probably given up from my aproach.

Thanks for pointing it out to me,
Hi odvratno,

Yes, the video streaming lags. It's hosted on a PC completely separate from the Arduino and not relayed through the Yaler relay infrastructure.

Queuing of messages would have to be done on the Arduino (or your PC, depending on the setup). The relay infrastructure itself does not have any state and just forwards the HTTP request/response back and forth.

derwassi4 years ago
I Got one of the white thingies:-D How will I receive my price?
Just kidding;-)

Really impressive Work, and a very detailed Instructable! Thumbs up!
odvratno.zgodan (author)  derwassi4 years ago