NRF24L01 not working as intended

im trying to make a remote control using 3 button that is controling servo and LED.i have this problem for quite a while now where the nrf24l01 just not working it just dont transmit and recieve anything. i use uno both for transmitter and reciever

transmitter

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

const uint64_t pipe = 0xE8E8F0F0E1LL;
int right = 2;
int left = 3;
int go = 4;
int State = 0;
RF24 radio(7,8); // CE, CSN pins

void setup() {
  Serial.begin(9600);
  pinMode(right,INPUT);
  pinMode(left,INPUT);
  pinMode(go,INPUT);
  digitalWrite(10,HIGH);
  radio.begin();
  radio.setChannel(108);
  radio.openWritingPipe(pipe);
  radio.stopListening();
}

void loop() {
  State = 0;
  if(digitalRead(right) == HIGH)
  {
    State = 10;
  }

  if(digitalRead(left) == HIGH)
  {
    State = 20;
  }
  
  if(digitalRead(go) == HIGH)
  {
    State = 30;
  }

  radio.write(&State, sizeof(State));
  Serial.println(State);
}

reciever

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

const uint64_t pipe = 0xE8E8F0F0E1LL;
bool yes_or_no = false;
int pos = 90;
int State = 0;
int CE = 7;
int CSN = 8;
RF24 radio(CE,CSN); // CE, CSN pins
Servo servo;

void setup()
{
  pinMode(3,OUTPUT);
  pinMode(2,INPUT);
  Serial.begin(9600);
  digitalWrite(10,HIGH);
  radio.begin();
  radio.setChannel(108);
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  servo.attach(6);
  servo.write(pos);
}

void loop()
{
  if(radio.available())
  {
    radio.read(&State, sizeof(State));
  }

  if(State == 10)
  {
    for(pos = 90; pos < 181; pos++)
    {
      servo.write(pos);
    }
    if(pos == 180)
    {
      pos = 90;
    }
  }

  if(State == 20)
  {
    for(pos = 90; pos > 0; pos--)
    {
      servo.write(pos);
    }
    if(pos == 0)
    {
      pos = 90;
    }
  }

  if(State == 30 && digitalRead(2) == LOW)
  {
    if(yes_or_no == true)
    {
      digitalWrite(3,HIGH);
      yes_or_no = false;
    }
    else
    {
      digitalWrite(3,LOW);
      yes_or_no = true;
    }
  }

  Serial.println(State);
}

How do you have everything connected; i.e. can you post a schematic of both the transmitter and receiver systems, and photos of both showing how it's all wired together?

Your transmitter code is blasting data into the air permanently as fast as it'll go. I wouldn't do that.

Read your buttons/inputs. Only send data if a button as changed and every 100ms or so if a button is being held. Your transmitter code will have to be rebuilt pretty much from the ground up to accomplish this.

However, before doing so, set up an easy test where you have the transmitter and the receiver on a table and the only thing the transmitter does, is send the same package of data to the receiver every second or so. Nothing else; no buttons, no nothing. The receiver can Serial.print the data to the Serial monitor to verify it has received it. Work on this setup until the receiver reliably receives the data. Then move back to the button thing.

1 Like

It was not designed to receive what it is transmitting. Post an annotated schematic showing exactly you have wired it, including all power, ground, power sources and note any leads over 10"25cm. What I think you are trying to describe has turned out to be a hardware problem most of the time. @rsmls is also requesting this information. Be sure you have at least a meter between the transmitter and receiver.

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