so on S05150E
S will mean that we are STARTing to send data
05 will mean that we choose to store data on input[5] variable
150 will mean that we chose number 150 to store ( on variable input[5])
E will mean that we inform chip that we are ENDING transmiting
This is a protocol. A specific definition of the data stream, and a set of instructions for parsing and using the data. Nicely done.
maybe there is a better idea on how to storing data to variables
The first step in defining a method is to define a protocol. You've done that.
can anyone help me on how can i do that?
The next step is to implement that protocol on both the sender and the receiver.
As you mentioned, you'll need a while loop on the Arduino that will read each character that is in the serial buffer. Within that while look, you'll need to test each character to see if it is the start character ('S'), or the end character ('E').
When it is the start character, initialize an array to hold the data (inData[0] = '\0';) and an index into that array (index = 0;). Set a flag (started = true;) that indicates that the start character has been received.
When it is the end character, set a flag (ended = true;) indicating that the end of the packet has been received, and break out of the while loop.
Otherwise, add the character to the array and increment the index, if started and not ended.
After the while loop, add a block to be executed if started and ended. In that block, you'll parse the array (which should contain 05150, for instance) and do something with the parsed data.
Search the forum for "started && ended" for an example of some code.