Random values sent to receiver side between correct ones

hello , im using two arduino unos and two Rf24 modules to control 2 servos and one brushless motor , i have displayed values on serial monitor from transmitting arduino and they are perfect but when i display them from receiver arduino there are random small values appearing between correct values which ruins all the work
transmitter code

/*
* Arduino Wireless Communication Tutorial
*     Example 2 - Transmitter Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
int value = 0; // set values you need to zero
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define led 12
RF24 radio(7, 8); // CNS, CE
const byte addresses[][6] = {"00001", "00002"};
boolean buttonState = 0;
    #define MAX_SIGNAL 2100
    #define MIN_SIGNAL 700
void setup() {
  pinMode(12, OUTPUT);
  radio.begin();
  radio.openWritingPipe(addresses[1]); // 00001
  radio.openReadingPipe(1, addresses[0]); // 00002
  radio.setPALevel(RF24_PA_MIN);
  Serial.begin(115200); 
}
void loop() {
  delay(5);
  radio.stopListening();
  int potValue = analogRead(A0);
  int angleValue = map(potValue, 0, 1023, 0, 180);
  radio.write(&angleValue, sizeof(angleValue));
      int potValue1 = analogRead(A1);
      int angleValue1 = map(potValue1, 0, 1023, 0, 180);
      radio.write(&angleValue1, sizeof(angleValue1));
          int potValue2 = analogRead(A2);
          int angleValue2 = map(potValue2, 0, 1023, MIN_SIGNAL, MAX_SIGNAL);
          radio.write(&angleValue2, sizeof(angleValue2));
           if(Serial.available()) 
           value = Serial.parseInt();    // Parse an Integer from Serial
           Serial.println(angleValue);
}

Receiver code

/*
* Arduino Wireless Communication Tutorial
*     Example 2 - Receiver Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
int value = 0; // set values you need to zero
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define button 4
RF24 radio(7, 8); // CNS, CE
const byte addresses[][6] = {"00001", "00002"};
Servo myServo;
Servo myServo1;
Servo firstESC;
boolean buttonState = 0;
void setup() {
  pinMode(button, INPUT);
  myServo.attach(5);
  myServo1.attach(6);
  firstESC.attach(9);
  radio.begin();
  radio.openWritingPipe(addresses[0]); // 00002
  radio.openReadingPipe(1, addresses[1]); // 00001
  radio.setPALevel(RF24_PA_MIN);
  Serial.begin(115200);
}
void loop() {
  delay(5);
  radio.startListening();
  if ( radio.available()) {
    while (radio.available()) {
      int angleV = 0;
      int angleVTRUE = 0;
      radio.read(&angleV, sizeof(angleV));
      if (angleV < 180 )
             {
             angleVTRUE = angleV;
             }
      myServo.write(angleVTRUE);
         int angleV1 = 0;
         int angleV1TRUE = 0;
         radio.read(&angleV1, sizeof(angleV1));
         if (angleV1 < 180 )
              {
              angleV1TRUE = angleV1;
              }
         myServo1.write(angleV1TRUE);
             int angleV2 = 0;
             int angleV2TRUE = 0;
             radio.read(&angleV2, sizeof(angleV2));
             bitSet(angleV2, 0);
             if (angleV2 < 2100 &&   angleV2 > 700)
             {
             angleV2TRUE = angleV2;
             }
              angleV2TRUE = constrain(angleV2TRUE,700,2100);
                   
             firstESC.writeMicroseconds(angleV2TRUE);
               if(Serial.available()) 
               value = Serial.parseInt(); 
               Serial.println(angleVTRUE);
    }
  }
}

PS: even after constrain() 0 values become 700 which is also not good
try displaying angleVTRUE and angleV1TRUE same problem
any help will be very appreciated and thank you in advance

Have a look at this Simple nRF24L01+ Tutorial - the examples do work.

It is pretty much essential to get the wireless communication working properly before you ad any other functionality because wireless problems can be hard to debug.

...R

thanks for the reply . The communication is working properly , tried sending strings and they arrived just as they should, i will also mention that ,if that helps, the number of values received is more than number of values transmitted which means if number 50 is sent 4 times i will get on the receiver side 5 or 6 values ( 4 times number 50 but with one or two random numbers between them). is there any way to ignore those values ?
for the brushless motor my range is (700 - 2100) so i would be pleased to know a way to ignore values under 700 and i tried it with this

if (angleV2 < 2100 &&   angleV2 > 700)
             {
             angleV2TRUE = angleV2;
             }

it did great with all values except values like (0-1-2) persisted and appeared on angleV2TRUE

mohamedalichelbi:
The communication is working properly , tried sending strings and they arrived just as they should, i will also mention that ,if that helps, the number of values received is more than number of values transmitted

I cannot reconcile the two comments I have highlighted.

The nRF24 is very reliable and has a lot of internal error checking.

Take all the servo etc code out of your program and just have the transmitter send an int to the receiver. Get that working before you include any other code.

It will be much easier to help if you use one of the examples from my tutorial as I am very familiar with them.

...R

im really thankful for response , i kept same wiring and your sketches are working perfectly :slight_smile: i tried my sketch with one variable and it was perfect no problems,i think i have to send my 3 variables in one packet. do you know a way to do it ?

mohamedalichelbi:
i have to send my 3 variables in one packet. do you know a way to do it ?

Post the program in which you have tried it and I will see if I can help.

Some of my examples send 2 values and can easily be extended to 3.

...R

i have to send my 3 variables in one packet. do you know a way to do it ?

Put the three values in an array. Send the array.