Arduino Arduino i2c problem

. I connect two uno arduino using I2C protocol I use line follower equation code but my master arduino received wrong numbers from the slave arduino For example slave code

 #include <Wire.h>

   const int r0 = 2;// RIGHT COLOR SENSOR
   const int r1 = 3;
   const int r2 = 4;
   const int r3 = 5;
   const int Rout = 6;
   const int l0 = A0;//LEFT COLOR SENSOR
   const int l1 = A1;
   const int l2 = A2;
   const int l3 = A3;
   const int Lout = 13;

int redR = 0;
int greenR = 0;
int blueR = 0;
int redL = 0;
int greenL = 0;
int blueL = 0;

int eq;//IR
int eq2;//COLOR
int IR1, IR2, IR3, IR4, IR5, IR6, LCOLOR, RCOLOR;

void setup() {
 Wire.begin(8);
 Wire.onRequest(requestEvent);
 Serial.begin(9600);

 pinMode(r0, OUTPUT);
 pinMode(r1, OUTPUT);
 pinMode(r2, OUTPUT);
 pinMode(r3, OUTPUT);
 pinMode(Rout, INPUT);
 pinMode(l0, OUTPUT);
 pinMode(l1, OUTPUT);
 pinMode(l2, OUTPUT);
 pinMode(l3, OUTPUT);
 pinMode(Lout, INPUT);

 digitalWrite(r0, HIGH);
 digitalWrite(r1, HIGH);
 digitalWrite(l0, HIGH);
 digitalWrite(l1, HIGH);


}

void loop() {

}
void requestEvent() {
 IR1 = digitalRead(7);
 IR2 = digitalRead(8);
 IR3 = digitalRead(9);
 IR4 = digitalRead(10);
 IR5 = digitalRead(11);
 LCOLOR=leftcolor();
   RCOLOR=rightcolor();



 Serial.print(IR1);
 Serial.print(IR2);
 Serial.print(IR3);
 Serial.print(IR4);
 Serial.print(IR5);

 Serial.print(LCOLOR);
 Serial.print(RCOLOR);
 Serial.println();




 eq =   (IR5 * 1) + (IR4 * 2) + (IR3 * 4) + (IR2 * 8) + (IR1 *  16);
 eq2 = (LCOLOR * 2) + (RCOLOR * 1);

 Wire.write(eq);
 Wire.write(eq2);


}
long rightcolor() {
 digitalWrite(r2, LOW);
 digitalWrite(r3, LOW);

 //count OUT, pRed, RED
 redR = pulseIn(Rout, digitalRead(Rout) == HIGH ? LOW : HIGH);
 digitalWrite(r3, HIGH);
 //count OUT, pBLUE, BLUE
 blueR = pulseIn(Rout, digitalRead(Rout) == HIGH ? LOW : HIGH);
 digitalWrite(r2, HIGH);
 //count OUT, pGreen, GREEN
 greenR = pulseIn(Rout, digitalRead(Rout) == HIGH ? LOW : HIGH);
 Serial.print("R Intensity:");
 Serial.print(redR, DEC);
 Serial.print(" G Intensity: ");
 Serial.print(greenR, DEC);
 Serial.print(" B Intensity : ");
 Serial.print(blueR, DEC);
 //Serial.println();

 if (redR <= greenR && blueR <= greenR && greenR < 7)
 {
   Serial.println(" - (wight)");
   long    RCOLOR = 0;
   return RCOLOR;


 }

 else if (blueR <= redR && blueR <= greenR && blueR < 10  )
 {
   Serial.println(" - (silver)");
   Wire.write("s");


 }

 else if (greenR < redR && greenR < blueR)
 {
   Serial.println(" - (Green Color)");
   long    RCOLOR = 1;
   return RCOLOR;


 }
 else {
 long    RCOLOR = 0;
   return RCOLOR;
 }

}
long leftcolor() {
 digitalWrite(l2, LOW);
 digitalWrite(l3, LOW);
 //count OUT, pRed, RED
 redL = pulseIn(Lout, digitalRead(Lout) == HIGH ? LOW : HIGH);
 digitalWrite(l3, HIGH);
 //count OUT, pBLUE, BLUE
 blueL = pulseIn(Lout, digitalRead(Lout) == HIGH ? LOW : HIGH);
 digitalWrite(l2, HIGH);
 //count OUT, pGreen, GREEN
 greenL = pulseIn(Lout, digitalRead(Lout) == HIGH ? LOW : HIGH);
 Serial.print("R Intensity:");
 Serial.print(redL, DEC);
 Serial.print(" G Intensity: ");
 Serial.print(greenL, DEC);
 Serial.print(" B Intensity : ");
 Serial.print(blueL, DEC);
 //Serial.println();

 if (redL <= greenL && blueL <= greenL && greenL < 7)
 {
   Serial.println(" - (wight2)");
   long LCOLOR = 0;
   return LCOLOR;


 }

 else if (blueL <= redL && blueL <= greenL && blueL < 10  )
 {
   Serial.println(" - (silver2)");
   Wire.write("s");
 }

 else if (greenL < redL && greenL < blueL)
 {
   Serial.println(" - (Green2)");
   long LCOLOR = 1;
   return LCOLOR;
 }
 else{
   long LCOLOR = 0;
   return LCOLOR;

 }

}

