Serial I/O Help


I just got an Arduino Duemilanove a few weeks ago. I need some help with Serial Input. I want to be able to type in a string and have the serial monitor output it back. I was able to do it with numbers, but haven’t been able to do it with a string without printing the increments. (ex. I input truck, output is t tr tru truc truck)

I want to be able to echo the string WITHOUT any header/footer chars, and, if possible, not have a set max. length.

What I want is:

Input: String Echoing Program Test
Output: String Echoing Program Test

But I only want the output to display once-- not repeat over and over again.

Here’s what I have so far.

#include <WString.h> 

int length;

char temp;
String outString = String(60); 
int stat = 0; 

void setup () {



void loop () {

  if(Serial.available() > 0 && stat == 0) {

    length = Serial.available(); 


  else if (Serial.available() > 0) {

    while(Serial.available() < 0) {

      temp =;
      stat = 1; 


  else if (stat == 1 && length == outString.length()) {  
    stat = 0;
    outString = ""; 

By the way, I know C and C++.

Thanks in advance.

If you know C/C++, you are way ahead of me! Anyhow the looping examples generally given caused me confusion. After tinkering for a while I managed to put together the below simple code that uses the WString.h library (which apparently handles input array development internally).

//zoomkat 8-6-10 serial I/O string test
//type a string in serial monitor, then send or enter

#include <WString.h>
String readString = String(100);

void setup() {

void loop() {

        while (Serial.available()) {
          if (Serial.available() >0) {
        char c =;
        readString.append(c); }
      if (readString.length() >0) {

Thanks, zoomkat! It works!