PROBLEM FACING CONNECTING TWO ARDUINO UNO USING NRF24L01

CONTROLLING LED AND SERVO MOTOR WIRE LESSLEY TWO ARDUINO UNO WITH FUNDUINO JOY STICK SHIELD USING NRF24L01.

PROBLEM FACING IS THAT LED WORKIN SATISFACTORY AS PER PROGRAMMER BUT SERVO MOTOR NOT WORKING, THAT MEANS WHEN I PRESS PUSH BUTTON OF LED SERVO ALSO VIBERATING.MY PROGRAME MENTIONED BELOW.

RECIEVER

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
Servo myServo;
int msg[1];
int angleValue ;

RF24 radio(9,10);//check your pin number on RF24 github check you have the right
//pin number for the arduino you're using. this pin is diffrent for diffrent arduino models.

const uint64_t pipe = 0xF0F0F0F0D2L;
int led1 = 2;
int led2 = A2;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;

void setup(void)
{
myServo.attach(3);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();

pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
}

void loop(void)
{

if(radio.available()){
bool done = false;
while (!done) {
done = radio.read(msg, 1);
Serial.println(msg[0]);

if (msg[0] == 111) {

digitalWrite(led1, HIGH);
digitalWrite(led7, LOW);
}if(msg[0] == 222){
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led7, LOW);
}
else if (msg[0] == 111){
digitalWrite(led2, LOW);}

else if(msg[0] == 212){

digitalWrite(led3, HIGH);
}else if(msg[0] == 216){

digitalWrite(led4, HIGH);
}else if(msg[0] == 218){

digitalWrite(led5, HIGH);
}else if(msg[0] == 220){

digitalWrite(led6, HIGH);
}else if(msg[0] == 224){

digitalWrite(led7, HIGH);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
delay(10);
} }}
if(radio.available()){
bool done = false;
while (!done) {
done = radio.read(&angleValue,sizeof (angleValue) );
myServo.write(angleValue);}
delay(10);}
else {

digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);

}
}

TRANSMITTER

#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>

int msg[1];
#define xAxis A0 // A0 for Arduino UNO
RF24 radio(9,10);//check your pin number on RF24 github check you have the right
//pin for the arduino you're using. this pin number is diffrent for diffrent arduino models.

const uint64_t pipe = 0xF0F0F0F0D2L;
int joystick[6];
int buttonPin1 = 2;
int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin4 = 5;
int buttonPin5 = 6;
int buttonPin6 = 7;
int buttonPin7 = 8;
int buttonState1 = 1;
int buttonState2 = 1;
int buttonState3 = 1;
int buttonState4 = 1;
int buttonState5 = 1;
int buttonState6 = 1;
int buttonState7 = 1;
int val[1];

void setup(void)
{

Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
pinMode(buttonPin6, INPUT);
pinMode(buttonPin7, INPUT);
}

void loop(void)
{
int potValue= analogRead(A0);
int angleValue = map(potValue, 0, 1023, 0, 180);
radio.write(&angleValue, sizeof(angleValue));

buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
buttonState6 = digitalRead(buttonPin6);
buttonState7 = digitalRead(buttonPin7);

if (buttonState1 == HIGH)
{
msg[0] = 111;
radio.write(msg, 1);
}
if (buttonState2 == HIGH)
{
msg[0] = 222;

radio.write(msg, 1);

}
if (buttonState3 == HIGH)
{
msg[0] = 212;
radio.write(msg, 1);
}
if (buttonState4 == HIGH)
{
msg[0] = 216;
radio.write(msg, 1);
}
if (buttonState5 == HIGH)
{
msg[0] = 218;
radio.write(msg, 1);
}
if (buttonState6 == HIGH)
{
msg[0] = 220;
radio.write(msg, 1);}
if (buttonState7 == HIGH)
{
msg[0] = 224;
radio.write(msg, 1);
}

}

WITH OUT SERVO MOTOR CODE LED WORKING SATISFACTORY...PLEASE HELP ME ON THIS MATTER

