nRF24L01 modules work only sometimes

Hi guys,

I am trying to get the NRF24 Modules to work but all I get is short lived moments of when it works. I am using the transmitter to send signals to the receiver, which in turn sends a signal to the Motor Controller module to spin the motor.

Both the transmitter and receiver are connected on Nano Every's. Currently they are both powered with 9v batteries. Both NRF24 modules have 10uf caps connected. I double checked for connections issues and shorts.

Sometimes the Rx and Tx connect and the motor spins correctly and everything is fine. This lasts only a few moments before it stops responding again. Usually it happen when I connect the USB to the transmitter to see what the Serial console is printing. Once I open up the Serial monitor it might, if I am lucky, connect and work for a bit.

I don't have any reason to believe that it is a connection issue since it sporadically works as intended. I can post a diagram if needed. If anyone has any clue I'd appreciate the help.

Here is my Tx code:

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

const byte ledPin = 5;

RF24 radio(7,8); //CE, CNS
const byte address[6] = "00001";
const int button = 3;
int buttonPressed;  


int joystick;


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.stopListening(); //transmitter

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
delay(300);  
digitalWrite(ledPin, HIGH);
delay(300);  
digitalWrite(ledPin, LOW);
radio.printDetails();
  
}

void loop() {
  
  // put your main code here, to run repeatedly:
 
  
  joystick = analogRead(A1);
  Serial.println(joystick);

  if(joystick > 530)
  {
    motorForward(joystick); 
  }
  if(joystick < 480)
  {
    motorBackward(joystick);
  }
  if(joystick >= 480 && joystick <= 530)
  {
    motorStill();
  }

  
}


void motorBackward(int jsInput)
{
 //digitalWrite(motorPin1, LOW);
 //digitalWrite(motorPin2, HIGH);
 int motorSpeed = map(jsInput, 480, 0, 0, 255);
 int message[] = {2, motorSpeed};
 radio.write(&message, sizeof(message));
 //analogWrite(motorPWM, motorSpeed);

 
 delay(20);
 
}

void motorForward(int jsInput)
{

 int motorSpeed = map(jsInput, 530, 1023, 0, 255);
 int message[] = {1, motorSpeed};
 radio.write(&message, sizeof(message));

 delay(20);
 
 

 
}

void motorStill()
{
   
    int message[] = {0};
    radio.write(&message, sizeof(message));
}

Here is my Rx code:

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#define motorPWM 6

RF24 radio(7,8); //CE, CNS
const byte address[6] = "00001"; 

byte motorPin1 = 4;
byte motorPin2 = 5;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0,address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.startListening();

 pinMode(motorPin1, OUTPUT);
 pinMode(motorPin2, OUTPUT);
 pinMode(motorPWM, OUTPUT);

 //test motor 
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPWM, 600);
Serial.print("Test motor started");
delay(2000);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin1, LOW);
Serial.print("Test motor complete");
radio.printDetails();


}

void loop() {
  
  // put your main code here, to run repeatedly:
  
if(radio.available())
{
   //0 = still, 1 is forward and 2 is backward
  int message[2];
  Serial.println("radio detected");
  radio.read(&message, sizeof(message));
  Serial.println(message[0]);
  Serial.println(message[1]);
  
  
   
  if(message[0] == 1)
  {
    
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    analogWrite(motorPWM, message[1]);
    delay(20);
    Serial.println("move forward");
  }

  if(message[0] == 2)
  {
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    analogWrite(motorPWM, message[1]);
    delay(20);
  }

  if(message[0] == 0)
  {
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    delay(20);
  }

  Serial.println("radio available");
  
  
}
  
}

Sorry to bring bad news. The 9 volt batteries will only power an Arduino for a short time just by itself. Add in other devices and there is not sufficient current, no matter what capacitors you use.

Save your self grief and power the NRF devices from pairs of AA cells in series. All grounds and - connected together.

So I have the 9v battery powering the motor control module and the arduino. Then the arduino 3.3v powering the nrf24l01. That is not good enough? The motor spins full force when I reset the program. In the setup code I have it turn on for a second just to make sure.

IF it was you would not be having the problem.

Well that is assuming that without a doubt it is a power issue. I will give that a try

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.