How do you wirelessly control a 360 degree servo motor with a potentiometer using nRF24L01+ chips between 2 Arduino Nanos?

I've seen a few videos on how to program this via an Arduino Uno, but the Nano doesn't have 13 digital pins and all of them connected the SCK pin on the nRF24L01+ chip to the 13th digital pin. I am completely new to Arduino and coding in general, so I don't even know where to start. If anyone can help me out or even code this for me, that would be amazing.

Maybe slow down, and leave the stream-of-conciousness style of posting behind?

Now, you were saying . . ?

The Nano has the same number of digital pins as the Uno so I do not understand what the problem is, nor do I understand what it is that you want to do

Here is tested code to read a pot, transmit the reading via rf24, receive the reading and send the reading to a servo. This code has been tested on Unos. This code uses example code from Robin2's simple rf24 tutorial.

Is this what you want?

Transmit

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

const byte CE_PIN = 9;
const byte CSN_PIN = 10;
const byte potPin = A0;

const byte slaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

struct Payload
{
  int potValue;  
}payload;

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 200; // send 5 times per second

void setup()
{
   Serial.begin(115200);
   Serial.println("SimpleTx Starting");
      
   radio.begin();
   radio.setChannel(76);  //76 library default
   //RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
   radio.setPALevel(RF24_PA_HIGH);
   radio.setDataRate( RF24_250KBPS );
   radio.setRetries(3, 5); // delay, count
   radio.openWritingPipe(slaveAddress);
}

void loop()
{
   currentMillis = millis();
   if (currentMillis - prevMillis >= txIntervalMillis)
   {
      send();
      Serial.print("pot value = ");
      Serial.println( payload.potValue);
    
      prevMillis = millis();
   }
}

//====================

void send()
{
   payload.potValue = analogRead(potPin);
   radio.write( &payload, sizeof(payload) );
}

Receive

// SimpleRx - the slave or the receiver

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

const byte servoPin = 4;
const byte CE_PIN = 9;
const byte CSN_PIN = 10;

const byte thisSlaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};

RF24 radio(CE_PIN, CSN_PIN);
Servo servo;

struct Payload
{
   int potValue;
} payload;

bool newData = false;

//===========

void setup()
{
   Serial.begin(115200);
   Serial.println("SimpleRx Starting");

   radio.begin();
   radio.setChannel(76);  //76 library default
   //RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
   radio.setPALevel(RF24_PA_HIGH);
   radio.setDataRate( RF24_250KBPS );
   radio.openReadingPipe(1, thisSlaveAddress);
   radio.startListening();
   servo.attach(servoPin);
}

//=============

void loop()
{
   getData();
   showData();
   actOnData();
}

//==============

void getData()
{
   if ( radio.available() )
   {
      radio.read( &payload, sizeof(payload) );
      newData = true;
   }
}

void showData()
{
   if (newData == true)
   {
      Serial.print("Data received >> ");
      Serial.print("pot value = ");
      Serial.println( payload.potValue);
      //newData = false;
   }
}

void actOnData()
{
   servo.write(map(payload.potValue, 0, 1023, 10, 170));
   newData = false;
}

My Nano's only have 12 digital pins, and basically, I wanna be able to control the servo motor wirelessly with a potentiometer.

This has the same problem as the other codes I used. My Arduino Nano's don't have a 13th digital pin and if you look at the wiring diagram for that code, you can see that the SCK pin on the nRF24L01 chip is plugged into the 13th digital pin on the Arduino Uno. I'm very new to this stuff, but I don't see a place in the code to change which digital pin it reads.

Nevermind, I didn't know that the 13th digital pin was on the other side of the board

Nanos have digital pins numbered 0 to 13 (14 pins) and in addition the pins labelled A0 to A5 (6 pins) can be used as digital pins.

That makes a total of 20 digital pins, or 18 if you avoid using pins 0 and 1 because they are used by the Serial interface

That is actually the 14th digital pin counting from zero

Okay, so that code partially worked, the only problem is that it's not receiving the pot values that the transmitter is sending out. All it says in the receiver serial monitor is "Data Received >> pot value received = 0" so it's not turning the servo motor. The transmitter serial monitor says "pot value = ( 0-1023)". I think there might be a problem with the transmitter sending out the values to the receiver. I don't really know where to start when trying to fix this. Do you have any idea's on what the problem is?

I know that the code works. It has been tested with real hardware.

If you read and, closely, follow Robin2's simple rf24 tutorial you should be able to get them working. That tutorial sure helped me. 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 );

I did the CheckConnection.ino test and I didn't have a bunch of 0x00 or 0xFF, so I think the connection from the nRF24L01 to the Arduino was fine, but the receiver is still not getting the values

This is what it shows me when I do the CheckConnection.ino

Transmitter:

