Introduction: Control a Arduino With Your Phone.
In this Instructable I'll show how to control your stuff with your phone and the arduino board. I've controlled everything from smoke machines too christmas light's with this program.
Video:
sorry the video is kinda odd because my camera is trying to adjusting for the light difference.
Step 1: The Parts
The parts
-NPN transistor
-Iphone/ Android(Using Iphone)
-The TouchOSC app (awesome app)
-Arduino 5v (any type)
-some wire
-Soldering iron
-Breadboard (optional but recommended)
- A Mac or PC
-Some sort of remote or low power button (anything that runs on AA,AAA batteries is usually fine)
-If you want to control a appliance look at the last step fore more info.
and thats it!
Step 2: Open Your Device (low Power)
Hopefully you can figure out this step by yourself. Remove a screw or two and open it. In the pictures Im opening an LED strobe lamp.
Step 3: Find the Button
Now on the the circuit board from you device find the button/switch you want to control with your smartphone. For me it was the On/Off switch on the strobe lamp. if your opening a remote control you likely find these pads shown in the 2nd picture
Step 4: Solder to the Contacts
Once you have found the contacts solder some wire to them, one for the positive and another for the ground. I strongly recommend using solid strand wire as its much easier to solder. For more help look at the photos.
Step 5: Connect the Transistor
Now you will need to connect your transistor to your Arduino and to your device. Look at the picture below for how to wire it up. I have annotated it if you need help. That little black thing is your device. If you know the polarity of the wires you can connect the positive to the left terminal of the transmitter and the ground to the right terminal
If you want to control more buttons connect additional transistor's the same way but instead of using pin 12 use 8, 9 or 11
Step 6: Make a TouchOSC Layout
Skip this step if your on Android!
1.Download the TouchOSC editor from here
2. Watch the video for a quick how to, on creating a layout.
3.Make your own layout
Right click to make a button and select pushbutton
you can have up to 4 buttons
4. When your done click the sync button and follow the on screen instructions.
Step 7: TouchOSC
1.Download TouchOSC to your iPhone/ Android
I imagine you will be able to find the app by searching for it on your local app store, if not go to hexler.net to find more info.
2.Find your IP
on a PC: start >run >cmd
Once your in command line type "ipconfig" (without quotes) and hit enter. your iP is next to the line "IPv4 address" it should be in this format"192.168.0.000" the 0's is your personal number
on a mac: click the apple at the top left of the screen, Then click about this mac.
Then more info. Then network. your ip will be under the IPv4 heading, it should be in this format"192.168.0.000" the 0's is your personal number
3. configure TouchOSC
On a iPhone:
I have attached pictures at the bottom for help. Just match your pages to mine except the ip/host address where you can replace the ?'s with your own IP address. the first picture is the main page make sure stay connected is on, Then click the box that says not configured and set it up according to the second photo just replace the ?'s with your address.
On Android:
I don't actually own an Android so I'm not sure how to configure it but i imagine it is very similar to the iPhone. If you own an Android device it would be great if you could post some pics to put in the Instructable
If you need any help just leave a comment below and i will try to help as fast as i can
Step 8: Setup the Programs
1. If you don't have it already download processing IDE from processing.org.
2. You will need to download the oscP5 library for processing
Go here and download the library. Extract the files and move the folder oscP5 to this directory {C:\Users\[your user name]\Documents\Processing\libraries\[put the folder here]}
3. Open the the code which can be downloaded below and open it in it's respective program.
For some reason Instructables renames the programs files so rema,e them back to the orignal (ControlArduino.pde)
The Processing IDE works just like the Arduino IDE. File->open
control Arduino goes with the Arduino IDE or vice versa
4. Select the COM port for the Arduino board in the Arduino IDE and remember the number.
Tools-> serial port-> COM?
5. Bring up the processing IDE and change "COM4" in the line " arduinoPort = new Serial(this, "COM4", 9600)" to the Arduino serial port you found in the previous step.
Step 9: Try It Out/Troubleshoot!!
Your almost done
1. Upload the code to the Arduino
2. Run the processing code.
3. Open the TouchOSC app
Just hit done in the right corner.
4. Hope it works!
If it doesn't work, don't fret.
You very likely got the polarity wrong. To solve this flip the wires that connect the transistor to your device and try it again.
If it still doesn't work leave a comment below and i will try to help
Thank you for reading my instructable! please Vote for this If you like it!
Step 10: Expansions
Your probably thinking "This is great but how can i control my coffee maker with my phone?"
Well here's the solution, You will need a relay. It allows you to control 110v/220v voltages.
I recommend getting a power switch tail available here .
If you feel to do something more DIY Sparkfun has a tutorial that can be found here
And if your dumb like me you can buy a relay board off eBay by searching "relay 5V board Arduino" and parse it into a extension cable and shock yourself while doing it.
These boards connect the same way as a transistor.

