Problems with nRF24L01, It disconnects after a while or shows negative values.

Good evening everyone!

I would like your help on this small project I am working on and hope to expand in the future, I’m sending ten variables through the nRF24L01 radio transceiver. five values correspond to variable resistors and another five correspond to the state of buttons.

The receiver receives the data without problem and shows it on a LCD 16x2 display. By pressing one button the data I can see the data of one variable and so on just like a menu, and with another button I can see the previous data

The problem is that whenever I press the buttons suddenly all the data on the LCD becomes zero, or the receiver starts showing me negative numbers on the serial monitor which isn’t supposed to happen. Sometimes even if I don’t press the buttons the receiver disconnects from the transmitter after 20 minutes and I have to reset both manually and everything starts working again.

I am not sure if the jumpers dupont on my breadboard are causing electromagnetic interference with the nRF24L01. I am supplying the nRF24L01 with 5V of Arduino. A voltage regulator turns those 5V into 3.3V

Here’s an attachment of the wiring of both nRF24L01:

And you always suspect the hardware and never the software?

Paul

Is the transmitter really only supplied by the Uno 3.3V. Have you tried putting a 10uF cap across the 3.3V supply. A large percentage of problems with the rf24 radios can be attributed to lack of power.

These are fire-and-forget packet transceivers, there is no "connection" to drop (unless that's provided
by a software layer atop the basic hardware level).

You haven't posted your code, making it impossible to see where the bug might be :slight_smile:

You regulator is missing the mandatory capacitors.

Transmitter:

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

const int pinCE = 9;
const int pinCSN = 10;

RF24 radio(pinCE, pinCSN);

const byte direccion[5] = "CANAL";

const int CALEFACTOR = 2;
const int BOMBA = 3;
const int ON_OFF = 4;
const int ALARMA = 5;
const int RUN = 6;

int ButtonStateP2 = 0;
int ButtonStateP3 = 0;
int ButtonStateP4 = 0;
int ButtonStateP5 = 0;
int ButtonStateP6 = 0;

float Analogo[5];
int Digital[5];

void setup()
{
  Serial.begin(9600); 
  radio.begin();
  radio.openWritingPipe(direccion);
  radio.stopListening();

  pinMode(CALEFACTOR,INPUT);
  pinMode(BOMBA,INPUT);
  pinMode(ON_OFF,INPUT);
  pinMode(ALARMA,INPUT);
  pinMode(RUN,INPUT); 
}
 
void loop()
{
  bool ok = radio.write(Analogo, sizeof(Analogo)) && radio.write(Digital, sizeof(Digital));
  
  if(ok)
  {
     POTENTIOMETERS();
     BUTTONS();
  }
  else
  {
     Serial.println("THE DATA COULDN'T BE SENT");
  }
  delay(1000);
}

void POTENTIOMETERS()
{
  //Generador De Vapor - Presión
  int Presion_Vapor = analogRead(A0);
  float Presion_Vapor_Res = Presion_Vapor * (5.0/1023.0);
  Analogo[0] = Presion_Vapor_Res;

  //Autoclave Grande - Temperatura
  int AG_Temp = analogRead(A1);
  float AG_Temp_Res = AG_Temp * (5.0/1023.0);
  Analogo[1] = AG_Temp_Res;
 
  //Autoclave Grande - Presión
  int AG_Temp_Presion = analogRead(A2);
  float AG_Temp_Presion_Res = AG_Temp_Presion * (5.0/1023.0);
  Analogo[2] = AG_Temp_Presion_Res;
 
  //Autoclave Pequeña - Temperatura
  int AP_Temp = analogRead(A3);
  float AP_Temp_Res = AP_Temp * (5.0/1023.0);
  Analogo[3] = AP_Temp_Res;

  //Autoclave Pequeña - Presión 
  int AP_Presion = analogRead(A4);
  float AP_Presion_Res = AP_Presion * (5.0/1023.0);
  Analogo[4] = AP_Presion_Res;

  Serial.print("***** SENSORES *****");
  Serial.print('\n');
  Serial.print("GENERADOR DE VAPOR (PSI): ");
  Serial.println(Analogo[0]);
  Serial.print("AUTOCLAVE GRANDE   (°C ): ");
  Serial.println(Analogo[1]);
  Serial.print("AUTOCLAVE GRANDE   (PSI): ");
  Serial.println(Analogo[2]);
  Serial.print("AUTOCLAVE PEQUEÑA  (°C ): ");
  Serial.println(Analogo[3]);
  Serial.print("AUTOCLAVE PEQUEÑA  (PSI): ");
  Serial.println(Analogo[4]);
  Serial.print('\n');
}

void BUTTONS()
{
  //Contactor De Calefactor
  ButtonStateP2 = digitalRead(CALEFACTOR);
  Digital[0] = ButtonStateP2;

  //Contactor De Bomba
  ButtonStateP3 = digitalRead(BOMBA);
  Digital[1] = ButtonStateP3;

  //Contactor De Encendido/Apagado
  ButtonStateP4 = digitalRead(ON_OFF);
  Digital[2] = ButtonStateP4;

  //Contactor De Alarma
  ButtonStateP5 = digitalRead(ALARMA);
  Digital[3] = ButtonStateP5;

  //Contactor De Run
  ButtonStateP6 = digitalRead(RUN);
  Digital[4] = ButtonStateP6;

  if(Digital[0] == 1)
  {
    Serial.print("*** CONTACTORES ****");
    Serial.print('\n');
    Serial.print("CALEFACTOR        : ");
    Serial.println("ENCENDIDO");
  }

  else
  {
    Serial.print("*** CONTACTORES ****");
    Serial.print('\n');
    Serial.print("CALEFACTOR        : ");
    Serial.println("APAGADO");
  }

  if(Digital[1] == 1)
  {
    Serial.print("BOMBA             : ");
    Serial.println("ENCENDIDA");
  }

  else
  {
    Serial.print("BOMBA             : ");
    Serial.println("APAGADA");
  }

  if(Digital[2] == 1)
  {
    Serial.print("ENCENDIDO/APAGADO : ");
    Serial.println("ENCENDIDO");
  }

  else
  {
    Serial.print("ENCENDIDO/APAGADO : ");
    Serial.println("APAGADO");
  }

  if(Digital[3] == 1)
  {
    Serial.print("INUNDACIÓN        : ");
    Serial.println("¡PELIGRO!");
  }

  else
  {
    Serial.print("INUNDACIÓN        : ");
    Serial.println("NORMAL");
  }

  if(Digital[4] == 1)
  {
     Serial.print("RUN               : ");
     Serial.println("ENCENDIDO");
     Serial.print('\n');
  }

  else
  {
     Serial.print("RUN               : ");
     Serial.println("APAGADO");
     Serial.print('\n');
  }
}

Receiver:

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

#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7); /* RS -> PIN 2, ENABLE -> PIN 3, D4 -> PIN 4, D5 -> PIN 5, D6 -> PIN 6, D7 -> PIN 7 */

/*MENU SELECT*/

const int next = A0;
const int previous = A1;

int value_next;
int value_previous;
int value = 0;

int lastButtonState=0;
int lastButtonState2=0;

/* TIMERS */

unsigned long LastReading = 0;
unsigned long UltimaLectura = 0;

/* ALARMA */

const int Buzzer = 8;

/*nRF24L01*/

const int pinCE = 9;
const int pinCSN = 10;

RF24 radio(pinCE, pinCSN);

const byte direccion[5] = "CANAL";

/* DATA SENT THROUGH nRF24L01 */

float Analogo[5];
int Digital[5];

void setup()
{
  Serial.begin(9600); 
  radio.begin();
  radio.openReadingPipe(1, direccion);
  radio.startListening();

  lcd.begin(16,2);
  lcd.clear();

  pinMode(Buzzer,OUTPUT);
}
 
void loop() 
{
  if(millis()-LastReading > 1000)
  {
    if (radio.available())
    {    
      radio.read(Analogo,sizeof(Analogo));
      radio.read(Digital,sizeof(Digital));
      
      for(int i = 0; i < 5; i++)
      {
        Serial.print(Analogo[i]);
        Serial.print(",");
      }

      for(int j = 0; j < 5; j++)
      {
        Serial.print(Digital[j]);
        Serial.print(",");
      }
      Serial.println("");
      ALARMA();
    }
    
    else
    {
      Serial.println("NO DATA AVAILABLE"); 
      digitalWrite(Buzzer,HIGH);
    }
    LastReading = millis();
  }
  MENU_BUTTONS();
}

void MENU_BUTTONS()
{
  value_next = analogRead(next);
  value_previous = analogRead(previous);
  
  // INCREMENTAR value
  
  if(value_next != lastButtonState)
  {
    if(value_next >= 100)
    {
      value = value + 1;
      delay(250);
    }
    
    if(value == 10)
    {
      value = 0;
    }
  }
  lastButtonState = value_next;
  
  // DECREMENTAR value
  if(value_previous != lastButtonState2)
  {  
    if(value_previous >= 100)
    {
      value = value - 1;
      delay(250);
    }
  
    if(value == -1)
    {
      value = 9;
    }
  }
  lastButtonState2 = value_previous;

  if(millis() - UltimaLectura > 500)
  {
  if(value == 0)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("GENERADOR VAPOR");
    lcd.setCursor(0,1);
    lcd.print(Analogo[0]);
    lcd.print(" PSI");
  }

  if(value == 1)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("AUTOCLAVE GRANDE");
    lcd.setCursor(0,1);
    lcd.print("TEMP:");
    lcd.print(Analogo[1]);
    lcd.print((char)223);
    lcd.print("C"); 
  }

  if(value == 2)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("AUTOCLAVE GRANDE");
    lcd.setCursor(0,1);
    lcd.print(Analogo[2]);
    lcd.print(" PSI");
  }

  if(value == 3)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("AUTOCLAVE PEQUE");
    lcd.setCursor(0,1);
    lcd.print("TEMP:");
    lcd.print(Analogo[3]);
    lcd.print((char)223);
    lcd.print("C");  
  }
  
  if(value == 4)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("AUTOCLAVE PEQUE");
    lcd.setCursor(0,1);
    lcd.print(Analogo[4]);
    lcd.print(" PSI");
  }

  if(value == 5)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("CALEFACTOR");
    
    if(Digital[0] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ENCENDIDO");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("APAGADO");
    }
  }

  if(value == 6)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BOMBA");
    
    if(Digital[1] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ENCENDIDO");
    }
    
    else
    {
      lcd.setCursor(0,1);
      lcd.print("APAGADO");
    }
  }

  if(value == 7)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("ON-OFF");
    
    if(Digital[2] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ENCENDIDO");
    }
    
    else
    {
      lcd.setCursor(0,1);
      lcd.print("APAGADO");
    }
  }
  
  if(value == 8)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("INUNDACION");
    
    if(Digital[3] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("PELIGRO!");
    }

    else
    {
      lcd.setCursor(0,1);
      lcd.print("NORMAL");
    }
  }
  
  if(value == 9)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("RUN");
    
    if(Digital[4] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ENCENDIDO");
    }

    else
    {
      lcd.setCursor(0,1);
      lcd.print("APAGADO");
    }
  }
  UltimaLectura = millis();
  }
}

void ALARMA()
{
  if(Analogo[0] > 3.5 || Analogo[1] > 3.5 || Analogo[2] > 3.5 || Analogo[3] > 3.5 || Analogo[4] > 3.5 || Digital[3] == 1)
  {
    digitalWrite(Buzzer,HIGH);
  }
  
  else
  {
    digitalWrite(Buzzer,LOW);
  }
}

groundFungus:
Is the transmitter really only supplied by the Uno 3.3V. Have you tried putting a 10uF cap across the 3.3V supply. A large percentage of problems with the rf24 radios can be attributed to lack of power.

I already did and it still doesn't work.

MarkT:
These are fire-and-forget packet transceivers, there is no "connection" to drop (unless that's provided
by a software layer atop the basic hardware level).

You haven't posted your code, making it impossible to see where the bug might be :slight_smile:

You regulator is missing the mandatory capacitors.

I already posted both codes. The transmitter never loses the connection, but the receiver loses the connection like every four or five seconds.