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