Can someone help me with this problem? (already solved)




arduino code:
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8

#include <Wire.h>

#define tx 1
#define rx 0
byte kleur;

int TimerIntervalAppinventor = 100; // this value needs to be equal to the value of the timer in Appinventor
byte frequency_R = 0;
byte frequency_G = 0;
byte frequency_B = 0;
byte connectionOK = 0;
byte NrOfCycles;
byte i=0;
byte naakijk = 0;
void setup() {
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);

// Setting frequency-scaling to 20%
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);

pinMode(tx, OUTPUT);
pinMode(rx, INPUT);

Serial.begin(9600);
}

void loop(){

delay(TimerIntervalAppinventor / 2); // timerInterval of Appinventor devided by 2, to be ready to receive all incoming data
NrOfCycles = NrOfCycles + 1; // transmission of data can only execute after 4 receive cycles
//***RECEIVING DATA ***//
// If receiving serial data from HC06
if (Serial.available() > 0)
{
connectionOK = 1; // only start sending data after reception of first data -else uC crashes
i = 0;
while (Serial.available())
{
delay(10);
kleur = Serial.read();
}

}

// Setting red filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
// Reading the output frequency
frequency_R = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor

delay(100);

// Setting Green filtered photodiodes to be read
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency_G = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor

delay(100);

// Setting Blue filtered photodiodes to be read
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
// Reading the output frequency
frequency_B = pulseIn(sensorOut, LOW);
// Printing the value on the serial monitor

delay(100);
// Matching colors based on received number

if (kleur == 32 && (frequency_R >= 29 && frequency_R <= 42)) {
naakijk = 1;

} else if (kleur == 55 && (frequency_R >= 48 && frequency_R <= 64)) {
naakijk = 1;

} else if (kleur == 84 && (frequency_R >= 72 && frequency_R <= 95)) {
naakijk = 1;

} else if (kleur == 23 && (frequency_R >= 15 && frequency_R <= 28)) {
naakijk = 1;

} else {
naakijk = 0;

}
//***TRANSMITTING DATA ****//
if ((NrOfCycles >= 4) && connectionOK) // transmission of data after 4 receive cycles for Appinventor
{ // kijken wat transmitt data is en printen
Serial.println(naakijk); //
NrOfCycles = 0; //
}
}

this is my arduino code and MIT app. The app gets a random number and sends it to the arduino with bluetooth and than de arduino compares the color it got form the app and the color it It reads with a color senor and the color that it sees and if there the same it sends 1 and if not it sends 0 to the app.
Problem: it gets the number but it gets the number on but it only shows up on the app for a while and then the app forgets the number and you can't use the "Nakijk" button because it thinks than that the number is 0.

Already solved