robotic hand with arduino nano and nRF24L01

I need help with this code, it's for a robotic hand. I am using 5 flex sensors, 5 servo motors, 2 arduino nano and 2 nRF24L01.

I would appreciate it if you would help me to know what is wrong in the code (transmitter and receiver)

//Receiver Code (Hand) - Mert Arduino and Tech

#include <Servo.h>    //the library which helps us to control the servo motor
#include <SPI.h>      //the communication interface with the modem
#include "RF24.h"     //the library which helps us to control the radio modem

//define the servo name
Servo myServo1;
Servo myServo3;
Servo myServo4;
Servo myServo2;
Servo myServo5;

RF24 radio(9,10);     /*This object represents a modem connected to the Arduino. 
                      Arguments 9 and 10 are a digital pin numbers to which signals 
                      CE and CSN are connected.*/

const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.

int msg[5];

void setup(){

  //define the servo input pins
  myServo1.attach(15); //A1
  myServo2.attach(16); //A2
  myServo3.attach(17); //A3
  myServo4.attach(18); //A4
  myServo5.attach(19); //A5
  
  radio.begin();                    //it activates the modem.
  radio.openReadingPipe(1, pipe);   //determines the address of our modem which receive data.
  radio.startListening();           //enable receiving data via modem
  }


void loop(){
  if(radio.available()){
    bool done = false;
    while (!done){
    done = radio.read(msg, sizeof(msg));

    myServo1.write(msg[2]); //A1
    myServo2.write(msg[4]); //A2
    myServo3.write(msg[3]); //A3
    myServo4.write(msg[1]); //A4
    myServo5.write(msg[0]); //A5
    }
  }
}
//Transmitter Code (Glove) - Mert Arduino and Tech

#include <SPI.h>                      //the communication interface with the modem
#include "RF24.h"                     //the library which helps us to control the radio modem

int msg[5]; //Total number of data to be sent (data package)

//define the flex sensor input pins
int flex_5 = A5;
int flex_4 = A4;
int flex_3 = A3;
int flex_2 = A2;
int flex_1 = A1;

//define variables for flex sensor values
int flex_5_val;
int flex_4_val;
int flex_3_val;
int flex_2_val;
int flex_1_val;

RF24 radio(9,10);                     //9 and 10 are a digital pin numbers to which signals CE and CSN are connected.
                                      
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.


void setup(void){
  Serial.begin(9600);
  radio.begin();                      //it activates the modem.
  radio.openWritingPipe(pipe);        //sets the address of the receiver to which the program will send data.
}

void loop(void){

  flex_5_val = analogRead(flex_5); 
  flex_5_val = map(flex_5_val, 630, 730, 80, 20);
  
  flex_4_val = analogRead(flex_4);
  flex_4_val = map(flex_4_val, 520, 710, 70, 175);
 
  flex_3_val = analogRead(flex_3);
  flex_3_val = map(flex_3_val, 510, 680, 140, 10);
 
  flex_2_val = analogRead(flex_2);
  flex_2_val = map(flex_2_val, 580, 715, 90, 175);
  
  flex_1_val = analogRead(flex_1);
  flex_1_val = map(flex_1_val, 550, 700, 90, 175);
  
  msg[0] = flex_5_val;
  msg[1] = flex_4_val;
  msg[2] = flex_3_val;
  msg[3] = flex_2_val;
  msg[4] = flex_1_val;
  radio.write(msg, sizeof(msg));
}

Thanks!

Alexxx17:
I would appreciate it if you would help me to know what is in the code (transmitter and receiver)

Basically a variant of an outdated joystick example that is using a NRF24L01+ library that has known shortcomings.

I would suggest:

  • move to a better library (some small changes to the code will be necessary)
  • remove all comments that document what obviously happens and only leave those that give some insight in a not obvious thing
  • don't call the NRF24L01+ a 'modem' (or would you call an ethernet chip also a modem?)
  • try to ask less fuzzy questions if you want specific information

I just do not know what's wrong with the code, and it does not get the signal :confused:

If your setup is not working, there are a lot more possible reasons than problematic code.

There are a ton of different NRF24L01+ modules and many ways to power them,
some configurations need at least a capacitor directly on the module to function,
some need a separate power supply. There are damaged chips, even DOAs.
Some configurations don't work well when close, some if the distance is large.

Servo motors draw a lot of power and influence other parts of the system.

Your code is misusing* a library I don't trust, but should basically 'work'.
(* it is flooding its channel with packets spaced only by five analogReads)
Maybe the receiver can keep up (I don't know how long servo.write() takes),
but calling servo.write() at that pace seems a bad idea to me.

I am using 5 flex sensors, 5 servo motors, 2 arduino nano and 2 nRF24L01
it does not get the signal

If you did everything that you don't show (power, cabling, setup, ...) right, it should work.
You shurely already checked the functionality of the modules by running the example sketches provided with the library.

Robin2 has a famous tutorial to NRF24L01+ communication,
you could try that, at least to verify the operation of the NRFs.
His sketches also use the already mentioned better library.