20:12:47.337 -> CheckConnection Starting
20:12:47.337 ->
20:12:47.337 -> FIRST WITH THE DEFAULT ADDRESSES after power on
20:12:47.383 -> Note that RF24 does NOT reset when Arduino resets - only when power is removed
20:12:47.476 -> If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
20:12:47.569 -> communicating with the nRF24
20:12:47.614 ->
20:12:47.614 -> SPI Speedz = 10 Mhz
20:12:47.614 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
20:12:47.662 -> RX_ADDR_P0-1 = 0xe7e7e7e7e7 0x4141417852
20:12:47.708 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
20:12:47.754 -> TX_ADDR = 0xe7e7e7e7e7
20:12:47.801 -> RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
20:12:47.847 -> EN_AA = 0x3f
20:12:47.847 -> EN_RXADDR = 0x03
20:12:47.893 -> RF_CH = 0x4c
20:12:47.893 -> RF_SETUP = 0x07
20:12:47.893 -> CONFIG = 0x0e
20:12:47.939 -> DYNPD/FEATURE = 0x00 0x00
20:12:47.939 -> Data Rate = 1 MBPS
20:12:47.986 -> Model = nRF24L01+
20:12:47.986 -> CRC Length = 16 bits
20:12:48.032 -> PA Power = PA_MAX
20:12:48.032 -> ARC = 0
20:12:48.032 ->
20:12:48.032 ->
20:12:48.032 -> AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1
20:12:48.126 -> and 250KBPS data rate
20:12:48.126 ->
20:12:48.126 -> SPI Speedz = 10 Mhz
20:12:48.172 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
20:12:48.219 -> RX_ADDR_P0-1 = 0xe7e7e7e7e7 0x4141417852
20:12:48.265 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
20:12:48.312 -> TX_ADDR = 0xe7e7e7e7e7
20:12:48.312 -> RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
20:12:48.358 -> EN_AA = 0x3f
20:12:48.406 -> EN_RXADDR = 0x03
20:12:48.406 -> RF_CH = 0x4c
20:12:48.406 -> RF_SETUP = 0x27
20:12:48.452 -> CONFIG = 0x0e
20:12:48.452 -> DYNPD/FEATURE = 0x00 0x00
20:12:48.499 -> Data Rate = 250 KBPS
20:12:48.499 -> Model = nRF24L01+
20:12:48.499 -> CRC Length = 16 bits
20:12:48.546 -> PA Power = PA_MAX
20:12:48.546 -> ARC = 0
20:12:48.593 ->
20:12:48.593 ->

Reciever:

20:15:26.190 -> CheckConnection Starting
20:15:26.237 ->
20:15:26.237 -> FIRST WITH THE DEFAULT ADDRESSES after power on
20:15:26.283 -> Note that RF24 does NOT reset when Arduino resets - only when power is removed
20:15:26.376 -> If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
20:15:26.423 -> communicating with the nRF24
20:15:26.469 ->
20:15:26.469 -> SPI Speedz = 10 Mhz
20:15:26.516 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
20:15:26.564 -> RX_ADDR_P0-1 = 0xe7e7e7e7e7 0x4141417852
20:15:26.618 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
20:15:26.657 -> TX_ADDR = 0xe7e7e7e7e7
20:15:26.657 -> RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
20:15:26.702 -> EN_AA = 0x3f
20:15:26.749 -> EN_RXADDR = 0x03
20:15:26.749 -> RF_CH = 0x4c
20:15:26.749 -> RF_SETUP = 0x07
20:15:26.796 -> CONFIG = 0x0e
20:15:26.796 -> DYNPD/FEATURE = 0x00 0x00
20:15:26.842 -> Data Rate = 1 MBPS
20:15:26.842 -> Model = nRF24L01+
20:15:26.889 -> CRC Length = 16 bits
20:15:26.889 -> PA Power = PA_MAX
20:15:26.937 -> ARC = 0
20:15:26.937 ->
20:15:26.937 ->
20:15:26.937 -> AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1
20:15:26.982 -> and 250KBPS data rate
20:15:27.030 ->
20:15:27.030 -> SPI Speedz = 10 Mhz
20:15:27.030 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
20:15:27.076 -> RX_ADDR_P0-1 = 0xe7e7e7e7e7 0x4141417852
20:15:27.124 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
20:15:27.171 -> TX_ADDR = 0xe7e7e7e7e7
20:15:27.217 -> RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
20:15:27.263 -> EN_AA = 0x3f
20:15:27.263 -> EN_RXADDR = 0x03
20:15:27.263 -> RF_CH = 0x4c
20:15:27.311 -> RF_SETUP = 0x27
20:15:27.311 -> CONFIG = 0x0e
20:15:27.311 -> DYNPD/FEATURE = 0x00 0x00
20:15:27.358 -> Data Rate = 250 KBPS
20:15:27.404 -> Model = nRF24L01+
20:15:27.404 -> CRC Length = 16 bits
20:15:27.404 -> PA Power = PA_MAX
20:15:27.451 -> ARC = 0
20:15:27.451 ->
20:15:27.451 ->

Looks OK to me.

How are the radios powered?

They're powered through the 5V pin on the Arduino, but they're connected to a regulator adapter like these: Amazon.com

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