0

I've been trying on and off to try and get my nrf24l01's working for some time and they never seem to work. Right now I'm just trying to turn a led on and off over the radio and it isn't working.

Here's the code for the transmitter

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

#define button 5
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
boolean buttonState = 0;
void setup() {
  pinMode(5, INPUT_PULLUP);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}
void loop() {

  buttonState = digitalRead(button);
  radio.write(&buttonState, sizeof(buttonState));
}

And here's the code for the receiver

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

int led = 2;
RF24 radio(7, 8); // CE, CSN
boolean buttonState = 0;
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}
void loop() {
 radio.startListening();
  while (!radio.available());
  radio.read(&buttonState, sizeof(buttonState));
  if (buttonState == HIGH) 
  {
    digitalWrite(led, HIGH);
  }
  else 
  {
    digitalWrite(led, LOW);
  }
}

I have the voltage regulator which steps the 5v arduino to 3.3 to the chip so I don't think not having a capacitor (what others recommended) is a problem. I have both radio chips hooked up to arduino nanos.

For the transmitter and receiver I have CE=7,CSN=8, SCK=13, MO=11, and MI=12

I also know that my led is working and the code for my button is working. Is there a problem with my code or is there a chance that my chips are broken even if im using a voltage regulator

  • The capacitor is not used to regulate the voltage per say, it is used to make sure the supplied voltage is 'clean' when the radio transmits it draws 'a lot' of current real fast, and if the regulator cannot keep up with that spike, the voltage drops. I have found that using a capacitor with these radios clears up some issues. – Chad G Apr 12 '18 at 15:16
0

Pretty sure your issue is you're not using the capacitor. I used a 10uF capacitor and it works great.

enter image description here

You put the capacitor on pins 1 and 2, make sure ground is on pin 1.

The capacitor is to make sure there is enough power being supplied when it needs it. Without the capacitor it causes unreliable communication.

If you have other issues this is a great summary video on using the NRF24L01+ transceivers: https://www.youtube.com/watch?v=kDTJULtFPgE

| improve this answer | |
0

It is not easy to find the problem remotely. Here is what I would do:

  1. My first problem have always been connections. I gave up using breadboards and other connectors. Use soldering instead to be sure your circuit is properly connected.

  2. Add some Serial.println() in both codes to see what exactly is going to be sent, and what has been received.

  3. On the sender code, add a delay(100) to the loop. That would give the module buffers a chance to process.

  4. You can improve it more by checking for the button value you read with the old value, and only send the value if the state has changed.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.