NRF24l01+ only work after reset

my NRF24l01+ only work after reseting arduino and it can only transmit and recieve 1 data i have this problem for days and i dont know how to fix it, here is the code

transmitter

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

RF24 radio(7,8);

const uint64_t pipe = 0xE8E8F0F0E1LL;

int value;

void setup() {
  // put your setup code here, to run once:
  digitalWrite(10,HIGH);
  radio.begin();
  radio.setChannel(100);
  radio.openWritingPipe(pipe);
  radio.stopListening();
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  value = analogRead(A0);
  Serial.println(value);
  radio.write(&value, sizeof(int)); 
}

reciever

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

RF24 radio(7,8);

const uint64_t pipe = 0xE8E8F0F0E1LL;
int pos;
int hold;
Servo servo;

void setup() {
  // put your setup code here, to run once:
  digitalWrite(10,HIGH);
  radio.begin();
  radio.setChannel(100);
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  servo.attach(3);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(radio.available())
  {
    radio.read(&hold, sizeof(hold));
  }

  pos = map(hold, 0, 1023, 0, 180);
  servo.write(pos);
}

what im trying to make is a potentiometer controling a servo for steering my RC car, i use arduino uno for both the transmitter and reciever.

Just off the top of my head:

The sketch is not checking any error returns from any of the RF24 object's methods. It could be telling you that there are problems, but your code will never know.

The transmitter sketch is flooding the transmitter in its loop() function. That's probably not optimal.

You're using at least one deprecated method in both sketches. Check for newer versions of openWritingPipe and openReadingPipe.

Without seeing a schematic, that's all I've got.

1 Like

i have an update the NRF works fine if i didnt connect the servo to arduino

How are you powering the servo? Please tell me you're not using the Arduino's 5V pin.

yeah i use the 5v pin because i have no battery laying around

And there's your problem. Even a small servo draws more current than the 5V pin can supply. The servo needs a dedicated external 5V supply.

1 Like

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