Controlling rgb-led from PC, via Arduino


I want to controll the color of a rgb-led with an Arduino, and I want to send the RGB values from my computer.

The Arduino recieve one string, with three values ("255;0;0")

How can I move the values from the string, to three variables/int?


Have you got any code to receive the string on the Arduino ? Is it a string (a zero terminated array of chars) or a String (an object created by the String library) ?

Please post any code that you have in full.

Post your whole sketch here.

In the meantime, you may be able to use strtok and atoi depending on how your current sketch works.

Sorry, here is my code:

String inData;

void setup() {

void loop() 
    while (Serial.available() > 0)
        char recieved =; // String should look like this: 12,14,15; 
        inData += recieved; 

        if (recieved == ';')
            Serial.print("Arduino Received: ");
            Serial.println(inData); // inData looks like this: 12,14,15
            inData = ""; // Clear recieved buffer

I save the recieved string in inData.

I have tried some few things with strtok and atoi, but did not understand how to use it..

I save the recieved string in inData.

Actually you are saving the received data in a String not a string. String objects (capital S) have a reputation for fragmenting memory of which there is precious little on most microcontrollers. strings (lowercase s) make better use of memory and functions like strtok work with them unlike Strings.

Have a look at Serial input basics for some ideas in better ways to read Serial data.