nRF24L01 remote and receiver distance problems

Hello

Before doing this project:

There was already a made receiver and remote.
But i didnt not have receiver code and remote(transmitter) was trashed beyond saving.

So i made new program on receiver, with only difference to hardware i used arduino nano every instead of regular arduino nano.

I made a new remote, schematic bellow.
For remote i also used arduino nano every. I am quite pleased with arduino nano every as it boots blazingly fast.

On remote i use regular nRF24L01 and on receiver end it is used NRF24L01+ PA/LNA.
Yeah i know it makes more sense to use NRF24L01+ PA/LNA on transmitter but i am limited with space + it was done like this originally.

But i am having big problems with working distance which currently is 20m.
Googling it they suggest to:

  • change speed to 250kbps
  • transmitting power to high or max
  • change channel (set to 120 now)
  • and put a capacitator between GND and VCC of module

I was also thinking if there is some interferrence from some other device, but even if i try it else where i get same results.

I tried replacing nRF24L01 since i have multiple in case there was something wrong with them.

I did all of above mentioned without any better results.

I am looking at schematic and arduino nano every uses AP2112 which is regular LDO with 600mA for 3.3V so i dont see how that could present problems or is it that i could have problems because of drop-down switcher in nano every?

Ill take it home during weekend to hook it up to osciloscope to check voltage stability or to make receiver and transmitter with regular arduinos .

Below schematic of remote and transmitter, reciver code.
But i am guessing if there was any code problems communication wouldnt work at all.

Any ideas/help is greatly appreciated.

#include "Arduino.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include<avr/wdt.h> //watchdog

RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";


const long power_off_interval = 5000;
const long transmit_interval = 80;
const long button_error_interval = 20000;


unsigned long currentMillis = 0;
unsigned long previousMillisPOff = 0; 
unsigned long previousMillisTransmit = 0; 
unsigned long previousMillisBlinking = 0; 
unsigned long previousMillisBErrordetect = 0; 

const int button1 = 2;
const int button2 = 3;
const int button3 = 4;
const int powerPin = 5;
const int ledPin = 6;

const int batteryVolTreshold = 181; //  3.55V
int batteryVol = 0;


boolean button1State = HIGH;
boolean button2State = HIGH;
boolean button3State = HIGH;

int state = 0; // 1 = ok voltage, 2 = low voltage, 3 = error
bool error = false;

bool ledOn = false; // keep track of the led state
bool ledBlinking = false;
long ledBlinking_interval = 500;

