control a servo using nRF24L01 module through flex sensor

hello friends i wanna control a servo motor through flex sensor using nRF24L01 module and two arduino.
i use this transmitter and reciver code it compile correct but motor not working properly so i need help
this is transmitter code

#include <SPI.h>

#include "RF24.h"
#define flex A1
int msg[1];


//SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 10//CE -> 9
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1LL;

  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 

void setup(void){                     
  radio.begin();
  radio.openWritingPipe(pipe); //
}
void loop(void){  
  val = analogRead(flex);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 750, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 

  msg[0] = val;
  radio.write(msg, 1);
}

this is reciver code

// êîä ¹2  (receiver) 
// Arduino NRF24L01+ Servo radio potentiometer  wireless Control

#include <Servo.h> 
#include <SPI.h>

#include "RF24.h"

Servo myservo;  // create servo object to control a servo 


//SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 10//CE -> 9
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1LL; 

int msg[1];
void setup() 
{ 
// Serial.begin(9600);
myservo.attach(3);  // attaches the servo on pin 3 to the servo object 
radio.begin();
radio.openReadingPipe(1,pipe); 
radio.startListening(); 
} 
void loop() 
{ 
  if (radio.available()){
    bool done = false;
    while (!done){
       done = radio.read(msg,1);
      myservo.write (msg[0]);
    }
  }
}

pls help me

Lots of people get caught out by this

radio.write(msg, 1);

It is much better to use

radio.write(msg, sizeof(msg));

The number in radio.write() is the number of bytes and you have defined msg[] as an int which is 2 bytes so it is only sending part of the data.

You need to make the same sort of allowance in the receiving code.

If that does not work then you should start by getting some simple communication established without any flex thing or servo.

I got my nRF24s working with this Tutorial

I suggest you use the TMRh20 version of the RF24 library - it solves some problems from the ManiacBug version

...R

i define msg[1] in transmitting and reciving both of them

i wanna make wireless robotic arm it is necessary to complete this project in 2 days, i also used 433Mhz rf module but it show error for virtual wire and servo header file for same interrupt and multiple function so i use nRf24 module but motor is not working what i do pls help me

maheshjsmr: i define msg[1] in transmitting and reciving both of them

That reply suggests that you did not study what I said carefully. I was not commenting on the length of the array. I was commenting on the length of a single element in the array.

Did you try using sizeof() ?

The fact that you left it to the last minute to seek advice is not a problem for the Forum. An nRF24 will do what you want very well, and very easily if you use it properly.

...R

ok i understand