Problem with serial data communication

Hello everybody,

Today I got my Arduino which is great. Board and software setup fine as well. I tried to write a sketch with serial data communication but even the simplest sketch did not work properly. The example below should just output the number of characters the user sends to the board. The board seems to receive data properly (LED flashes) but the output is always crap. Sometimes nothing happens, sometimes the result is wrong.
Is there still a problem with the code or do I have a problem with the hardware? Could somebody try the sketch on your computer.
Thanks in advance for any hint!

/*

  • Serial Output Test

*/

void setup()
{
Serial.begin(9600);
Serial.flush();
}

void loop()
{
if (Serial.available()>0) {
delay(100);
int numChar = Serial.available();
Serial.println("Test");
Serial.println(numChar);
}
Serial.flush();
}

the simplest sketch did not work properly

but the output is always crap

These are not very helpful diagnostics.
Is it in hieroglyphs?
Base-13?

Try removing that Serial.flush(); in your main loop and then see if the symptom changes.

Lefty

@ awol: You're right that was not too precise but it was already around midnight...

@Lefty
When I removed the Serial.flush I got into a permanent loop where my first entry got sent to the serial monitor over and over again until I entered a new number.
But after I included it into the if statement it worked fine. Now I have something I can build on.
Many Thanks !!!
Cielful

/*

  • Serial Output

*/

void setup()
{
Serial.begin(9600);
Serial.flush();
}

void loop() // run over and over again
{
if (Serial.available()>0) {
delay(500);
int numChar = Serial.available();
Serial.println("Test");
Serial.println(numChar);
numChar = 0;
Serial.flush();
}
}