NRF24L01 module doesn't work

I have made a program to control a servo with a potentiometer. The potentiometer and the servo can communicate through the NRF24L01 module. But it doesn’t work.

This is the code from te master:

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

RF24 radio(7, 8); // CE, CSN

const byte address[6] = {"Node1"};
const int potpin = A0;

int val = 0;

void setup() {

radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);

radio.write(&val, sizeof(val));
delay(5);
}

And this is the code from the receiver:

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

Servo myservo;
RF24 radio(7, 8); // CE, CSN
const byte address[6] = {"Node1"};
const int servo = 9;
int val = 0;

void setup()
{
Serial.begin(9600);
myservo.attach(servo);

radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop()
{
delay(5);
radio.startListening();

if ( radio.available()) {
while (radio.available()) {
radio.read(&val, sizeof(val));
myservo.write(val);
Serial.print("Servo position = ");
Serial.println(val);
}
}
}

Is the code wrong or is it something else?
sorry for my bad English.

If you are not good in englisch use google-translate
Write your detailed message in your native language and let do googletranslate do the translation.
The grammar won't be brilliant but it will be easy to understand. And that is the important thing.

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

You can re-edit your first posting.

You should a description what you can watach what your software is doing.

For debuging purposes you should add serial output to see what is going on in your code.
If you don't know how to add serial output just ask
best regards Stefan

I set up 2 Unos with rf24 radios, sender with pot and receiver with servo. I only changed pins (CE, CSN, servo pin) to test your code. It works fine. I can adjust the position of the servo with the potentiometer.

How are the radio modules powered? The most likely cause of problems with rf24 radios is lack of current capability of the power supply. I use homemade adapters like these with great success.

Carefully check your wiring.

Check out Robin2's simple rf24 tutorial. He discusses the power problem and some remedies. His tutorial is what I used to get my radios to work. There is a sketch to test the physical wired connection between the radio module and its processor (see reply #30).

1 Like

Posting a schematic of how you wired it, not a frizzy picture will help us help you. I suspect groundFungus is correct the schematic will tell all.

this is how I wired it.

Hi.

Sorry that is what is called a fritzy image.

Have you got a 10uF or 47uF capacitor across 3V3 and gnd AT the NRF pins?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

You should add the capacitor or larger 100 uF as @TomGeorge reminds you.

Do not expect to power the servo from the Arduino 5 volt pin. Use an external power source with more than adequate current. Do you know what the current requirement of your servo is?

Get a simple set of programs you had nothing to do with writing working. No potentiometer, no servo. Test your wiring and NRFs this way. If your wiring is bad, or they broke, you are out of luck and didn't even know why.

If you want to skip those steps, at least:

Remove the servo from you circuit and see if the Serial.print line on the servo side is producing plausible values.

Until you can see plausible values for myservo.write(…), it is a waste of time to actually add the servo.

HTH

a7

This are the photos of the master arduino:


I hope that this photos are better.
Thank jou for helping

And this are the photos of de reciever arduino:

mart,

if you take pictures then on the picture must be visible which wire starts where and ends where
in one and the same picture. The letters on the connectors must be readable.

The alternative is a hand-drawn schematic.

The NRF24L-module has a documentation where each and every pin is named.
With your fritzing picture and your smartphone-pictures you have posted yet
you force your potential users to look up the documentation which pin is what.

This is work that you have to do. The hand-drawn connecting lines between the NRF24 and the arduino can wiggle up / down / left / right as much as they want as long it is easy to see which arduino-IO-pin-number is connected to pin-number of the NRF24

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

A very effictive way to anaylse what is really going on is to add Serial.print-commands
to see in the serial monitor what is really going on in your code.

Did you do some basic tests?

best regards Stefan

How should I do a basic test?
tank you for helping.

I would suggest carefully reading and following Robin2's simple rf24 tutorial. That tutorial was instrumental in me getting my rf24 radios to work. Get those basic sketches to work.

Run the CheckConnection.ino sketch in reply #30 and post the results.

using codes that are well known to work
this tutorial has basic codes that have serial-output that will give you feedback what is working and what not

For using it by copy & paste you have to change your wiring
to use the hardware-SPI-Io-Pins as shown in this tutorial

There is a basic code that sends a fixed text
"Message 0"

best regards Stefan