Wireless control 1 servo and 1 DC-motor with 2 potentiometers using nrf24

I got stuck trying to wirelessly control 1 servo (eventually 2 servos) and 1 DC-motor.

I got 2 servos wireless control working and 1 DC-motor wireless control. But when I try to combine the two it doesn't work. Any tips?

Not working transmitter code 1 servo, 1 DC-motor:

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

int motor_Pin = A2;              // connects to analoge pin A2, dc-motor
int msg_Pin = A0;                    // connects to analoge pin A0

int msg[2];                           // creates an array of 2, holding data of both potmeters


RF24 radio(5,10);                     //5 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){
  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){
  // writes data in the array &maps input over 180 degrees

  
  msg[0] =  map (analogRead(motor_Pin), 0, 1023, 0, 255); 
  msg[1] =  map (analogRead(msg_Pin), 0, 1023, 0, 180); 

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

Not working receiver code 1 servo, 1 DC-motor:

#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


int motorPin = 9;          //define motorname
Servo myServo;        //define the servo name

RF24 radio(5, 10);     /*This object represents a modem connected to the Arduino.
                      Arguments 5 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[2];



void setup() {

  myServo.attach(3);                //3 is a digital pin to which servo signal connected
  pinMode(motorPin, OUTPUT);

  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()){            //checks whether any data have arrived at the address of the modem
      radio.read(&msg, sizeof(msg));
      analogWrite(motorPin, msg[0]);
      myServo.write(msg[1]);
    }
  }
//}

(Working) transmitter code 2 servos:

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

int msg_Pin = A0;                    // connects to analoge pin A1
int msgTwo_Pin = A1;;                // connects to analoge pin A1

int msg[2];                           // creates an array of 2, holding data of both potmeters


RF24 radio(5,10);                     //5 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){
  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){
  // writes data in the array &maps input over 180 degrees
  msg[0] =  map (analogRead(msg_Pin), 0, 1023, 0, 180); 
  msg[1] =  map (analogRead(msgTwo_Pin), 0, 1023, 0, 180); 

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

(Working) receiver code 2 servos:

#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

Servo myServo;        //define the servo name
Servo myServoTwo;     //define the servo name

RF24 radio(5, 10);     /*This object represents a modem connected to the Arduino.
                      Arguments 5 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[2];



void setup() {
  myServo.attach(3);                //3 is a digital pin to which servo signal connected
  myServoTwo.attach(6);             //6 is a digital pin to which servo signal connected

  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()){            //checks whether any data have arrived at the address of the modem
      radio.read(&msg, sizeof(msg));
      myServo.write(msg[1]);
    myServoTwo.write(msg[0]);
    }
  }
//}

(Working) transmitter code 1 DC-motor:

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

int msgThree_Pin = A2;              // connects to analoge pin A2, dc-motor

int msg[1];                           // creates an array of 1, holding data of more potmeters, when larger


RF24 radio(5,10);                     //5 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){
  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){
  
  msg[0] =  map (analogRead(msgThree_Pin), 0, 1023, 0, 255); 

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

(Working) receiver code 1 DC-motor:

#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


int motorPin = 9;          //define motorname

RF24 radio(5, 10);     /*This object represents a modem connected to the Arduino.
                      Arguments 5 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[1];



void setup() {

  pinMode(motorPin, OUTPUT);

  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()){            //checks whether any data have arrived at the address of the modem
      radio.read(&msg, sizeof(msg));
      analogWrite(motorPin, msg[0]);
    }
  }
//}

"Not working" is the most useless thing you can say here. The code IS working. It is doing EXACTLY what you told it to do. If what it actually does is not what you expect, it is your expectations that are wrong.

Now, what, EXACTLY, does the code do? How does that differ from what you expect?

int msg[2];

  msg[0] =  map (analogRead(motor_Pin), 0, 1023, 0, 255);
  msg[1] =  map (analogRead(msg_Pin), 0, 1023, 0, 180);

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

Why do you need an int array to hold two values in the range 0 to 155?

Thanks for your reply, I mean with not working that the servos chitter around and the speed control of the dc-motor doesn't do anything. I am trying to build a wireless controlled plane kind of thing. Therefor I need 2 servos, 1 for left/right, 1 for up/down and 1 dc-motor for propulsion. On the transmitter side I have 3 potentiometers, with the servos it controls the direction and with the DC-motor it controls the speed.

I packed the messages in an array to solve a previous issue wherein if I tried to move one servo the other one would chitter around as well. The two messages seemed to interfere with each other. This is now resolved and the servos run smoothly without any interference.

I packed the messages in an array

A good idea, no doubt. But, the array is a moving van, when an egg-crate would have worked, faster, better, cheaper.

Have a look at this Simple nRF24L01+ Tutorial.

...R

I found the solution. I changed the pin of the DC-motor from pin 9 to pin 3 and now it works.

"UNO uses Timer1 with Servo library. Also Timer1 is needed to do PWM in pins 9 and 10. Then, if you use servos, you can not use PWM with pins 9 and 10."