And the master code

 #include <Wire.h>
int t1 = 2; // motor 1 transistor signal
int t2 = 3; // motor 2 transistor signal
int r1 = 4; //motor 1
int r2 = 5; //motor 2
int eq ; // line tracking
int eq2;  // color sensor
int IR1, IR2, IR3, IR4, IR5, IR6, LCOLOR, RCOLOR;

int trig = 8;
int echo = 10;
long TIME, distance;
void setup() {
 Wire.begin();
 Serial.begin(9600);
}

void loop() {
 Wire.requestFrom(8, 2);
 unsigned int eq = Wire.read();
 unsigned int eq2 = Wire.read();
Serial.print("eq1=");
 Serial.print(eq);
  Serial.print("eq2=");
 Serial.print(eq2);


 distance = ultrasonic();
 if (distance <= 5) {
   avoid();
 }


 else {

   linetracking(eq);
 }


}
void FORWARD(int x) {

 analogWrite(t2, x);
 analogWrite(t1, x);
 digitalWrite(r2, HIGH);
 digitalWrite(r1, HIGH);
}
void BACK(int x) {

 digitalWrite(t2, x);
 digitalWrite(t1, x);
 digitalWrite(r2, LOW);
 digitalWrite(r1, LOW);

}
void RIGHT(int x) {

 analogWrite(t2, 0);
 analogWrite(t1, x);
 digitalWrite(r2, LOW);
 digitalWrite(r1, HIGH);
}
void LEFT(int x) {

 analogWrite(t2, x);
 analogWrite(t1, 0);
 digitalWrite(r2, HIGH);
 digitalWrite(r1, LOW);
}
void STOP() {

 analogWrite(t2, 0);
 analogWrite(t1, 0);
 digitalWrite(r2, LOW);
 digitalWrite(r1, LOW);
}
void RIGHTB  (int x) {

 analogWrite(t2, x);
 analogWrite(t1, x);
 digitalWrite(r2, LOW);
 digitalWrite(r1, HIGH);

}
void LEFTB(int x) {

 analogWrite(t2, x);
 analogWrite(t1, x);
 digitalWrite(r2, HIGH);
 digitalWrite(r1, LOW);
}
void TURNGO(int x) {

}
int  ultrasonic() {
 digitalWrite(trig, LOW);
 delayMicroseconds(2);
 digitalWrite(trig, HIGH);
 delayMicroseconds(10);
 digitalWrite(trig, LOW);
 TIME = pulseIn(echo, HIGH);
 distance = TIME / 2 / 29.1;
 Serial.println(distance);
 return distance;
}
void avoid() {
 BACK(95);
 delay(500);
 LEFTB(170);
 delay(400);
 FORWARD(95);
 delay(1157);
 RIGHTB(177);
 delay(530);
 FORWARD(75);
}
void linetracking(int eq) {
 switch (eq) {
   case 0: STOP();
     break;
   case 1: break;
   case 2: break;
   case 3: break;
   case 4: break;
   case 5: break;
   case 6:
     FORWARD (200);
     break;
   case 7: break;
   case 8: break;
   case 9: break;
   case 10: break;
   case 11: break;
   case 12: break;
   case 13: break;
   case 14: break;
   case 15: break;
   case 16: break;
   case 17: break;
   case 18: break;
   case 19: break;
   case 20: break;
   case 21: break;
   case 22: break;
   case 23: break;
   case 24:
     LEFT (200);
     break;
   case 25: break;
   case 26: break;
   case 27: break;
   case 28:
     LEFT (200);
     break;
   case 29: break;
   case 30:
     LEFT (200);
     break;
   case 31: break;
   case 32: break;
   case 33:
     RIGHT (200);
     break;
   case 34: break;
   case 35:
     RIGHT (200);
     break;
   case 36: break;
   case 37: break;
   case 38: break;
   case 39:
     RIGHT (200);
     break;
   case 40: break;
   case 41: break;
   case 42: break;
   case 43: break;
   case 44: break;
   case 45: break;
   case 46: break;
   case 47: break;
   case 48: break;
   case 49: break;
   case 50: break;
   case 51: break;
   case 52: break;
   case 53: break;
   case 54: break;
   case 55: break;
   case 56: break;
   case 57: break;
   case 58: break;
   case 59: break;
   case 60: break;
   case 61: break;
   case 62: break;
   case 63:
     color(eq2);
     break;



   default:
     STOP ();
     break;
 }
}
void color(int eq2) {
 switch (eq2) {
   case 0: //00
     FORWARD(200);
     break;

   case 1:  //01
     RIGHT(200);
     break;

   case 2:  //10
     LEFT(200);
     break;
   case 3:  //11
     TURNGO(200);
     break;



 }
}

