char solution[] = {'a', 'b', 'b', 'a'}; int count = 0; int solutionLength = 4; void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: if (Serial.available() > 0) { char Data = Serial.read(); if (Data == solution[count]) { // digitalWrite(outpin1,HIGH); if (count == solutionLength - 1) { Serial.print('y'); count = 0; } else { Serial.print('p'); count++; } } else { Serial.print('n'); count = 0; } // Serial.read(); } delay(1000); // digitalWrite(outpin1,LOW); // digitalWrite(outpin2,LOW); }