Control arduino outputs via C++ programs


I need some help to be sure Arduino is suitable for the purpose I’m interested in.

So, I need arduino to control 12 coin-type vibrators with ~1.5 to 3 V each. But this control is dependent from an user interface with a program.

I think, from what I read, that this is possible using the serial/USB port.
And that I can initiate a port with:


And create the control of a specific pin with:

pinMode(ledPin, OUTPUT);

Then, everytime I need to switch ON or OFF I just:


So, this was what I understood.
However, I have some questions, like:

  • this works with the USB/serial the same way?
  • I can use the arduino library in a C++ program? what about for other languages?
  • Can I give orders with DigitalWrite(), perhaps, to more than one output pin at a time?
  • Is there any known delay on these interaction?

Well… thank you very much for your time!

Hi joao!

  1. The USB connection of the Arduino looks like a serial port to your computer (due to the FTDI drivers), so communication works as if it was a normal serial port.

  2. Polling inputs/setting outputs etc. directly from a C++ program could be difficult. There is a firmware for the Arduino called Firmata which lets you use Arduino commands directly from Processing (for processing a corresponding Firmata library exists). So you upload the Firmata sketch onto the Arduino and can then control it directly from Processing. Perhaps something similar exists for C++, though under the hood of the Firmata solution the Arduino is controlled by sending serial messages, too (but kind of invisible to the user).

  3. DigitalWrite() can be used on several pins, as it sets the pin high or low and it remains in its state until you call another digitalWrite() on it. If you have to do a digitalWrite() to several pins simultaneously (that means at exactly the same moment), then you can directly manipulate the ATMega’s port registers (I think that’s what they’re called, never used them myself, but someone else will know better). So yes, this is possible too.

  4. Depending on how much data has to be sent to the Arduino you could roughly estimate the delay for interactions by using the Baud rate. For example at 9600 Baud (1 Baud = 1 bit(second)), you could transfer 9600 bits (=1200 bytes) per second. Afaik, Arduino supports Baudrates up to 115200 Baud (=14400 bytes/second). That’s quite an amount of data per second.

I hope this information is useful for you, be aware that an Arduino pin can source or sink a maximum of 40mA, so you would probably have to control your motors using transistors.

Cheers, Otacon2k

Thanks a lot,

I thought Arduino could also be used as a relay board.
But, it’s not so easy right?

Since Arduino’s language is built on C++ I was expecting a library for direct control from the computer.

I still need to consider a Relay Board then for the purpose!

Many thanks,

I still need to consider a Relay Board then for the purpose!

No you don’t.

Exactly what do you want to do with one?

Is it to relay data or is it to control a relay?

FIRMATA was designed for this kind of scenario.

Nice one, had a quick look at their website. I didn’t know Firmata was so generic, just knew the Processing library…

Well, seems your answer is found then…

Hey, thanks!

So, I’ll go deep on Firmata.

I need to integrate Arduino Control (basically output control) in a C++ program.


Sorry again, after a look on firmata website, I have more doubts!

Is it possible or not to use Arduino and possible firmata glue languages for:

Write a program in C++ or Perl, and include the firmata library for the specific language. Then, during the code, control the ON/OFF of the different outputs of the board.

Thank you all!

Hi everyone,

again, I think I have a new solution that I was not aware of:

I can control arduino via serial connection, and through it give orders using Arduino’s own language. Is this correct?

This way, no matter is the language I am programing on, as long as it has a library to deal with serial. Is this correct?

Thank you, and i really need help,