This tutorial was featured on the official Arduino blog on 3/9/2011
The next four episodes are all about communicating between the Arduino and other devices. In this video, we’ll focus on communicating with the computer via a standard serial connection. We’ll be using a new programming language called “processing” to visualize some information from the Arduino on the computer screen. If you are new to processing, they have an excellent set of tutorials to help you get started.
The Arduino Contest has been extended! You only have 1 more week to submit your project!
Serial.flush() has changed in Arduino 1.0. You can use the following instead:
You can download the files associated with this episode here:
Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.
Question: How can I connect 3 potentiometers to the Arduino and let them control the RGB colors one by one with processing?
It just so happens that arduino has that exact tutorial on their website! http://arduino.cc/en/Tutorial/VirtualColorMixer
May i know how to wirte the source code for appilcation using vb.net to communicate with Arduino Uno? Thanks
this article explains how to access serial ports with Visual Basic. http://support.microsoft.com/kb/823179
Jeremy this tutorial is amazing, i want to adquire an Arduino Uno, but i´m only know vb.net, could you show a tutorial or something related interfacing the arduino Uno with vb.net, like this same tutorial?
It may just be easier if you use the netduino, since it is programmed in .NET: http://www.netduino.com/
Amazing tutorial series! Finally, someone willing to show us how to go beyond the basics. Thank you.
I want to make a MAME cabinet. Is it possible to use an Arduino Uno for all the button controls? (ie like 12 buttons) Can the Serial handle the speed that I might need to play games with?
It should be able to. You can set the baud rate to whatever you want for serial communication.
thanks for the help,can i ask to do a PHP to Arduino tutorial,it will be very
helpfull,i need to conect each other to control a light in physical space and
Check out the source code from this project that I did a while back: https://jeremyblum.com/2010/03/05/arduino-website-stats/
Already done it ,thanks.I need to make a switch in my site with php to control a light connected with arduino,do i need processing in the middle?I am new with php…any help is
very important.Thanks for the responce.(I think you are using wordpress here and its leaving user information in the Reply form)
It depends where php is running. Is the PHP server on the same computer that the arduino is connected to? If so, you don’t need an intermediary. If it’s a remote server, you’ll need to make a PHP script on the remote server that saves data to a txt file or a database. A separate program, written in something like python or processing will need to run on your local computer and poll the remote data to update the arduino via serial. You can also skip the local computer completely by getting an ethernet shield for the arduino.
I think i will start with local computer setup and then move on ethernet shield(which is great solution!)A remote server is best for my project,i better start coding,is a long way..Thanks for the advise Jeremy and keep on
Im currently combining your tutorial on motors with serial comms. Im trying to read the the value of the motorPin and println to serial. This seems to be working baring the fact that the value is only read at the end of the loop cycle. How can I make read and println the value continuously as it changes?
Can you post the code?
Thanks for your response but I have managed to solve my issue as well as a couple of others with a days tinkering. Thank you anyway :)) Your tutorials are a huge help!
Hi jeremy. Great tutorials. im sorry if i commented here i dont know where is the topic for ethernet shields. my question is Can i use arduino uno and an ethernet shield because i saw a project which i want to do but it uses a arduino duemilanove but its not available at element 14 only uno? i ask you because this is my first project and i dont want to waste money on my first project. if you dont mind can you give me the idea on this project its a simple on and off but web based so you can control it anywhere at first a want to test it on led then scale up to 220v light and i will use solid state relays. thanks
The Uno is the newest version of the arduino, and will work just fine with the ethernet shield. Good luck with your project!
thanks for your response. im sorry i have another question how can i connect my arduino to a rented web server so i can control my arduino anywhere with internet access and i want to use php because i will make a log in for my project and that log in requires database and if i have database i can do many things to my project like an estimated cost of the electricity bill. thanks!
You need to have physical access to the webserver to connect the arduino to it.
do you mean the mac address of the webserver? Is it possible to connect my ethernet shield for example if i rent a server at hostgator, can you please give me some source codes? I saw your project the roboclaw and web controlled my project is something like that but not a robot only lights and temperature sensors. thanks again for the reply it helps me alot.
If you want to use your arduino directly as a server, you don’t need to rent one as well. You can actually build a very simple web server on an embedded platform like the arduino. Then serve webpages from it directly, and control your device like that. That’s how I made the roboclaw.
I can make the arduino a web server but how to serve the webpages on the arduino anywhere not only on the local network then control it anywhere via internet.?thanks!
You’ll need to give the arduino a static IP internal to your network. Then forward external port 80 on your router to port 80 on your ARduino’s IP address. Last, use a service like dyndns to assign your ISP-assigned external IP to a URL.
Wow Thanks ! i will message you again if i have problems thanks again but is there way for me to use php for my pages like hosting them on a free hosting because the arduino webserver doesnt support Php? but I will try html first im just asking so when i want to enhance my pages i could use it. THanks!
Yes, you could use PHP on a normal server and use it to send post commands to an html page hosted on your arduino.
Hi and realy a nice tutorail, but i have a question.
I am making an app for my android cellphone so i use processing.
The app has to do following when i press it a screens goes open and i have a colorwheel. The value that i press has to be send via internet to the arduino ethernet shield. And from there via the PWM outputs to the RGB led. But only my cellphone may make connection to the arduino ethernet shield. How to make this??
I don’t understand how you’re using processing on your android phone. Why not just build a mobile website that you can visit from your phone that sends data to the arduino?
yes but i have made a server on the arduino via the ethernet shield. and i make connection with that, but i dont know how to send my signal like when i press the value of rgb ( 0, 245,15) or something like that to my arduino ethernet shield. Well i dont know how to make the code that when i press it that that goes to my PWM outputs. If you know what i mean.
Send it as a GET variable to your arduino server, like this: , where 192.168.1.200 would be replaced with the actual local IP address of your arduino server.
And i found out how to do it, I am using the RESTduino, thx to that i just have to set in my processing a line with link(IP adress/port number/variable)
Would you happen to know the best way to interface a scanner with the ardunio, i want to control its on/off functionality using a switch, but i”m having trouble interfacing the scanner with the ardunio
Like a photo scanner? If you just want to turn the scanner on/off with a switch, an arduino is un-needed. just wire a switch inline with the scanner power.
sorry i might be a bit confusing but i mean a gui type switch like an embedded application that enables a user to touch a button on the screen and activate the scanner
You mean to initialize the scan? The scanner probably uses a proprietary protocol for that. You’d have to do some reverse engineering of their software if you wanted to initialize the scan. Some programming languages might have hooks built in for interfacing with scanners.
Hey Jeremy! I really love this tutorial (and all of your others) Very Clear and Helpful. I was just wondering what the next step would be with this project to change the color of a screen that is being hosted
Being hosted? What do you mean? The next step is whatever you want it be.
like if i wanted to change the color of a website with the pot, and it would be displayed live on the internet so that people could visit the site and see it being changed by me.
You might want to check out http://www.thingspeak.com
Sir I want material or a link or a tutorial that can help me how to control robot using android app.
I am very much new to arduino plz help me.
Check out this: http://www.amarino-toolkit.net/
i am writing a c code to send values to an arduino decimilia which will control a motor
the problem is that everytime i run the program it accepts only one input value after which it crashes with the error message: write access violation
i am using visual studio .net 2003 to build the application and run it
any ideas as to what might be wrong?
Sounds like you might be overflowing a buffer, but I’m honestly not sure – I don’t use .net too much.
hey I am trying to use camera to detect color!!!
so I want arduino to have serial communication with camera.
But somehow is doesn’t work. could it be code problem?
Could be. You haven’t really given me enough info. What kind of camera is it?
WARNING : RXTX Version mismatch
Jar version = RXTX-2.pres1
native lib Version = RXTX-2.2pres2
This show me when I run the program, everything is ok , but the screen doesn’t chance the color.
I know the answer for Warning: RXTX Version mismathc, if some one have the same problem just send me an email. [email protected]
Hey jeremy I need move a servo with bend sensor or flex sensor. You have a example? I need a code and connection.
Watch my motor tutorial and my analog sensor tutorial.
hi Jeremy. Can’t you please help me create a program to control 2 stepper-motor from my computer using serial. thank you
Great tutorial series, excellent job explaining things. Please check out my first project, based on your tutorials, a super fast and very accurate light sensor with a processing output to view 4 parameters!! http://youtu.be/FaxZ_JfYrV8
Great work! If you’re willing to post the source code and schematics as open-source online, let me know and I’d be happy to host it on my site.
Jeremy you do amazing tutorials!! thank you a lot for that!
Well, I got a question, I’m trying to connect : Arduino->Processing->MySQL->PHP.
I want to upload the data received from the Arduino to my webpage.
So, Do you know any example code using processing and PHP at the same time? I’m having trouble doing this. Thanks a lot!!
Check out this thread: http://forum.processing.org/topic/http-post-processing
Jeremy Thanks for the tutorials. I am having more fun than my wife can handle with the Arduino Uno. My knowledge of C or C Plus Plus is limited. But your tutorials are really helping me to learn..
Just a thanks
I need help, I typed in all the code completely right but when I run it I get an error saying that serial port 9600 or COM 23 is in use. How ca I fix this?
It means another program is using the COM port. unplug the arduino and plug it back in again, or restart your computer.
Hi Jeremy, how can I replace user value from 0 and 1 to A and B..??? In this tutorial you just write “int val = Serial.read() – 1;”..but when I replaced all 0 to A and 1 to B and once I press A it work with LED ON but if I pressed B it write “Invalid!”..Could you help me how to off the LED with B..
int ledPin = 13;
//Create Serial Object
//Have the arduino wait to receive input
while (Serial.available() == A);
//Read the Input
int val = Serial.read() – ‘A’;
if (val == B)
Serial.println(“Led is On”);
else if (val == A)
Serial.println(“Led is Off”);
Change serial.read and serial.available lines back to what they were in my original code, and ensure the letters are treated as chars by putting them in single quotes for your if statements.
hi jeremy, hope you are doing great…, thanks for your contribution to get a great carrier in robotics as an beginner… hope such really nice presentations for future also…
hi..this is sumanth……i am doing a project on “Burglar alarm system” ….can u please suggest me how to interface the web cam on arduino (uno) board plz……it would be helpful for me……
Lookin forward for your reply…..Thank you
The ardunio doesn’t really have enough power to process live video signals. You might be better off with a beagleboard.
Hi jeremy,your tutorials are really some piece. Here’s what I need your help in – I need a processing code that will be used to generate 4 tab like applets & which will be used to control 2 motors via Arduino . I’am new to processing & hence not getting any single idea about it. I need your help here . Looking forward for your reply. I’ve also tried visiting the processing .org for free tutorials, but didn’t seemed to help me exactly .
I can’t write out programs for everybody unfortunately, and I’m not an expert a processing myself. I suggest you start playing with it, and ask specific questions on the processing forum.
I am from Germany and my English is rather poor.
I just started to use Arduino and now I found your tutorials.
You make a very great work!
I dont speak very good English, but I understood nearly everything.
It is a pleasure to follow your instructions – especially for beginners like me.
Thank you very much!
I’ve been trying to do a serial comm between the arduino and processing but … it keeps getting exception on serial comm is already in used.
Any solution for it ???
*The baud rate and port is set to the same for both
Thanks alot !
DO you already have it connected to the arduino serial monitor? Only one program on your computer can use the serial port at a time.
hi jeremy, can u please guide for my project?…i am trying to build LED matrix using arduino clone and interface it using visual basic…the problem is i don’t know hot to connect arduino and VB…can u please guide me in constructing the code?…
thanks a lot…
I’ve never used VB with the arduino, so I don’t have any sample code. You’ll need to find out how to communicate with a serial port from VB.
Hi, jer. Is it possible to use arduino microcontroller that already has motor driver . Romeo all in one 328, how can i attach rc
Receiver with spektrum . Is it just direct plug receiver signal into the serial communication tx.
Any code that you .Have encountered. If there is 2 motors for differential drive should we need to use 2 channel meaning 2 tx assuming i power the receiver directly.
Appreciate your views on this
I haven’t used that, but if it’s serial, you’ll just need to plug it into the arduino’s UART interface. Keep in mind that you will need to unplug it while programming and vice versa.
Great tutorials! Wow where do you find the time?
I want to use the arduino to read the data from a USB mouse then output this data to the computer.
Can I use the UNO of will I have to go to the Mega?
It might be possible to read PS/2-style mouse signals, but reading the USB commands will be a bit more difficult.
I’m trying to use this method to use two potentiometers and a button to make an Etch-A-Sketch programme, with the potentiometers controlling the X and Y points of the line and the button to clear the canvas.
I can make a drawing programme in Processing with the mouse controlling the line and have also managed to write one that displays the value of the potentiometers. However, I’m really don’t know how to map the X and Y values to the potValue from the Arduino sketch. Would you be able to provide some guidance please?
I’m doing a project in arduino using ultrasonic sensor.
I just want to ask how can I connect it to vb.net so that vb.net can read the output of Arduino? Arduino Sends 1 & 0 in serial monitor.Just want to vb.net to post it in its window..
Hoping for your positive reply..
I tried to get some sensor data displayed from my arduino using processing. But am not getting the same values which i get in the serial monitor of arduino in the processing graph..could u help me on this?Could you pls guide me on this..!
I want to communicate between two Arduino Uno boards through XBee. The first board senses an analog signal through the analog input pins and converts it into a PWM and transmits through the Xbee. In the receiver end, i want to receive that PWM and convert it into the same Analog voltage variations. is it possible to do so? if it is, then can you please give me the link for the code of the receiver end?
How do I use the serial port to send the value 0 or 1 without pressing enter?
I want to control two motors left and right, both together t moves forward
And one at the time to turn.
So far I updated you code from this tutorial, and it work fine but I have to press enter all the time.
I will appreciate all the help I can get.
Thank in advance
sir jeremy,can u give me some knowledge about our project,,pur project is Automatic Vehicle Identification using RFID,im a bit confuse on what should be writtin in Vb 2006 to control tHe gate barrier(SERVO MOTOR)
can you show me some example how to use void SerialEvent()? I wrote an application like this as follow, but it doesn’t work, i don’t know why.
boolean bInput = false;
bInput = false;
bInput = true;
Hi Jeremy! Our group is working on an SMS controller which can turn an appliance ON and OFF. It is composed of a GSM module (SIM900D), microcontroller (Gizduino), relay card, and power analyzer. Don’t mind the relay card and the power analyzer, our problem lies on the communication of the microcontroller and the GSM module. Here’s how it works: the user will send a command via SMS using his mobile phone (ON, OFF or ASK), microcontroller will digitalWrite the pins connected to the relay and power analyzer HIGH if it receives a text “ON” and will digitalWrite the pins LOW if an “OFF” message is received. We were told that we need to interface AT commands in Arduino, can you help us with this? You may email me at [email protected] Thanks a lot! :)