Receiver:
void setup() {
  
  wdt_reset();  // Reset the watchdog
  wdt_enable(WDT_PERIOD_512CLK_gc);  // Enable the watchdog with a timeout of 0.512 second


  pinMode(powerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(button1, INPUT_PULLUP);  
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  
 
  radio.begin();
  radio.openWritingPipe(address);
  radio.setRetries(15, 10);  //every time it transmits  10 times with a delay in between of 15 * 250uS = 4000uS - 4ms
  radio.setChannel(120);
  radio.setPALevel(RF24_PA_HIGH);
  radio.setDataRate(RF24_250KBPS);
  radio.powerUp();    
  radio.stopListening();          //This sets the module as transmitter


  digitalWrite(powerPin, HIGH);
  digitalWrite(ledPin, LOW);
  previousMillisPOff = millis();
  
}

void loop() {

  currentMillis = millis();

  button1State = digitalRead(button1);
  button2State = digitalRead(button2);
  button3State = digitalRead(button3);

  //  AUTOMATIC POWER OFF
  if ((currentMillis - previousMillisPOff <= power_off_interval) && (button1State == LOW || button2State == LOW || button3State == LOW))
  {
    previousMillisPOff = millis();
  }

  // if button is not pressed for longer then interval it turns off the arduino
  if (currentMillis - previousMillisPOff >= power_off_interval) {
    digitalWrite(powerPin, LOW);
  }


  //  VOLTAGE  INDICATOR
  //  fully charged battery is 4.1v
  //  nominal voltage is  3.7v
  // 3.55v is where i start signaling low battery voltage, which corresponds to 181 value
  batteryVol = analogRead(A0);
  if (error == false){
    if(batteryVol > batteryVolTreshold){
       state = 1;
    }else{
       state = 2;
    }
  }


  // LED
  if (state == 1){
    ledBlinking = false;
  }else if(state == 2){
    ledBlinking = true;
    ledBlinking_interval = 500;
  }else{
    ledBlinking = true;
    ledBlinking_interval = 125;
  }

  if (ledBlinking == false){
    digitalWrite(ledPin, HIGH);
  }else{
    if ((currentMillis - previousMillisBlinking) >= ledBlinking_interval){
      ledOn = !ledOn;
       if (ledOn){
        digitalWrite(ledPin, HIGH); // turn led on
       } else {
        digitalWrite(ledPin, LOW); // turn led off
       }
       previousMillisBlinking = millis();
    }
  }


  // ERROR DETECTION
  // if 2 buttons pressed
    if(((button1State == LOW)&&(button2State == LOW)) || ((button1State == LOW)&&(button3State == LOW))|| ((button2State == LOW)&&(button3State == LOW))){
      error = true;
    }
    if ((currentMillis - previousMillisBErrordetect) >= button_error_interval) {
      error = true;
    }

    if (error == true){
      state = 3;
    }

  
  //  BUTTONS
  if ((((currentMillis - previousMillisTransmit) >= transmit_interval)) && (error == LOW)) {
    if ((button1State == LOW)&&(button2State == HIGH)&&(button3State == HIGH)) { // if button 1 pressed
      char text[] = "1119";
      radio.write(&text, sizeof(text));
    } else if ((button1State == HIGH)&&(button2State == LOW)&&(button3State == HIGH)) {  // if button 2 pressed
      char text[] = "2229";
      radio.write(&text, sizeof(text));
    } else if ((button1State == HIGH)&&(button2State == HIGH)&&(button3State == LOW)) {  // if button 3 pressed
      char text[] = "3339";
      radio.write(&text, sizeof(text));
    } else {  // no button pressed we reset error detection for button
      previousMillisBErrordetect = millis();
    }
    
    previousMillisTransmit = millis();
  }  
  
  wdt_reset();  // Reset the watchdog
}

Transmitter:

#include "Arduino.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include<avr/wdt.h> //watchdog

RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";


const long power_off_interval = 5000;
const long transmit_interval = 80;
const long button_error_interval = 20000;


unsigned long currentMillis = 0;
unsigned long previousMillisPOff = 0; 
unsigned long previousMillisTransmit = 0; 
unsigned long previousMillisBlinking = 0; 
unsigned long previousMillisBErrordetect = 0; 

const int button1 = 2;
const int button2 = 3;
const int button3 = 4;
const int powerPin = 5;
const int ledPin = 6;

const int batteryVolTreshold = 181; //  3.55V
int batteryVol = 0;


boolean button1State = HIGH;
boolean button2State = HIGH;
boolean button3State = HIGH;

int state = 0; // 1 = ok voltage, 2 = low voltage, 3 = error
bool error = false;

bool ledOn = false; // keep track of the led state
bool ledBlinking = false;
long ledBlinking_interval = 500;


void setup() {
  
  wdt_reset();  // Reset the watchdog
  wdt_enable(WDT_PERIOD_512CLK_gc);  // Enable the watchdog with a timeout of 0.512 second


  pinMode(powerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(button1, INPUT_PULLUP);  
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  
 
  radio.begin();
  radio.openWritingPipe(address);
  radio.setRetries(15, 10);  //every time it transmits  10 times with a delay in between of 15 * 250uS = 4000uS - 4ms
  radio.setChannel(120);
  radio.setPALevel(RF24_PA_HIGH);
  radio.setDataRate(RF24_250KBPS);
  radio.powerUp();    
  radio.stopListening();          //This sets the module as transmitter


  digitalWrite(powerPin, HIGH);
  digitalWrite(ledPin, LOW);
  previousMillisPOff = millis();
  
}

void loop() {

  currentMillis = millis();

  button1State = digitalRead(button1);
  button2State = digitalRead(button2);
  button3State = digitalRead(button3);

  //  AUTOMATIC POWER OFF
  if ((currentMillis - previousMillisPOff <= power_off_interval) && (button1State == LOW || button2State == LOW || button3State == LOW))
  {
    previousMillisPOff = millis();
  }

  // if button is not pressed for longer then interval it turns off the arduino
  if (currentMillis - previousMillisPOff >= power_off_interval) {
    digitalWrite(powerPin, LOW);
  }


  //  VOLTAGE  INDICATOR
  //  fully charged battery is 4.1v
  //  nominal voltage is  3.7v
  // 3.55v is where i start signaling low battery voltage, which corresponds to 181 value
  batteryVol = analogRead(A0);
  if (error == false){
    if(batteryVol > batteryVolTreshold){
       state = 1;
    }else{
       state = 2;
    }
  }


  // LED
  if (state == 1){
    ledBlinking = false;
  }else if(state == 2){
    ledBlinking = true;
    ledBlinking_interval = 500;
  }else{
    ledBlinking = true;
    ledBlinking_interval = 125;
  }

  if (ledBlinking == false){
    digitalWrite(ledPin, HIGH);
  }else{
    if ((currentMillis - previousMillisBlinking) >= ledBlinking_interval){
      ledOn = !ledOn;
       if (ledOn){
        digitalWrite(ledPin, HIGH); // turn led on
       } else {
        digitalWrite(ledPin, LOW); // turn led off
       }
       previousMillisBlinking = millis();
    }
  }


  // ERROR DETECTION
  // if 2 buttons pressed
    if(((button1State == LOW)&&(button2State == LOW)) || ((button1State == LOW)&&(button3State == LOW))|| ((button2State == LOW)&&(button3State == LOW))){
      error = true;
    }
    if ((currentMillis - previousMillisBErrordetect) >= button_error_interval) {
      error = true;
    }

    if (error == true){
      state = 3;
    }

  
  //  BUTTONS
  if ((((currentMillis - previousMillisTransmit) >= transmit_interval)) && (error == LOW)) {
    if ((button1State == LOW)&&(button2State == HIGH)&&(button3State == HIGH)) { // if button 1 pressed
      char text[] = "1119";
      radio.write(&text, sizeof(text));
    } else if ((button1State == HIGH)&&(button2State == LOW)&&(button3State == HIGH)) {  // if button 2 pressed
      char text[] = "2229";
      radio.write(&text, sizeof(text));
    } else if ((button1State == HIGH)&&(button2State == HIGH)&&(button3State == LOW)) {  // if button 3 pressed
      char text[] = "3339";
      radio.write(&text, sizeof(text));
    } else {  // no button pressed we reset error detection for button
      previousMillisBErrordetect = millis();
    }
    
    previousMillisTransmit = millis();
  }  
  
  wdt_reset();  // Reset the watchdog
}

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