Please don't SHOUT.

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

Also use the AutoFormat tool to indent your code for easier reading,

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

...R

THANK YOU FOR YOUR FAVORABLE REPLY.
I am a beginner in Arduino programming so that program is also little bit lengthy sorry for inconvenience.
I have make a program for wire less controlling of a servo motor and LED(7 Nos.) using ARDUINO UNO, Funduino Joy stick shield V1.A and NRF24L01.First i have prepare the program only for controlling the LEDs and its become success as that LEDs working as per program.Than i added Servo motor also in circuit and make some changes in existing LED program. Unfortunately the result is erratic out put.joy stick input signal interrupting the led signal and some time servo motor respond led input .code given below is led and servo motor.

RECIEVER

```
**[/b]#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h> 
#include <Servo.h>

Servo myServo;
RF24 radio(9,10);
const uint64_t pipe = 0xF0F0F0F0D2L;

int led1 = 2;
int led2 = A2;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int msg[1];
int angleValue ;

void setup(void)
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  myServo.attach(3);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
}
void loop(void)
{
 
  if(radio.available()){
    bool done = false;
    while (!done) {
    done = radio.read(msg, 1);
    Serial.println(msg[0]);

if (msg[0] == 111) {
      digitalWrite(led1, HIGH);
      digitalWrite(led7, LOW);
      }
    if(msg[0] == 222){
        digitalWrite(led1, LOW);
        digitalWrite(led2, HIGH);
        digitalWrite(led7, LOW);
        }
    else if (msg[0] == 111){
          digitalWrite(led2, LOW);
        }
    else if(msg[0] == 212){
       
          digitalWrite(led3, HIGH);
        }
    else if(msg[0] == 216){
          digitalWrite(led4, HIGH);
        }
    else if(msg[0] == 218){
          digitalWrite(led5, HIGH);
        }
    else if(msg[0] == 220){
          digitalWrite(led6, HIGH);
        }
    else if(msg[0] == 224){
          digitalWrite(led7, HIGH);
          digitalWrite(led1, LOW);
          digitalWrite(led2, LOW);
        delay(10);
        }
      }
  }
    if(radio.available()){         
      bool done = false;           
      while (!done) {
      done = radio.read(&angleValue,sizeof (angleValue) );
      myServo.write(angleValue);}
      delay(10);
    }
      else { 
      digitalWrite(led3, LOW);
      digitalWrite(led4, LOW);
      digitalWrite(led5, LOW);
      digitalWrite(led6, LOW);
     
      }
}
[b]**
```

TRANSMITTER

```
**[/b]
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>

#define xAxis A0 
RF24 radio(9,10);
const uint64_t pipe = 0xF0F0F0F0D2L;

int msg[1];
int buttonPin1 = 2;
int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin4 = 5;
int buttonPin5 = 6;
int buttonPin6 = 7;
int buttonPin7 = 8;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
int buttonState7 = 0;

void setup(void)
{
  radio.begin();
  radio.openWritingPipe(pipe);
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin3, INPUT_PULLUP);
  pinMode(buttonPin4, INPUT_PULLUP);
  pinMode(buttonPin5, INPUT_PULLUP);
  pinMode(buttonPin6, INPUT_PULLUP);
  pinMode(buttonPin7, INPUT_PULLUP);
}

void loop(void)
{
  int potValue = analogRead(A0);
  int angleValue = map(potValue, 0, 1023, 0, 180);
  radio.write(&angleValue, sizeof(angleValue));
 
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  buttonState5 = digitalRead(buttonPin5);
  buttonState6 = digitalRead(buttonPin6);
  buttonState7 = digitalRead(buttonPin7);

if (buttonState1 == HIGH){
    msg[0] = 111;
    radio.write(msg, 1);
  }
if (buttonState2 == HIGH){
    msg[0] = 222;
    radio.write(msg, 1);
  }
if (buttonState3 == HIGH){
    msg[0] = 212;
    radio.write(msg, 1);
  } 
if (buttonState4 == HIGH){
    msg[0] = 216;
    radio.write(msg, 1);
  }
if (buttonState5 == HIGH){
    msg[0] = 218;
    radio.write(msg, 1);
  }
if (buttonState6 == HIGH){
    msg[0] = 220;
    radio.write(msg, 1);
  }
    if (buttonState7 == HIGH){
    msg[0] = 224;
    radio.write(msg, 1);
  }

}

[b]**
```

