title: How can I receive data from a PC to an Arduino?
body: <p>I developed an application that sends data for an Arduino by the serial port, but I can't understand how I can receive it on the Arduino. I send a string by the serial port for the Arduino and the Arduino receives it, but it does not work in my code (on the Arduino, I receive a byte at a time).</p>
  
  <p><strong>Update: it's working ;)</strong></p>
  
  <p>The code in C# that sends data:</p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  
  using System.Threading;
  using System.IO;
  using System.IO.Ports;
  
  pulic class senddata() {
  
      private void Form1_Load(object sender, System.EventArgs e)
      {
          //Define a serial port.
          serialPort1.PortName = textBox2.Text;
          serialPort1.BaudRate = 9600;
          serialPort1.Open();
      }
  
      private void button1_Click(object sender, System.EventArgs e)
      {
          serialPort1.Write("10");  //This is a string. The 1 is a command. 0 is interpeter.
      }
  }
  </code></pre>
  
  <p>The Arduino code:</p>
  
  <p><strong>I have Update the Code</strong></p>
  
  <pre><code>#include &lt;Servo.h&gt;
  
  Servo servo;
  String incomingString;
  int pos;
  
  void setup()
  {
      servo.attach(9);
      Serial.begin(9600);
      incomingString = "";
  }
  
  void loop()
  {
      if(Serial.available())
      {
          // Read a byte from the serial buffer.
          char incomingByte = (char)Serial.read();
          incomingString += incomingByte;
  
          // Checks for null termination of the string.
          if (incomingByte == '0') { //When 0 execute the code, the last byte is 0.
              if (incomingString == "10") { //The string is 1 and the last byte 0... because incomingString += incomingByte.
                  servo.write(90);
              }
              incomingString = "";
          }
      }
  }
  </code></pre>