how to send input values from host computer to arduino,such that speficing the number of rotations for a stepper motor etc

  • Via serial. Most CNCs and 3D printers send GCode over serial.
    – Gerben
    Apr 15, 2015 at 19:18

1 Answer 1


The easiest method is to use the serial communication. Use the sample code at http://arduino.cc/en/Tutorial/SwitchCase2, upload that to an Arduino, start the serial monitor (Ctrl+Shift+M), make sure the baud rate is the same as set in the code (9600 in this case), then write the commands and send them to the Arduino.

Edit Since the serial characters are usually read one by one you need a character that will signal the end of the string. This is usually a newline \n, but can be any character you choose (and can be sent to Arduino).

Sample code (processString would be your function to do something with the string):

char buf[64];
byte cnt = 0;
void loop() 
    while (Serial.available()>0) {
        byte c = Serial.read();
        // Check for terminator character or the size of buffer
        if (c == '\n' || cnt >= 63) {
            // Add the terminating 0
            buf[cnt] = 0;
            // Process the full string
            // Prepare to read the next string
            cnt = 0;
        } else {
            // Not terminator - add to string
            buf[cnt++] = c;
  • okay.If i want to sent a string the same read() is used? Is there any modifications needed for sending strings? Apr 16, 2015 at 3:40
  • check my updated answer above
    – rslite
    Apr 16, 2015 at 13:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.