Note:-wire less module checked working properly.

The receiving code doesn’t know if the message is for the LED’s or the servo. You need to add a header byte or some other means of identifying what is contained in the message.

You have 32 bytes in every message to use, you should transmit both pieces of data in the same message using a “struct” to hold the variables.

[/b]
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>



#define xAxis A0   
RF24 radio(9,10);
const uint64_t pipe = 0xF0F0F0F0D2L;

int msg[1];
int buttonPin1 = 2;
int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin4 = 5;
int buttonPin5 = 6;
int buttonPin6 = 7;
int buttonPin7 = 8;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
int buttonState7 = 0;


void setup(void)
{
  radio.begin();
  radio.openWritingPipe(pipe);
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin3, INPUT_PULLUP);
  pinMode(buttonPin4, INPUT_PULLUP);
  pinMode(buttonPin5, INPUT_PULLUP);
  pinMode(buttonPin6, INPUT_PULLUP);
  pinMode(buttonPin7, INPUT_PULLUP);
}

void loop(void)
{
  int potValue = analogRead(A0);                              //  INPUT FOR SERVO MOTOR
  int angleValue = map(potValue, 0, 1023, 0, 180); // INPUT FOR SERVO MOTOR
  radio.write(&angleValue, sizeof(angleValue));         // INPUT FOR SERVO MOTOR
  
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  buttonState5 = digitalRead(buttonPin5);
  buttonState6 = digitalRead(buttonPin6);
  buttonState7 = digitalRead(buttonPin7);
 

 if (buttonState1 == LOW){
    msg[0] = 111;
    radio.write(msg, 1);               // INPUT FOR LED1
   }
 if (buttonState2 == LOW){ 
    msg[0] = 222;
    radio.write(msg, 1);               // INPUT FOR LED2
   }
 if (buttonState3 == LOW){
    msg[0] = 212;
    radio.write(msg, 1);               // INPUT FOR LED3
   }  
 if (buttonState4 == LOW){
    msg[0] = 216;
    radio.write(msg, 1);                 // INPUT FOR LED4
   }
 if (buttonState5 == LOW){
    msg[0] = 218;
    radio.write(msg, 1);                // INPUT FOR LED5
   }
 if (buttonState6 == LOW){
    msg[0] = 220;
    radio.write(msg, 1);                 // INPUT FOR LED6
   }
    if (buttonState7 == LOW){
    msg[0] = 224;
    radio.write(msg, 1);
   }                                              // INPUT FOR LED7
 
  }

[b]

RECEIVER CODE

[/b]#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>  
#include <Servo.h>  // SERVO LIBRARY INCLUDED

Servo myServo; 
RF24 radio(9,10);
const uint64_t pipe = 0xF0F0F0F0D2L;

int led1 = 2;
int led2 = A2;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int msg[1];
int angleValue ;

