want to make digital pin high only for 2 seconds and then low

my rest of arduino section is working perfecttly. now on recving 1 in 7th place of my string i want my offtone pin high only for 2seconds and then low again. it should remain low untill i get another 1 in 7th string place.

if (inData[7] == '1') //// FOR RIGHT TONE SELECTION
    {
      //digitalWrite(rightnoise, LOW);
      //digitalWrite(leftnoise, LOW);
      //digitalWrite(offnoise, LOW);
      digitalWrite(righttone, LOW);
      digitalWrite(lefttone, LOW);
      digitalWrite(offtone, HIGH);
      delay(2000);
      digitalWrite(offtone, LOW);
    }

to avoid confusion i have posted ony my doubt section code here
and complete program in next

my code is large more than 9500 characters so i attached the .ino file.
with this code i get continous high signal at the offtone pin it doesnot go low at all.once i am able to achieve the offtone pin high only for 2 seconds and then low until next command is recieved
i will do it for right tone pin and left tone pin also. but only when there conditions are satisfied i mean only in if else loop of right tone, left tone and off tone.

full_prog_without_print.ino (11 KB)

Are all of your messages the same length? If not, you may be looking at characters from old messages if you send a long message followed by a short message.

The message:

<xxxxxx1xx>

followed by the message:

<123>

will act like:

<123>xx1xx>

which has a 1 in the 7 position.

m sorry i didnt understand u karma.
i need a syntax for keeping my desired pin high after reception of desired signal only for 2sec n then low it. n then wait for next command

vanashree:
i need a syntax for keeping my desired pin high after reception of desired signal only for 2sec n then low it. n then wait for next command

See the technique for timing in the Blink Without Delay example sketch. The demo several things at a time is an extended example of the technique. Basically, record the value of millis() when the signal is received and keep comparing that value with the subsequent values of millis. When millis() - startMills >= 2000 it is time to make the pin LOW.

...R