3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.


Arduino Candygrabber

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. 

UPDATE 2:
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 :-)
 
Remove these adsRemove these ads by Signing Up
 

Step 1What you'll need

What you\
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$ (http://www.adafruit.com/index.php?main_page=product_info&cPath=17_21&products_id=81 )
4.Breadboard
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
2.Screwdrivers
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) - http://www.mamp.info/en/index.html
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 www.videowhisper.com/ ). You can find out more at http://www.red5.org/
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) – www.no-ip.org
5.TinkerProxy – so flash can communicate with arduino - http://code.google.com/p/tinkerit/


Here you can download all the source codes:

UPDATE
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 XMLSocketAppController.as , Red5Broadcast.as and Red5SharedObject.as 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. 

« Previous StepDownload PDFView All StepsNext Step »
26 comments
Jan 29, 2012. 8:18 AMniksen says:
Hi!

Thanks for awesome and detailed tutorial.

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

http://clip2net.com/s/1xb7j

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!
Aug 17, 2011. 5:32 PMococa252 says:
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
Aug 18, 2011. 2:05 AMococa252 says:
Thanks for your reply,

Correct,
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.

sharedObject=SharedObject.getRemote(sharedObjectUrl,netConnection.uri,false);

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;
http://camoconnell.local/socketShell.php

the Client.swf is running on my local red5 server;
http://camoconnell.local:5080/arduino/Client.html

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,
Cam
Mar 29, 2011. 4:21 PMWehrdo says:
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. :)
Aug 16, 2011. 12:15 AMococa252 says:
hey odvratno, amazing project! bravo

I found a portal site which rates free hosting;
http://www.free-webhosts.com/reviews/
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?

thanks,
Cam
May 28, 2011. 3:04 PM9ale7 says:
never seen this on the newsletter!, definitely worth to be mentioned

LOVE it :)
May 19, 2011. 12:54 PMtech123456789 says:
Uh, why can't I get my prize?
May 19, 2011. 12:40 PMtech123456789 says:
Cool! Will vote.
May 17, 2011. 11:28 PMDemonSpawn says:
This and the Portal turret are my favorite i'ables EVER!!!
May 14, 2011. 12:55 PMJordan arduino says:
im using the arduino uno and the code knob to turn a servo it works fine im gessing
May 11, 2011. 5:09 PMAdam Manick says:
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.
May 13, 2011. 4:27 PMAdam Manick says:
Cool. I’ll vote for you
May 13, 2011. 10:59 AMRobot Lover says:
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*
May 13, 2011. 12:10 AMNaturalCrafter says:
I actually own one of these candy grabbers. I got it awhile back and have not done anything with it. What a great idea!
May 11, 2011. 3:59 AMsuuun says:
Awesome, I played while u was smoking :-D
May 9, 2011. 1:23 PMSHIFT! says:
Oooohh, THE CLAW!
Mar 31, 2011. 2:35 AMtamberg says:
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/

Cheers,
tamberg
Mar 31, 2011. 9:26 AMtamberg says:
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.

Cheers,
tamberg
Mar 27, 2011. 2:07 PMderwassi says:
Yiiieeehhaaaaa!
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!

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
25
Followers
1
Author:odvratno.zgodan