Transmitter/ Receiver using nRF24L01+

I am using nRF24L01+ with two Arduino Nanos, one receives analog input and sends the data over to the second Arduino to display on a 20X4 LCD display, but it seems that nothing is being sent on even received as I tried to print the input on the first Arduino on the serial monitor but I got nothing.
is there a problem with my code or the logic used here?
Thanks in advance for the help :slight_smile:

Below is my modified codes from HowToMechatronics

Transmitter code

/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//Define LSD Inputs
float PosLSD = A0;
float NegLSD = A1;
//Define period Inputs
float PosPer = A6;
float NegPer = A7;
//Define Reg Rod position Input
float RegRod = A2;

struct Data_Package
{
  //Setup analog inputs
float PLSD = analogRead(PosLSD);
float NLSD = analogRead(NegLSD);
float PPer = analogRead(PosPer);
float NPer = analogRead(NegPer);
float RRod = analogRead(RegRod);
};
Data_Package data;

//Setup tramitter pins and channel
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001"; //channel

void setup() 
{
   Serial.begin(9600);

//Setup the transmitter
  
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening();
}
//Send the signal
void loop() {
  // Send the whole data from the structure to the receiver
  radio.write(&data, sizeof(Data_Package));
    Serial.print("a: + ");
  Serial.print(data.PLSD);
  Serial.print(" b: - ");
  Serial.print(data.NLSD);
  Serial.print(" c: + ");
  Serial.print(data.PPer);
  Serial.print(" d: - ");
  Serial.print(data.NPer);
  Serial.print(" e:  ");
  Serial.print(data.RRod);
  delay(2000);
}

Receiver Code

/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/

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

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

struct Data_Package
{

float PLSD;
float NLSD;
float PPer;
float NPer;
float RRod;
};
Data_Package data;

//Setup tramitter pins and channel
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001"; //channel

void setup() 
{
   Serial.begin(9600);

//Setup the transmitter
  lcd.begin(20,4);  
  radio.begin();
  radio.openReadingPipe(0,address);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening();
}
//Send the signal
void loop() 
{ 
  // Check whether there is data to be received
  if (radio.available()) 
  {
    radio.read(&data, sizeof(Data_Package)); // Read the whole data and store it into the 'data' structure
  }
 
  lcd.setCursor(0,0);
  lcd.print("PosLSD +");
  lcd.setCursor(9,0);
  lcd.print(data.PLSD,DEC);

  lcd.setCursor(0,1);
  lcd.print("NegLSD -");
  lcd.setCursor(9,1);
  lcd.print(data.NLSD,DEC);

  lcd.setCursor(0,2);
  lcd.print("PosPer +");
  lcd.setCursor(9,2);
  lcd.print(data.PPer,DEC);

  lcd.setCursor(0,3);
  lcd.print("NegPer +");
  lcd.setCursor(9,3);
  lcd.print(data.NPer,DEC);


  Serial.print("a: + ");
  Serial.print(data.PLSD);
  Serial.print(" b: - ");
  Serial.print(data.NLSD);
  Serial.print(" c: + ");
  Serial.print(data.PPer);
  Serial.print(" d: - ");
  Serial.print(data.NPer);
  Serial.print(" e:  ");
  Serial.print(data.RRod);
  delay(2000);
}

If you read and, closely, follow Robin2's simple rf24 tutorial you should be able to get them working. That tutorial sure helped me. The code in the examples has been proven to work many many times. If it does not work for you, there is likely a hardware problem.

Run the CheckConnection.ino (look in reply #30) to verify the physical wiring between the radio module and its processor (Arduino).

Make sure the rf24 power supply can provide enough current. This is especially true for the high power (external antenna) modules. I use homemade adapters like these. They are powered by 5V and have a 3.3V regulator on the board. Robin2 also has suggested trying with a 2 AA cell battery pack.

If using the high powered radios make sure to separate them by a few meters. They may not work too close together. Try the lower power settings.

Reset the radios by cycling power to them after uploading new code. I have found that to help. They do not reset with the Arduino.

Switch to 1MB data rate to catch the not so cloned clones.
radio.setDataRate( RF24_1MBPS );

Post a diagram showing your wiring.

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