Wireless Servo Control With Arduino

by keysdapp in Circuits > Arduino

31 Views, 1 Favorites, 0 Comments

Wireless Servo Control With Arduino

Servos working with joystick

NOTE: Some sections of this Instructable contain code blocks that don't load properly until you scroll to the end of the page. Try doing that and scrolling back up before reading it.


In this Instructable, we’ll be showing you how to set up a basic wireless communication system using an Arduino (Uno or Nano) and the nRF24L01 (henceforth called RF24) transceiver modules. When we first tried to work with these modules, we ran into several challenges with wiring and coding, as many tutorials didn’t explain the process clearly and in depth. That’s why we decided to share my experience and make it easier for you! Most guides focus on complex setups, but in this tutorial, we’ll keep it simple by showing you how to:

  1. Wire the RF24 module to your Arduino board correctly.
  2. Code a basic transmitter and receiver system using the RF24 library.
  3. Enable wireless communication between two Arduino boards for sending and receiving data.
  4. Add in data sources and destinations, such as a joystick and servos.

By the end of this Instructable, you'll be able to set up a system to send a simple message and be able to control servos remotely. Let’s dive in!

Supplies

PXL_20250407_170955210.jpg
  1. 2x Arduino boards (UNO or NANO)
  2. 2x nRF24L01 Bluetooth Modules
  3. Jumper wires (M to F)
  4. Computer with Arduino IDE installed
  5. 2 Micro Servos
  6. 2 Potentiometers

Wiring the RF24 Transmitter and Receiver

wiring.png

Here is a circuit diagram that shows how to properly wire the RF24. The same wiring is used for both the transmitter and receiver.

Wiring the Radios

jsjej.png

Here is a table that explains how to wire you RF24 transmitter and receiver. The table explains where each RF24 pin connects to the Arduino pins. It also explains the function of each pin and explains what it does.

Wiring Potentiometers to Transmitter

Screenshot 2025-04-08 102241.png
Screenshot 2025-04-08 111001.png

Here is a wiring diagram of how to wire potentiometers to the arduino using your transmitter RF24. On the right is a table that explains where to wire each potentiometer pin and explains what each pin is used for. To wire the RF24 follow steps 1 and 2.

Wiring Servos to Receiver

Screenshot 2025-04-10 105750.png
Screenshot 2025-04-10 110658.png

Here is a diagram of how to wire potentiometers to the arduino using your receiver RF24. On the right is a table that explains how to wire the servo and which pins to wire it to. To wire the RF24, follow steps 1 and 2.

Programming a Hello World Transmitter

This code uses the 1.4.11 version of the RF24 library. It is unlikely that the code will change much in future updates, so using a different version will rarely be a source of issues, but is still something to keep in mind.

Transmitter

First, let’s program the transmitter. We’ll need to import the necessary packages first:

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

Next, we can set our pin and address constants:

const uint8_t CSN_PIN = 8;
const uint8_t CE_PIN = 9;
const byte ADDR[] = "00001";

The CE_PIN and CSN_PIN constants correspond to the digital pins you plugged the RF24 into. The ADDR constant must remain the same on the receiver for the devices to talk to each other.

Now we can instantiate and set up our radio:

RF24 radio(CE_PIN, CSN_PIN);

void setup()
{
  radio.begin();
  radio.setPALevel(RF24_PA_LOW); // Set power level to low to prevent heating. NOTE: Reduces range.
  radio.openWritingPipe(ADDR);
  radio.stopListening();
}

The setPALevel method is optional, but during testing we found that we didn’t need the range provided by the high-power mode.

Next, let’s finish the Hello World example by sending a message every second:

const char DATA[] = "Hello World!";
void loop()
{
  radio.write(&DATA, sizeof(DATA));

  delay(1000);
}

Receiver

The receiver setup is very similar:

#include <RF24.h>
#include <SPI.h>
const uint8_t CSN_PIN = 8;
const uint8_t CE_PIN = 9;
const byte ADDR[] = "00001";
RF24 radio(CE_PIN, CSN_PIN);

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.setPALevel(RF24_PA_LOW);
  radio.openReadingPipe(0, ADDR); // difference begins here
  radio.startListening();
}

The only difference is that you need to open a reading pipe and start to listen instead of opening a writing pipe and stop listening. We also set up the Serial so that we can see the data that is being received.

As for receiving the message and printing it out, the library also makes it very easy:

void loop()
{
  char data[32] = "";

  radio.read(&data, sizeof(data));
  Serial.println(data);
}

And just like that, we have our two Arduinos communicating wirelessly!

Programming

Transmitter

Adding a data source (here, a joystick) is ridiculously easy. A joystick is just two potentiometers so we need to add their pins to the constants:

const uint8_t X_PIN = A0;
const uint8_t Y_PIN = A1;

Then we can set them to input in the setup:

pinMode(X_PIN, INPUT);
pinMode(Y_PIN, INPUT);

In order to control the servos properly, we need to map the joystick outputs (which range from 0-1023) to an angle (0-179):

int x = analogRead(X_PIN);
int y = analogRead(Y_PIN);
unsigned char data[] = {0, 0};
data[0] = map(x, 0, 1023, 0, 179);
data[1] = map(y, 0, 1023, 0, 179);

We also store that data in an array so we can send it over the radio:

radio.write(&data, sizeof(data));

Receiver

The receiver is a tiny bit trickier, since we need the Servo library (we used version 1.2.2):

#include <Servo.h>
// ...
Servo servoX;
Servo servoY;

And then all we need to do is write the data to the servos:

void loop()
{
unsigned char data[] = {0, 0};
radio.read(&data, sizeof(data));

servoX.write(data[0]);
servoY.write(data[1]);
}

Video Demonstration

Servos working with joystick

Here is a video of our working wireless servo control. In the video we use a joystick, however the joystick works the same way as the potentiometers would. When the joystick moves up and down it controls one servo, when it moves side to side, it controls the other servo. With the potentiometers, one potentiometer controls one servo, the other potentiometer controls the other servo.