void setup(void)
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  myServo.attach(3);                  // SERVO CONNECTED TO PIN 3
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
}
void loop(void)
{
   // Receiving code for LED 1 TO LED 7

  if(radio.available()){
    bool done = false;
    while (!done) {
    done = radio.read(msg, 1);
    Serial.println(msg[0]);

    if (msg[0] == 111) {
      digitalWrite(led1, HIGH);
      digitalWrite(led7, LOW);
      }
    if(msg[0] == 222){
        digitalWrite(led1, LOW);
        digitalWrite(led2, HIGH);
        digitalWrite(led7, LOW);
        }
     else if (msg[0] == 111){
          digitalWrite(led2, LOW);
        }
     else if(msg[0] == 212){
        
          digitalWrite(led3, HIGH);
        }
    else if(msg[0] == 216){
          digitalWrite(led4, HIGH);
        }
    else if(msg[0] == 218){
          digitalWrite(led5, HIGH);
        }
    else if(msg[0] == 220){
          digitalWrite(led6, HIGH);
        }
    else if(msg[0] == 224){
          digitalWrite(led7, HIGH);
          digitalWrite(led1, LOW);
          digitalWrite(led2, LOW);
        delay(10);
        }
      }
   }

//Recieving code for servo motor

    if(radio.available()){           
      bool done = false;             
      while (!done) {
      done = radio.read(&angleValue,sizeof (angleValue) );
      myServo.write(angleValue);}
      delay(10);
     }
                  //Receiving code for LEDs
      else {   
      digitalWrite(led3, LOW);
      digitalWrite(led4, LOW);
      digitalWrite(led5, LOW);
      digitalWrite(led6, LOW);
      
      }
 }
[b]

sir,
Header added on the program.

"You have 32 bytes in every message to use, you should transmit both pieces of data in the same message using a “struct” to hold the variables."

I need more clarification on above quote.

sreekanthmp:
"You have 32 bytes in every message to use, you should transmit both pieces of data in the same message using a “struct” to hold the variables."

I need more clarification on above quote.

Have you carefully studied the examples in my Tutorial - the answer lies there.

...R

Please give one example of "struct" used programe for servo motor control

sreekanthmp:
Please give one example of "struct" used programe for servo motor control

There is lots of online info about structs.

If you know how to use an array (as in my examples) then using a struct is very similar. The difference between an array and a struct is that a struct can have elements with different variable types whereas in an array all the elements must be the same type.

It may even be possible to implement your requirement with an array.

...R

Please give me the instruction how to use "struct" command in programme and what is the use of struct.

Take some time to read this:
http://www.cplusplus.com/doc/tutorial/structures/
then write some simple programs to experiment with that information. If you still have questions after that come back here and ask something specific.

Google "C++ struct" and there is more info than you will ever want to read.

THANK YOU FOR YOUR FAVORABLE REPLY.
I am a beginner in Arduino programming so that program is also little bit lengthy sorry for inconvenience.
I have make a program for wire less controlling of a servo motor and LED(7 Nos.) using ARDUINO UNO, Funduino Joy stick shield V1.A and NRF24L01.First i have prepare the program only for controlling the LEDs and its become success as that LEDs working as per program.Than i added Servo motor also in circuit and make some changes in existing LED program. Unfortunately the result is erratic out put.joy stick input signal interrupting the led signal and some time servo motor respond led input .Transmitting code and Reciever code given below.

I came to know that this problem will solve using "struct" command in existing program . Please help me to modify the program with "struct".Because i have no thorough knowledge in C,C++

TRANSMITTER

[/b]
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>



#define xAxis A0   
RF24 radio(9,10);
const uint64_t pipe = 0xF0F0F0F0D2L;

int msg[1];
int buttonPin1 = 2;
int buttonPin2 = 3;
int buttonPin3 = 4;
int buttonPin4 = 5;
int buttonPin5 = 6;
int buttonPin6 = 7;
int buttonPin7 = 8;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
int buttonState7 = 0;


void setup(void)
{
  radio.begin();
  radio.openWritingPipe(pipe);
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin3, INPUT_PULLUP);
  pinMode(buttonPin4, INPUT_PULLUP);
  pinMode(buttonPin5, INPUT_PULLUP);
  pinMode(buttonPin6, INPUT_PULLUP);
  pinMode(buttonPin7, INPUT_PULLUP);
}

