To do that I have used a computer with Ubuntu 12.04 and the program language C++, but if you want to used Windows the code works too, only have to change the port used to conect with arduino, but this is explain in the next step.
This program is only the first version so it must be improved.

Arduino use the usb port to simulate a serial port so we have to use a usb cable to connect the arduino usb port to computer usb port.

Step 1: Program in C++

This is the code of C++, I have created a main class and a Arduino class, so this is object oriented.

#ifndef ARDUINO_H
#define ARDUINO_H

#include <SerialStream.h>
#include <SerialStreamBuf.h>
#include <SerialPort.h>
#include <string>

class Arduino{
    int open);
    DataBuffer read();
    void close();
    string dev = "/dev/ACM0";
    SerialPort serial;

#endif // ARDUINO_H

This is the header of Arduino class.
There are three functions open, read and close.
Open: Open the conection bewteen arduino and the computer.
Read: Read the bufer where is all dates that arduino has send to the computer.
Close: Close the conection bewteen arduino and the computer.

To connect with arduino I have used the port of my computer "/dev/ACM0", if you use Windows instead of Linux you have to use the port "COM1" or "COM2". But to see what port is using arduino you have to use the JDK of arduino and select a port in "Tools -> Serial Port".

# include <Arduino.h>


int Arduino::abrir(){
    int estado = 0;


    if (serial.IsOpen() == false)
        estado = -1;

    return estado;

void Arduino::cerrar(){

DataBuffer Arduino::leer(){
    SerialPort::DataBuffer buffer;
    serial.Read(buffer, 10, 1000);

    return buffer;

This is the code of Arduino class.

#include <iostream>
#include <SerialStream.h>
#include <SerialStreamBuf.h>
#include <SerialPort.h>
#include <string>

using namespace std;
using namespace LibSerial;

int main(int argc, char **argv)
    Arduino arduino();
    return 0;

And finally this is the main class.
<p>Hi, I'm trying to run your code on my mac to send my c++ robot commands to my Arduino Uno that controls my robot motor . So the only thing I changed was the port name, mine is &quot;/dev/cu.usbmodem1421.&quot; But the problem is my xcode does not have any of these Serial libraries you used. I tried to add SerialLib but it didn't work. Since I'm new to Arduino and c++ can you show me how to add the Serial libraries. One more thing after I got it to work do I need to use serial monitor to see if the code's working. </p><p>Thanks in advance</p>
<p>I was able to test scm which is an alternative library to rxtx/javaxcomm for serial port communication. The arduino sent and received data correctly.</p><p>Wiki : <a href="http://www.embeddedunveiled.com/" rel="nofollow"> http://www.embeddedunveiled.com/</a></p><p>Repository : <a href="https://github.com/RishiGupta12/serial-communication-manager" rel="nofollow"> https://github.com/RishiGupta12/serial-communicat...</a></p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/fYLQbelGunQ" width="500"></iframe></p>
<p>Why would one release the code with structure names not in English? That's a bad practice.<br></p>

About This Instructable



More by dvdllms87:How to connect Arduino to a PC through the serial port
Add instructable to: