Problems with the data received from nRF24L01, 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 after some 10 minutes, the values of the potentiometers become zero and the ones of the buttons become negative on the serial monitor which isn't supposed to happen. I have to reset the receiver manually and everything starts working again.

These are the negative values, I receive after a few minutes:

Code of the transmitter circuit:

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

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

RF24 radio(pinCE, pinCSN);

const byte address[5] = "CANAL";

const int PushButton1 = 2;
const int PushButton2 = 3;
const int PushButton3 = 4;
const int PushButton4 = 5;
const int PushButton5 = 6;

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

float Analog[5];
int Digital[5];

unsigned long LastReading = 0;

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

  pinMode(PB1,INPUT);
  pinMode(PB2,INPUT);
  pinMode(PB3,INPUT);
  pinMode(PB4,INPUT);
  pinMode(PB5,INPUT); 
}
 
void loop()
{
  if(millis() - LastReading > 1000)
  {
    bool ok = radio.write(&Analog, sizeof(Analog)) && radio.write(&Digital, sizeof(Digital));
    
    if(ok)
    {
      POTENTIOMETERS();
      BUTTONS();
      Serial.println("");
    }
    else
    {
      Serial.println("DATA NOT SENT");
    }
    LastReading = millis();
  }
}

void POTENTIOMETERS()
{
  int sensorValue1 = analogRead(A0);
  float sensorValueResult = sensorValue1 * (5.0/1023.0);
  Analog[0] = sensorValueResult;

  int sensorValue2 = analogRead(A1);
  float sensorValueResult2 = sensorValue2 * (5.0/1023.0);
  Analog[1] = sensorValueResult2;
 
  int sensorValue3 = analogRead(A2);
  float sensorValueResult3 = sensorValue3 * (5.0/1023.0);
  Analog[2] = sensorValueResult3;
 
  int sensorValue4 = analogRead(A3);
  float sensorValueResult4 = sensorValue4 * (5.0/1023.0);
  Analog[3] = sensorValueResult4;

  int sensorValue5 = analogRead(A4);
  float sensorValueResult5 = sensorValue5 * (5.0/1023.0);
  Analog[4] = sensorValueResult5;
  
  for(int i = 0; i < 5; i++)
  {
    Serial.print(Analog[i]);
    Serial.print(",");
  }
}

void BUTTONS()
{
  ButtonStateP2 = digitalRead(PushButton1);
  Digital[0] = ButtonStateP2;

  ButtonStateP3 = digitalRead(PushButton2);
  Digital[1] = ButtonStateP3;

  ButtonStateP4 = digitalRead(PushButton3);
  Digital[2] = ButtonStateP4;

  ButtonStateP5 = digitalRead(PushButton4);
  Digital[3] = ButtonStateP5;

  ButtonStateP6 = digitalRead(PushButton5);
  Digital[4] = ButtonStateP6;
  
  for(int j = 0; j < 5; j++)
  {
    Serial.print(Digital[j]);
    Serial.print(",");
  }
}

Code of the receiver circuit:

#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 */


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

int value_next;
int value_previous;
int value = 0;

int lastButtonState=0;
int lastButtonState2=0;

unsigned long LastReading = 0;
unsigned long LastReadingButton = 0;

unsigned long value_button_next = 0;
unsigned long value_button_previous = 0;

const int Buzzer = 8;

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

RF24 radio(pinCE, pinCSN);

const byte address[5] = "CANAL";

float Analog[5];
int Digital[5];

void setup()
{
  Serial.begin(9600); 
  radio.begin();
  radio.openReadingPipe(1, address);
  radio.startListening();
  
  lcd.begin(16,2);
  lcd.clear();

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

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

void MENU_BUTTONS()
{
  value_next = analogRead(next);
  value_previous = analogRead(previous);
  
  if(value_next != lastButtonState)
  {
    if(value_next >= 100)
    {
      if(millis() - value_button_next > 250)
      {
        value = value + 1;
        value_button_next = millis();
      }
    }
    
    if(value == 10)
    {
      value = 0;
    }
  }
  lastButtonState = value_next;
  
  if(value_previous != lastButtonState2)
  {  
    if(value_previous >= 100)
    {
      if(millis() - value_button_previous > 250)
      {
        value = value - 1;
        value_button_previous = millis();
      }
    }
  
    if(value == -1)
    {
      value = 9;
    }
  }
  lastButtonState2 = value_previous;

  if(millis() - LastReadingButton > 500)
  {
  if(value == 0)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 1");
    lcd.setCursor(0,1);
    lcd.print(Analog[0]);
  }

  if(value == 1)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 2");
    lcd.setCursor(0,1);
    lcd.print(Analog[1]);
  }

  if(value == 2)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 3");
    lcd.setCursor(0,1);
    lcd.print(Analog[2]);
  }

  if(value == 3)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 4");
    lcd.setCursor(0,1);
    lcd.print(Analog[3]);
  }
  
  if(value == 4)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 5");
    lcd.setCursor(0,1);
    lcd.print(Analog[4]);
  }

  if(value == 5)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 1");
    
    if(Digital[0] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }

  if(value == 6)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 2");
    
    if(Digital[1] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }

  if(value == 7)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 3");
    
    if(Digital[2] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }
  
  if(value == 8)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 4");
    
    if(Digital[3] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }
  
  if(value == 9)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 5");
    
    if(Digital[4] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }
  LastReadingButton = millis();
  }
}

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

Numbers going negative like that is often caused by a variable rolling over. Are all of your data types big enough to hold the highest number expected?

Arduino data types.

Don't send two separate wireless messages back to back like this as you have no guarantee that the receiver will get both messages.

bool ok = radio.write(&Analog, sizeof(Analog)) && radio.write(&Digital, sizeof(Digital));

Create a struct that holds all the values and just send one message - something like

struct myDataStruct {
   Analog[5];
   int Digital[5];
};

myDataStruct dataToSend;

Just make sure that the total size does not exceed 32 bytes. Note that you could send the analog values as ints and convert them to floats in the receiver program.

Populate the arrays like this

dataToSend.Analog[0] = sensorValueResult;
etc

then send the data with

bool ok = radio.write(&dataToSend, sizeof(dataToSend)) ;

...R

I already changed the code like you recommended, I didn't know what a "struct" was, so I had to do a little of research. I don't receive negative values anymore, although the receiver circuit loses the connection with the transmitter for a second every now and then, perhaps it's related to the fact I changed the interval from 1 second to 250 milliseconds. Here's the code modified

Transmitter:

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

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

RF24 radio(pinCE, pinCSN);

const byte address[5] = "CANAL";

const int PushButton1 = 2;
const int PushButton2 = 3;
const int PushButton3 = 4;
const int PushButton4 = 5;
const int PushButton5 = 6;

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

struct myDataStruct
{
  int Analog[5];
  int Digital[5];
};
myDataStruct dataToSend;

unsigned long LastReading = 0;

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

  pinMode(PB1,INPUT);
  pinMode(PB2,INPUT);
  pinMode(PB3,INPUT);
  pinMode(PB4,INPUT);
  pinMode(PB5,INPUT);
}
 
void loop()
{
  if(millis() - LastReading > 250)
  {
    bool ok = radio.write(&dataToSend,sizeof(dataToSend));
   
    if(ok)
    {
      POTENTIOMETERS();
      BUTTONS();
      Serial.println("");
    }
    else
    {
      Serial.println("DATA NOT SENT");
    }
    LastReading = millis();
  }
}

void POTENTIOMETERS()
{
  int sensorValue1 = analogRead(A0);
  dataToSend.Analog[0] = sensorValue1;

  int sensorValue2 = analogRead(A1);
  dataToSend.Analog[1] = sensorValue2;
 
  int sensorValue3 = analogRead(A2);
  dataToSend.Analog[2] = sensorValue3;
 
  int sensorValue4 = analogRead(A3);
  dataToSend.Analog[3] = sensorValue4;

  int sensorValue5 = analogRead(A4);
  dataToSend.Analog[4] = sensorValue5;
 
  for(int i = 0; i < 5; i++)
  {
    Serial.print(dataToSend.Analog[i]);
    Serial.print(",");
  }
}

void BUTTONS()
{
  ButtonStateP2 = digitalRead(PushButton1);
  dataToSend.Digital[0] = ButtonStateP2;

  ButtonStateP3 = digitalRead(PushButton2);
  dataToSend.Digital[1] = ButtonStateP3;

  ButtonStateP4 = digitalRead(PushButton3);
  dataToSend.Digital[2] = ButtonStateP4;

  ButtonStateP5 = digitalRead(PushButton4);
  dataToSend.Digital[3] = ButtonStateP5;

  ButtonStateP6 = digitalRead(PushButton5);
  dataToSend.Digital[4] = ButtonStateP6;
 
  for(int j = 0; j < 5; j++)
  {
    Serial.print(dataToSend.Digital[j]);
    Serial.print(",");
  }
}

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 */


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

int value_next;
int value_previous;
int value = 0;

int lastButtonState=0;
int lastButtonState2=0;

unsigned long LastReading = 0;
unsigned long LastReadingButton = 0;

unsigned long value_button_next = 0;
unsigned long value_button_previous = 0;

const int Buzzer = 8;

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

RF24 radio(pinCE, pinCSN);

const byte address[5] = "CANAL";

struct myDataStruct
{
  int Analog[5];
  int Digital[5];
};
myDataStruct dataToReceive;

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, address);
  radio.startListening();
 
  lcd.begin(16,2);
  lcd.clear();

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

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

void MENU_BUTTONS()
{
  value_next = analogRead(next);
  value_previous = analogRead(previous);
 
  if(value_next != lastButtonState)
  {
    if(value_next >= 100)
    {
      if(millis() - value_button_next > 250)
      {
        value = value + 1;
        value_button_next = millis();
      }
    }
   
    if(value == 10)
    {
      value = 0;
    }
  }
  lastButtonState = value_next;
 
  if(value_previous != lastButtonState2)
  { 
    if(value_previous >= 100)
    {
      if(millis() - value_button_previous > 250)
      {
        value = value - 1;
        value_button_previous = millis();
      }
    }
 
    if(value == -1)
    {
      value = 9;
    }
  }
  lastButtonState2 = value_previous;

  if(millis() - LastReadingButton > 500)
  {
  if(value == 0)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 1");
    lcd.setCursor(0,1);
    lcd.print(dataToReceive.Analog[0]);
  }

  if(value == 1)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 2");
    lcd.setCursor(0,1);
    lcd.print(dataToReceive.Analog[1]);
  }

  if(value == 2)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 3");
    lcd.setCursor(0,1);
    lcd.print(dataToReceive.Analog[2]);
  }

  if(value == 3)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 4");
    lcd.setCursor(0,1);
    lcd.print(dataToReceive.Analog[3]);
  }
 
  if(value == 4)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 5");
    lcd.setCursor(0,1);
    lcd.print(dataToReceive.Analog[4]);
  }

  if(value == 5)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 1");
   
    if(dataToReceive.Digital[0] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }

  if(value == 6)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 2");
   
    if(dataToReceive.Digital[1] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }

  if(value == 7)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 3");
   
    if(dataToReceive.Digital[2] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }
 
  if(value == 8)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 4");
   
    if(dataToReceive.Digital[3] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }
 
  if(value == 9)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 5");
   
    if(dataToReceive.Digital[4] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }
  LastReadingButton = millis();
  }
}

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

What Arduino board are you using?

Arduino UNO

OK, just checking. On a 32-bit processor your struct would be too large to transfer in a single packet. But, that's not the problem if you're using an 8-bit AVR.

Victor97XD:
although the receiver circuit loses the connection with the transmitter for a second every now and then,

There is not such thing as a connection that gets lost. The only time there is a connection between two nRF24 modules is for the few millisecs when an actual message is transmitted.

DO NOT put this in your receiver program as it is likely to get out of sync with the transmitter

if(millis()-LastReading > 250)

Your receiver should be checking for a new message as often as possible. Just do the message timing in the transmitter. Four times per second should be no problem.

...R
Simple nRF24L01+ Tutorial

Hi,
Have you got a 10uF capacitor across the power input pins of the NRF?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

I erased that line of code and now it works like a charm, although the buzzer on the receiver circuit beeps all the time now.

I suppose this happens because Arduino is checking the code constantly and the condition is fluctuating between true and false, so I had to delete it. The only purpose of this line was to make sure whether there was a connection with the transmitter or not.

else
  {
    Serial.println("NO DATA AVAILABLE");
    digitalWrite(Buzzer,HIGH);
  }

I modified the transmitter code to send data every 250 milliseconds to the receiver circuit just to see how fast the data could reflected on the LCD and a user interface I am developing for this project, everything looked good at first but after a few minutes the data started fluctuating in the serial monitor. I am not sure if this happened because of the time of transmission between both circuits.

Although the data keeps fluctuating every now and then even with a delay of four seconds between both circuits.

Here's my final code of both circuits:

Transmitter code:

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

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

RF24 radio(pinCE, pinCSN);

const byte address[5] = "CANAL";

const int PushButton1 = 2;
const int PushButton2 = 3;
const int PushButton3 = 4;
const int PushButton4 = 5;
const int PushButton5 = 6;

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

struct myDataStruct
{
  int Analog[5];
  int Digital[5];
};
myDataStruct dataToSend;

unsigned long LastReading = 0;

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

  pinMode(PB1,INPUT);
  pinMode(PB2,INPUT);
  pinMode(PB3,INPUT);
  pinMode(PB4,INPUT);
  pinMode(PB5,INPUT);
}
 
void loop()
{
  if(millis() - LastReading > 2000)
  {
    bool ok = radio.write(&dataToSend,sizeof(dataToSend));
   
    if(ok)
    {
      POTENTIOMETERS();
      BUTTONS();
      Serial.println("");
    }
    else
    {
      Serial.println("DATA NOT SENT");
    }
    LastReading = millis();
  }
}

void POTENTIOMETERS()
{
  int sensorValue1 = analogRead(A0);
  dataToSend.Analog[0] = sensorValue1;

  int sensorValue2 = analogRead(A1);
  dataToSend.Analog[1] = sensorValue2;
 
  int sensorValue3 = analogRead(A2);
  dataToSend.Analog[2] = sensorValue3;
 
  int sensorValue4 = analogRead(A3);
  dataToSend.Analog[3] = sensorValue4;

  int sensorValue5 = analogRead(A4);
  dataToSend.Analog[4] = sensorValue5;
 
  for(int i = 0; i < 5; i++)
  {
    Serial.print(dataToSend.Analog[i]);
    Serial.print(",");
  }
}

void BUTTONS()
{
  ButtonStateP2 = digitalRead(PushButton1);
  dataToSend.Digital[0] = ButtonStateP2;

  ButtonStateP3 = digitalRead(PushButton2);
  dataToSend.Digital[1] = ButtonStateP3;

  ButtonStateP4 = digitalRead(PushButton3);
  dataToSend.Digital[2] = ButtonStateP4;

  ButtonStateP5 = digitalRead(PushButton4);
  dataToSend.Digital[3] = ButtonStateP5;

  ButtonStateP6 = digitalRead(PushButton5);
  dataToSend.Digital[4] = ButtonStateP6;
 
  for(int j = 0; j < 5; j++)
  {
    Serial.print(dataToSend.Digital[j]);
    Serial.print(",");
  }
}

Receiver code:

#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 */


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

int value_next;
int value_previous;
int value = 0;

int lastButtonState=0;
int lastButtonState2=0;

unsigned long LastReading = 0;
unsigned long LastReadingButton = 0;

unsigned long value_button_next = 0;
unsigned long value_button_previous = 0;

const int Buzzer = 8;

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

RF24 radio(pinCE, pinCSN);

const byte address[5] = "CANAL";

float AnalogConv[5];

struct myDataStruct
{
  int Analog[5];
  int Digital[5];
};
myDataStruct dataToReceive;

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, address);
  radio.startListening();
 
  lcd.begin(16,2);
  lcd.clear();

  pinMode(Buzzer,OUTPUT);
}
 
