How to use strings

Hello Everyone,
I am new to arduino trying to blink an led on charchter sent but I want an led to blink when turnonled is typed in the serial monitor and led should go low when turnoffled is typed in the serial monitor..
I have attached code...
Thank you..

const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into

void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}

void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}

Welcome to the forum! But please edit your post and include code tags. See How to use the forum.

And as for the problem, Just check letter for letter. If a letter is right, check the next letter to the next letter. And so on. And if you make it to the end, you know you received the string you wanted to act on :slight_smile:

Ow, and be aware, a String is not the same as a string. To keep things easy, use a array of char's, that's a C-string :slight_smile:

char checkString[] = "turnoffled";

Maybe a new forum category should be added to address questions and answers about the String class. Here is another from today: When to use String - Programming Questions - Arduino Forum