THE MASTER ARDUINO RECEIVED THE CODE LIKE THIS eq= o And eq2= 255 And I do not know why?? Could you please help me.

Please edit your post and add code tags! You can see how the forum system changes your code without these tags.

You have Serial.print() calls in the interrupt service routine. Inside an ISR interrupts are disabled but the serial interface depends on interrupts to empty the queue. If ever possible you should do the relevant stuff in the loop and only send the data in the requestEvent method.

Thanks for helping me sir
I couldn't catch what I should do
Can you explain your answer with simple example
Thanks in advance

Can you explain your answer with simple example

Here's a copy of part of your code:

void requestEvent() {
 IR1 = digitalRead(7);
 IR2 = digitalRead(8);
 IR3 = digitalRead(9);
 IR4 = digitalRead(10);
 IR5 = digitalRead(11);
 LCOLOR=leftcolor();
   RCOLOR=rightcolor();



 Serial.print(IR1);
 Serial.print(IR2);
 Serial.print(IR3);
 Serial.print(IR4);
 Serial.print(IR5);

 Serial.print(LCOLOR);
 Serial.print(RCOLOR);
 Serial.println();




 eq =   (IR5 * 1) + (IR4 * 2) + (IR3 * 4) + (IR2 * 8) + (IR1 *  16);
 eq2 = (LCOLOR * 2) + (RCOLOR * 1);

 Wire.write(eq);
 Wire.write(eq2);

...

As you can see you use "Serial.print()" and "Serial.println()" inside the requestEvent() routine. But requestEvent is called inside an ISR (Interrupt Service Routine). During an ISR all interrupts are disabled. A call to Serial.print() writes the bytes to a buffer. Usually an interrupt empties that buffer one byte after the other but here this isn't possible as interrupts are disabled. As soon as the buffer is full the code behind Serial.print() waits until some bytes are processed by the interrupt. As this never happens (remember: interrupts are disabled) the code is in a dead lock.

So remove all calls of Serial.print() and Serial.println() inside the requestEvent() routine and from every routine called by that routine.

Also check the return value of Wire.requestFrom() to identify failures in the I2C communication. If I'm right you'll see that the transfer fails in many situations.

The behaviour of Wire.write() is asymmetric; its behaviour depends on whether you're a master or slave.

Calling write() from the master fills a 32-byte buffer which is transmitted when endTransmission() is called.

Calling write() from the slave sends the data immediately.
If you call write(uint8_t), you send one byte (extra bytes requested by the server are garbage).

To send multiple bytes from the slave, you have to fill your own buffer and send it all at once.

Your ISR is also calling leftcolor() and rightcolor(). There are serial prints, calls to pulseIn, and additional wire.write statements inside those functions. I would recraft the program to keep the ISR short and address those two functions outside of the ISR.