How can i read serial data into a string until a certain character is recieved?
What you need to do here is implement a small finite state machine.

Basically you need to look at each character as it comes in and make a decision what to do with it depending on what state you're in at the moment.

Basically the operational decisions you need to make are:


Is the character a &lt; and am I currently not reading a string?


Yes, start reading the string.

Is the character a > and am I currently reading a string?


Yes, finish reading the string and process it

Is it any other character and I am currently reading the string?


Yes, add it to the buffer.



So you can see there some common questions:


What is the character?
What am I doing at the moment?


So you need to have a simple state variable that remembers if you're reading the string or not, and something to say where in the buffer you are so you know where in the buffer to add any incoming characters.

boolean readingString = false;


A simple true/false will suffice to depict if we're reading the string or not.  Start off not reading the string.

char buffer[80] = "";


A buffer to store the text - maximum of 80 characters (including the NULL terminating character)

int charPointer = 0;


Something to know where in the buffer are currently.

Now to read the characters:

First get the next character from the serial port:

loop() {
    if (Serial.available()) {
        int incoming = Serial.read();


Now decide what to do with it.  We have a number of possible situations, some of which can be combined into single options.  For instance, if we get a "&lt;" while reading a string it's an error condition - but do we really care?  It could be that we lost the end of the last string and have just started a fresh one - so we can just treat it as the start of a string regardless of what state we're in.  Let's use a switch for this since it's nice and tidy:

        switch (incoming) {
            case '&lt;':
                readingString = true; // Start reading string
                charPointer = 0; // Set the buffer pointer to the start
                buffer[0] = 0; // Make the string empty
                break;

            case '&gt;':
                if (readingString) {
                    processBufferData(); // Do something with the buffer
                }
                readingString = false; // Finish reading
                break;

            default: // Anything that's not &gt; or &lt;
                // If we are reading the string and the buffer isn't full
                if (readingString &amp;&amp; charPointer &lt; 78) {
                    // Add the character to the buffer and increment the pointer
                    buffer[charPointer++] = incoming;
                    buffer[charPointer] = 0; // Don't forget to terminate the string
                }
        }
    }
}


So the reception of a &lt; starts the string reading, the reception of a > stops it and triggers the processing of the string, and anything else (while we are reading the string) gets added to the buffer.