Participated in the
Microcontroller Contest
42 Comments
8 years ago
You need a wifi shield correct??
9 years ago
Visit my instruction for how to download paid apps for free!!!!!!!!!!!!!!!!!!!!!!thanks
9 years ago
Is there any other options you might know besides arduino? I seen these Smart appliances at a pretty compact size. The size resembles something much smaller then an Arduino uno.
9 years ago on Step 9
Hi, I can´t get the code i processing to work. When I try to run it, it says Found one too many ( charaters without a ) match it.
The Arduino stands with a constant voltage out from the transistor is that right also?
Hope you can help :-)
10 years ago on Step 10
looks like a line follower in the back
11 years ago on Step 8
hi, nice article, can you readd pde filoes? Because i can only download tem files, and when I rename them to pde, aplication is incomplete:
import processing.serial.*;
import oscP5.*;
import netP5.*;
OscP5 oscP5;
int alphaValue;
Serial arduinoPort;
float v_push1 = 0.0f;
float v_push2 = 0.0f;
float v_push3 = 0.0f;
float v_push4 = 0.0f;
void setup() {
size(320,440);
frameRate(25);
arduinoPort = new Serial(this, "COM1", 9600);//change to the serial port arduino is on
/* start oscP5, listening for incoming messages at port 8000 */
oscP5 = new OscP5(this,8000);
}
void oscEvent(OscMessage theOscMessage) {
String addr = theOscMessage.addrPattern();
float val = theOscMessage.get(0).floatValue();
if(addr.equals("/1/push1")) { v_push1 = val; }
else if(addr.equals("/1/push2")) { v_push2 = val; }
else if(addr.equals("/1/push3")) { v_push3 = val; }
else if(addr.equals("/1/push4")) { v_push4 = val; }
}
void draw() {
background(0);
// fader5 + push 1-4 outlines
fill(0);
stroke(0, 196, 168);
rect(17,21,287,55);
rect(17,369,60,50);
rect(92,369,60,50);
rect(168,369,60,50);
rect(244,369,60,50);
// fader5 + push 1-4 fills
fill(0, 196, 168);
if(v_push1 == 1.0f) rect(22,374,50,40);
if(v_push2 == 1.0f) rect(97,374,50,40);
if(v_push3 == 1.0f) rect(173,374,50,40);
if(v_push4 == 1.0f) rect(249,374,50,40);
if(v_push1 == 1.0f) arduinoPort.write("U");
if(v_push1 == 0.0f) arduinoPort.write("u");
if(v_push2 == 1.0f) arduinoPort.write("D");
if(v_push2 == 0.0f) arduinoPort.write("d");
if(v_push3 == 1.0f) arduinoPort.write("L");
if(v_push3 == 0.0f) arduinoPort.write("l");
if(v_push4 == 1.0f) arduinoPort.write("R");
if(v_push4 == 0.0f) arduinoPort.write("r");
as I see the rest is missing.
Reply 11 years ago on Step 8
It should run if it does not. Try this
import processing.serial.*;
import oscP5.*;
import netP5.*;
OscP5 oscP5;
int alphaValue;
Serial arduinoPort;
float v_push1 = 0.0f;
float v_push2 = 0.0f;
float v_push3 = 0.0f;
float v_push4 = 0.0f;
void setup() {
size(320,440);
frameRate(25);
arduinoPort = new Serial(this, "COM1", 9600);//change to the serial port arduino is on
/* start oscP5, listening for incoming messages at port 8000 */
oscP5 = new OscP5(this,8000);
}
void oscEvent(OscMessage theOscMessage) {
String addr = theOscMessage.addrPattern();
float val = theOscMessage.get(0).floatValue();
if(addr.equals("/1/push1")) { v_push1 = val; }
else if(addr.equals("/1/push2")) { v_push2 = val; }
else if(addr.equals("/1/push3")) { v_push3 = val; }
else if(addr.equals("/1/push4")) { v_push4 = val; }
}
void draw() {
background(0);
// fader5 + push 1-4 outlines
fill(0);
stroke(0, 196, 168);
rect(17,21,287,55);
rect(17,369,60,50);
rect(92,369,60,50);
rect(168,369,60,50);
rect(244,369,60,50);
// fader5 + push 1-4 fills
fill(0, 196, 168);
if(v_push1 == 1.0f) rect(22,374,50,40);
if(v_push2 == 1.0f) rect(97,374,50,40);
if(v_push3 == 1.0f) rect(173,374,50,40);
if(v_push4 == 1.0f) rect(249,374,50,40);
if(v_push1 == 1.0f) arduinoPort.write("U");
if(v_push1 == 0.0f) arduinoPort.write("u");
if(v_push2 == 1.0f) arduinoPort.write("D");
if(v_push2 == 0.0f) arduinoPort.write("d");
if(v_push3 == 1.0f) arduinoPort.write("L");
if(v_push3 == 0.0f) arduinoPort.write("l");
if(v_push4 == 1.0f) arduinoPort.write("R");
if(v_push4 == 0.0f) arduinoPort.write("r");
}
Reply 10 years ago on Step 8
is it possible to change it a little bit to only send once to the arduino after you let go of a button? like some to the lines of
if(v_push1 == 1.0f)
then(v_push1 == 0.0f) arduinoPort.write("1");
so it reads that you push then sends the 1 once after you let go
Reply 10 years ago on Step 8
yup, I think this should work but I don't have the chance to test it right now.
int var
if (v_push1 == 1.0f) {
var = 1;
}
else if(v_push == 0.0f & var==1){
var = 0;
arduinoPort.write("D");
}
Reply 10 years ago on Step 8
works great till i add the other 2 buttons here is the last part would like help if its not a problem :)
void draw() {
background(0);
// fader5 + push 1-4 outlines
fill(0);
stroke(0, 196, 168);
rect(17,21,287,55);
rect(17,369,60,50);
rect(92,369,60,50);
rect(168,369,60,50);
rect(244,369,60,50);
// fader5 + push 1-4 fills
fill(0, 196, 168);
if(v_push1 == 1.0f) rect(22,374,50,40);
if(v_push2 == 1.0f) rect(97,374,50,40);
if(v_push3 == 1.0f) rect(173,374,50,40);
if (v_push1 == 1.0f) {
var = 1;
}
else if(v_push1 == 0.0f & var==1){
var = 0;
arduinoPort.write("1");
}
if (v_push2 == 1.0f) {
var = 1;
}
else if(v_push2 == 0.0f & var==1){
var = 0;
arduinoPort.write("2");
}
if (v_push3 == 1.0f) {
var = 1;
}
else if(v_push3 == 0.0f & var==1){
var = 0;
arduinoPort.write("3");
}
}
Reply 10 years ago on Introduction
if i run this code the errors come out like this:
sketch_oct30a:-1: error: variable or field 'oscEvent' declared void
sketch_oct30a:-1: error: 'OscMessage' was not declared in this scope
sketch_oct30a:0: error: 'import' does not name a type
sketch_oct30a:1: error: 'import' does not name a type
sketch_oct30a:2: error: 'import' does not name a type
sketch_oct30a:3: error: 'OscP5' does not name a type
sketch_oct30a:5: error: 'Serial' does not name a type
sketch_oct30a.cpp: In function 'void setup()':
sketch_oct30a:14: error: 'size' was not declared in this scope
sketch_oct30a:15: error: 'frameRate' was not declared in this scope
sketch_oct30a:16: error: 'arduinoPort' was not declared in this scope
sketch_oct30a:16: error: expected type-specifier before 'Serial'
sketch_oct30a:16: error: expected `;' before 'Serial'
sketch_oct30a:18: error: 'oscP5' was not declared in this scope
sketch_oct30a:18: error: expected type-specifier before 'OscP5'
sketch_oct30a:18: error: expected `;' before 'OscP5'
sketch_oct30a.cpp: At global scope:
sketch_oct30a:22: error: variable or field 'oscEvent' declared void
sketch_oct30a:22: error: 'OscMessage' was not declared in this scope
help please!
10 years ago on Step 8
What about on Mac please respond
Reply 10 years ago on Step 8
it should be almost exactly the same but you will have to find your network settings. I don't own a mac any more so I can't confirm whether it will work or not
10 years ago on Step 8
I am getting this error message:
ERROR @ OscP5 ERROR. an error occured while forwarding an OscMessage
to a method in your program. please check your code for any
possible errors that might occur in the method where incoming
OscMessages are parsed e.g. check for casting errors, possible
nullpointers, array overflows ... .
method in charge : oscEvent java.lang.reflect.InvocationTargetException
Reply 10 years ago on Step 8
Sorry for the late response. Make sure the network settings are correct.
Is this error occurring while compiling or running?
10 years ago on Step 7
Dude this is great I am just starting arduino and am wondering about where the contacts are and that whole step just confused me could u write me up a simpler way thank you
Reply 10 years ago on Step 7
Step five was the confusing one
10 years ago on Step 9
my Arduino doesn't seem to be registering any response form the app? i don't know if it has anything to do the the outgoing port? yours is 900 but i don't know if that is correct for me? when i run the processing code it loads my browser with a panel that looks something like the app once i click done but it does have the yellow bars or anything that the actual app has.
10 years ago on Introduction
I am a bit unsure how to find the information being asked on step 8, 4 and 5. I am using a mac if it matters :]
11 years ago on Step 8
By the way, does anyone knows good samples ar tutorial using TouchOSC and Microsoft Visual c++?