NRF24 optimization

Hi, I'm using NRF24 and a custom PCB with esp32.

My goal is to get around 100 meter stable reception, in an open field but that might have some interferences in the way.

By testing what I have now I reach around ~70 meters.

The Module gets its 3.3V from AMS1117-3.3.

What other things I can do to improve range? data speed rate is in lower priority.

What other similar boards/modules/ic's are there with the same popularity and price would you recommend?

Code:
Sender side:

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

#define CE_PIN 5
#define CSN_PIN 4

#define CONTINUOUS_PIN 32 //RED
#define BUTTON_PIN 33 //GREEN

#define CONTINUOUS 1
#define NOT_CONTINUOUS 0

bool continuousState = false;

RF24 radio(CE_PIN, CSN_PIN);

const uint64_t this_node_address = 0xABCDABCD71LL;
const uint64_t other_node_address = 0xABCDABCD72LL;

struct Payload {
  int red_green_status;
  int sensitivity;
  int player_id;
};

void updateContinuousExperiment();
void sendData();
void experiment(int continuous);

void setup() {
  Serial.begin(115200);
  Serial.println("Master starting!");

  pinMode(CONTINUOUS_PIN, INPUT_PULLUP);
  pinMode(BUTTON_PIN, INPUT_PULLUP);

  radio.begin();
  radio.setChannel(115);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_HIGH);
  radio.openWritingPipe(other_node_address);
}

void loop() {

  updateContinuousExperiment();

  if (continuousState) {
    experiment(CONTINUOUS);
  }
  else {
    experiment(NOT_CONTINUOUS);
  }

}

void experiment(int continuous) {
  if (!continuous) {
    if (digitalRead(BUTTON_PIN) == LOW) {
      sendData();
      Serial.println("Sending data");
      delay(500);
    }
  }
  else {
      sendData();
  }
}

void updateContinuousExperiment() {

  if (digitalRead(CONTINUOUS_PIN) == LOW) {
    continuousState = !continuousState;
    Serial.print("Continuous state: ");
    Serial.println(continuousState);
    delay(500);
  }

}

void sendData() {
  Payload data;
  data.red_green_status = 1;
  data.sensitivity = 5;
  data.player_id = 20;

  bool success = radio.write(&data, sizeof(data));
  if (success) {
    Serial.println("Message sent successfully!");
  } else {
    Serial.println("Failed to send message!");
  }
}

Receiver side:

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

#define CE_PIN 5
#define CSN_PIN 4

#define LED 26

RF24 radio(CE_PIN, CSN_PIN);

struct Payload {
  int red_green_status;
  int sensitivity;
  int player_id;
};

const uint64_t this_node_address = 0xABCDABCD72LL;
const uint64_t other_node_address = 0xABCDABCD71LL;

void setup() {
  Serial.begin(115200);
  Serial.println("Slave starting!");

  radio.begin();
  radio.setChannel(115);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_HIGH);
  radio.openReadingPipe(1, this_node_address);
  radio.startListening();

  pinMode(LED, OUTPUT);

  digitalWrite(LED, HIGH);
  delay(500);
  digitalWrite(LED, LOW);
  delay(500);
  digitalWrite(LED, HIGH);
  delay(500);
  digitalWrite(LED, LOW);

}

void loop() {
  static unsigned long lastMessage = 0;

  if (radio.available()) {
    Payload data;
    radio.read(&data, sizeof(data));

    if (data.player_id == 20) {
      digitalWrite(LED, HIGH);
      lastMessage = millis();
    }
  }

  if (millis() - lastMessage > 200) {
    digitalWrite(LED, LOW);
  }
}

Thanks

Do your NRF24 boards have an external or built in antenna ?

Yes, forgot to mention I am using the NRF24L01+PA+LNA Wireless Module

HC-12 modules have a much better range than NRF2401.

But take care because some bad batches of cloned HC-12 boards were made with very poor range and these might still be on sale. Google to find out how to spot the good ones from the bad ones.

Thanks, I see that they come with this spring like antenna, are these what you meant?
https://bit.ly/3UFfkDD

For 2.4Ghz radios, then the LoRa SX1280 is a good choice.

Can be as fast as the NRF24 but with longer range plus the ability to slow it down a bit and get silly long range.

Current distance record for SX1280 is I believe 89km, ground to high altitude balloon, but it would go further.

If UHF is OK, there are no duty cycle issues etc, then there are plenty of modules out there that will do the distance, HC-12 is one popular choice.

What is the difference between LoRa SX1278(which seems to be cheaper and longer range) and SX1280?

SX1278 runs on UHF, 434Mhz, 868Mhz, 915Mhz.
SX1280 runs on 2.4Ghz.

1 Like

Thanks all, will try the suggestions from here

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