void loop()
{
  if (radio.available())
  {   
    radio.read(&dataToReceive,sizeof(dataToReceive));

    CONVERSIONS();
     
    for(int i = 0; i < 5; i++)
    {
      Serial.print(AnalogConv[i]);
      Serial.print(",");
    }

    for(int j = 0; j < 5; j++)
    {
      Serial.print(dataToReceive.Digital[j]);
      Serial.print(",");
    }
    Serial.println("");
    
    ALARM();
  }
  MENU_BUTTONS();
  
  /*else
  {
    Serial.println("NO DATA AVAILABLE");
    digitalWrite(Buzzer,HIGH);
  }*/
}
  
void MENU_BUTTONS()
{
  value_next = analogRead(next);
  value_previous = analogRead(previous);
 
  if(value_next != lastButtonState)
  {
    if(value_next >= 300)
    {
      if(millis() - value_button_next > 250)
      {
        value = value + 1;
        value_button_next = millis();
      }
    }
   
    if(value == 10)
    {
      value = 0;
    }
  }
  lastButtonState = value_next;
 
  if(value_previous != lastButtonState2)
  { 
    if(value_previous >= 300)
    {
      if(millis() - value_button_previous > 250)
      {
        value = value - 1;
        value_button_previous = millis();
      }
    }
 
    if(value == -1)
    {
      value = 9;
    }
  }
  lastButtonState2 = value_previous;

  if(millis() - LastReadingButton > 500)
  {
  if(value == 0)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 1");
    lcd.setCursor(0,1);
    lcd.print(AnalogConv[0]);
  }

  if(value == 1)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 2");
    lcd.setCursor(0,1);
    lcd.print(AnalogConv[1]);
  }

  if(value == 2)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 3");
    lcd.setCursor(0,1);
    lcd.print(AnalogConv[2]);
  }

  if(value == 3)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 4");
    lcd.setCursor(0,1);
    lcd.print(AnalogConv[3]);
  }
 
  if(value == 4)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("POT 5");
    lcd.setCursor(0,1);
    lcd.print(AnalogConv[4]);
  }

  if(value == 5)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 1");
   
    if(dataToReceive.Digital[0] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }

  if(value == 6)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 2");
   
    if(dataToReceive.Digital[1] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }

  if(value == 7)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 3");
   
    if(dataToReceive.Digital[2] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }
 
  if(value == 8)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 4");
   
    if(dataToReceive.Digital[3] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }
 
  if(value == 9)
  {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("BUTTON 5");
   
    if(dataToReceive.Digital[4] == 1)
    {
      lcd.setCursor(0,1);
      lcd.print("ON");
    }
    else
    {
      lcd.setCursor(0,1);
      lcd.print("OFF");
    }
  }
  LastReadingButton = millis();
  }
}

void CONVERSIONS()
{
  AnalogConv[0] = dataToReceive.Analog[0] * (5.0 / 1023.0);
  AnalogConv[1] = dataToReceive.Analog[1] * (5.0 / 1023.0);
  AnalogConv[2] = dataToReceive.Analog[2] * (5.0 / 1023.0);
  AnalogConv[3] = dataToReceive.Analog[3] * (5.0 / 1023.0);
  AnalogConv[4] = dataToReceive.Analog[4] * (5.0 / 1023.0);
}


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

TomGeorge:
Hi,
Have you got a 10uF capacitor across the power input pins of the NRF?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

I did place capacitors between the power inputs of both circuits, 10uF to be exact.

Here are the diagrams of both pictures

I forgot to add the capacitors in the diagrams

How to post images
How to post an image.
Another page on posting images.

Not sure why the receiver shows me wrong values sometimes, this happens every now and then and after a few minutes it corrects itself.

Victor97XD:
I erased that line of code and now it works like a charm, although the buzzer on the receiver circuit beeps all the time now.

I suppose this happens because Arduino is checking the code constantly and the condition is fluctuating between true and false, so I had to delete it. The only purpose of this line was to make sure whether there was a connection with the transmitter or not.

else

{
    Serial.println("NO DATA AVAILABLE");
    digitalWrite(Buzzer,HIGH);
  }

Just omit that code completely. It is pointless checking if there is no data available because that is the normal condition and it will be true 99% of the time.

...R