1
\$\begingroup\$

I want to control my car with nRF24L01 2.4GHz Radio/Wireless Transceivers. I am using an Arduino Mega, Arduino UNO, joystick, LED and two nRF24L01 2.4GHz radio/wireless transceivers. Here the Arduino Mega is the transmitter circuit and the Arduino UNO is the receiver circuit.

In the transmitter the circuit connections are:

  1. GND
  2. VCC 3.3V
  3. CE to Arduino pin 9
  4. CSN to Arduino pin 10
  5. SCK to Arduino pin 13
  6. MOSI to Arduino pin 11
  7. MISO to Arduino pin 12
  8. Joystick X axis to Arduino pin A0
  9. Joystick Y axis to Arduini pin A1
  10. Joystick Vcc and GND

Here I want to send the joystick's x and y axis with the module. Here are the receiver circuit connections:

  1. GND
  2. VCC 3.3V
  3. CE to Arduino pin 9
  4. CSN to Arduino pin 10
  5. SCK to Arduino pin 13
  6. MOSI to Arduino pin 11
  7. MISO to Arduino pin 12
  8. LED to Arduino pin 3.

This LED helps to control. Actually I want to control my car with joystick like a remote controlled car. Here is the transmitter's code:

#include "SPI.h"
#include "nRF24L01.h"
#include "RF24.h"
#define VRx A0
#define VRy A1

int VRxPos = 90;
int VRyPos = 90;
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup()
{
    radio.begin();
    radio.openWritingPipe(pipe);
}

void loop()
{
    VRxPos = analogRead(VRx);
    VRxPos = map(VRxPos, 0, 1023, 0, 180);
    VRyPos = analogRead(VRy);
    VRyPos = map(VRyPos, 0, 1023, 0, 180);
    if((VRxPos==88) && (VRyPos==85))
    {
        msg[0] = 111;
        radio.write(msg, 1);
    } else {
        msg[0] = 112;
        radio.write(msg, 1);
    }
}

Here is the receivers's code:

#include "SPI.h"
#include "nRF24L01.h"
#include "RF24.h"

int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL; 
int LEDpin = 3;

void setup()
{
    radio.begin();
    radio.openReadingPipe(1,pipe); 
    radio.startListening(); 
    pinMode(LEDpin, OUTPUT);
}

void loop()
{
    if (radio.available())
    {
        bool done = false;
        while (!done)
        {
            done = radio.read(msg, 1);
            if (msg[0] == 111)
            {
                delay(10);
                digitalWrite(LEDpin, HIGH);
            } else {
                digitalWrite(LEDpin, LOW);
            }
            delay(10);
        }
    }
}

It's not working. The LED is not lighting. What can I do to solve this problem? Is const uint64_t pipe = 0xE8E8F0F0E1LL; wrong? I saw some different numbers for this equation. What is this logic?

\$\endgroup\$
3
\$\begingroup\$

I would suggest you edit this question and use the code format to pretty print your code as it's very hard to follow the way it currently is.

The value for the pipe variable is an address, more or less the equivalent of your computer IP address: when a message is broadcast into the air all the potential receivers will filter out any message not corresponding to an address they are interested into.

In particular your nRF24L01+ chip is capable to listen for up to 6 addresses.

Another address is the one you use to transmit, so that everybody receiving your message knows who has sent it and to reply to.

So, in your code radio.openReadingPipe(1,pipe); // pipe value being 0xE8E8F0F0E1LL

means hey, radio, use the second pipe to listen for any message incoming from address 0xE8E8F0F0E1LL, while radio.openWritingPipe(pipe); // pipe value being 0xE8E8F0F0E1LL

means hey, radio, when sending messages identify yourself with address 0xE8E8F0F0E1LL.

That's the explanation for the pipe thing and in a short form: those two values in your sketch must match.

Regarding the fact you are not receiving the message, I suggest the following:

  1. try setting the message payload size to a fixed value with radio.setPayloadSize(1)
  2. add a 1uF capacitor short between GND and Vcc on your nRF24 board
  3. try to use the most reliable configuration which, on the nRF24L01+ is the 250Kbps with maximum PA level by setting radio.setPALevel(RF24_PA_HIGH); radio.setDataRate(RF24_250KBPS);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.