void loop(void)
{
  int potValue = analogRead(A0);                              //  INPUT FOR SERVO MOTOR
  int angleValue = map(potValue, 0, 1023, 0, 180); // INPUT FOR SERVO MOTOR
  radio.write(&angleValue, sizeof(angleValue));         // INPUT FOR SERVO MOTOR
  
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  buttonState5 = digitalRead(buttonPin5);
  buttonState6 = digitalRead(buttonPin6);
  buttonState7 = digitalRead(buttonPin7);
 

 if (buttonState1 == LOW){
    msg[0] = 111;
    radio.write(msg, 1);               // INPUT FOR LED1
   }
 if (buttonState2 == LOW){ 
    msg[0] = 222;
    radio.write(msg, 1);               // INPUT FOR LED2
   }
 if (buttonState3 == LOW){
    msg[0] = 212;
    radio.write(msg, 1);               // INPUT FOR LED3
   }  
 if (buttonState4 == LOW){
    msg[0] = 216;
    radio.write(msg, 1);                 // INPUT FOR LED4
   }
 if (buttonState5 == LOW){
    msg[0] = 218;
    radio.write(msg, 1);                // INPUT FOR LED5
   }
 if (buttonState6 == LOW){
    msg[0] = 220;
    radio.write(msg, 1);                 // INPUT FOR LED6
   }
    if (buttonState7 == LOW){
    msg[0] = 224;
    radio.write(msg, 1);
   }                                              // INPUT FOR LED7
 
  }

[b]

RECEIVER

[/b]#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>  
#include <Servo.h>  // SERVO LIBRARY INCLUDED

Servo myServo; 
RF24 radio(9,10);
const uint64_t pipe = 0xF0F0F0F0D2L;

int led1 = 2;
int led2 = A2;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int msg[1];
int angleValue ;

void setup(void)
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  myServo.attach(3);                  // SERVO CONNECTED TO PIN 3
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
}
void loop(void)
{
   // Receiving code for LED 1 TO LED 7

  if(radio.available()){
    bool done = false;
    while (!done) {
    done = radio.read(msg, 1);
    Serial.println(msg[0]);

    if (msg[0] == 111) {
      digitalWrite(led1, HIGH);
      digitalWrite(led7, LOW);
      }
    if(msg[0] == 222){
        digitalWrite(led1, LOW);
        digitalWrite(led2, HIGH);
        digitalWrite(led7, LOW);
        }
     else if (msg[0] == 111){
          digitalWrite(led2, LOW);
        }
     else if(msg[0] == 212){
        
          digitalWrite(led3, HIGH);
        }
    else if(msg[0] == 216){
          digitalWrite(led4, HIGH);
        }
    else if(msg[0] == 218){
          digitalWrite(led5, HIGH);
        }
    else if(msg[0] == 220){
          digitalWrite(led6, HIGH);
        }
    else if(msg[0] == 224){
          digitalWrite(led7, HIGH);
          digitalWrite(led1, LOW);
          digitalWrite(led2, LOW);
        delay(10);
        }
      }
   }

//Recieving code for servo motor

    if(radio.available()){           
      bool done = false;             
      while (!done) {
      done = radio.read(&angleValue,sizeof (angleValue) );
      myServo.write(angleValue);}
      delay(10);
     }
                  //Receiving code for LEDs
      else {   
      digitalWrite(led3, LOW);
      digitalWrite(led4, LOW);
      digitalWrite(led5, LOW);
      digitalWrite(led6, LOW);
      
      }
 }
[b]

You should explain to us where you got the information that structure will solve your problem and how it would solve it. Strict is just a way of organizing data.

Try Googling struct nrf24

marco_c:
You should explain to us where you got the information that structure will solve your problem and how it would solve it. Strict is just a way of organizing data.

i got information from project guidance ARDUINO FORUM.

sreekanthmp is referring to this thread:
http://forum.arduino.cc/index.php?action=profile;u=251768
which is starting to mirror the discussion here.

sreekanthmp started a new thread for discussion of struct:
http://forum.arduino.cc/index.php?topic=544587

That link it to a profile, not discussion.

Sorry, here's the right one:
http://forum.arduino.cc/index.php?topic=544108.msg3709013#msg3709013

Threads merged.