I made a project to control servo motor wirelessly using potentiometer using nrf24l01. But the circuit didn't work properly. I don't know why, here's

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

int potpin1 = A0;
int potpin2 = A1;
int potpin3 = A2;
int potpin4 = A3;

Int data[4];

RF24 radio(9,10);
const unit64_t pipe=0xE8E8F0F0E1LL;

void setup() [
radio.begin();
radio.openWritingPipe(pipe);
]

void loop() {

data[0] = analogRead(potpin1);
data[1] = analogRead(potpin2);
data[2] = analogRead(potpin3);
data[3] = analogRead(potpin4);

data[0] = map(data[0],0,1023,5,175);
data[1] = map(data[0],0,1023,5,175);
data[2] = map(data[0],0,1023,5,175);
data[3] = map(data[0],0,1023,5,175);

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

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

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

RF24 radio(9,10);
const uint64_t pipe=0xE8E8F0F0E1LL;
int data[4];

void setup() {
servo1.attach(4);
servo2.attach(5);
servo3.attach(6);
servo4.attach(7);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}

void loop() {
if(radio.available()) {
bool done = false;
while(!done) {
radio.read(data,sizeof(data));
servo1.write(data[0]);
servo2.write(data[1]);
servo3.write(data[2]);
servo4.write(data[3]);
}
}
}

Ugly, unformatted, outdated, not working code.

This looks like a stack of copy/paste errors:

1 Like

I just beginner. This is my first Arduino project. I am trying to learn. Can you please help

Split this project into two parts:

  1. Test the servo part in the receiver simulating what the transmitter would have sent.
  2. Get a basic NRF24L01 radio pair talking to each other using a standard tutorial.
  3. join it all up.

You should format code before posting (use the feature in the Arduino IDE)
You should use code tags when posting here so the code appears in a limited window.

When trying to get my radios to work I tried many tutorials. The one that helped the most is Robin2's simple rf24 tutorial. If you, carefully, read and follow that tutorial you stand a real good chance of getting the radios to communicate.

If you want example code to read, send and receive 2 analog (potentiometer) joysticks (4 axis), I have working code that I will share. But you need to get the radios to work with the tutorial code first.

Be sure to power the servo correctly, using a 4xAA battery pack.

Do NOT use the Arduino 5V output to power the servo. Don't forget to connect the battery, servo and Arduino ground connections together!

Can you share example code

Did you get the radios to work with the example code from Robin2's tutorial. Until you do that, my code is worthless.

It is very important that you get the 3.3V supply to the radio modules to supply 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.

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