1

My project is to control a servo with a joystick using nRF24L01. I have this code working well, but the problem is that I want to add a lamp in the receiver side, and a switch in the transmitter side. I had tried so many codes from the internet, but nothing works. When I implement the code for the led, the servo and the joystick will stop working unfortunately. Maybe the problem could be solved by transmitting on 2 channels each channel has a command. But, the question is how this is the transmitter code that is working normally :

Transmitter Code

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

RF24 radio(7, 8); // CE, CSN const byte address[6] = "00001";

void setup() {

radio.begin(); radio.openWritingPipe(address); // 00002 radio.setPALevel(RF24_PA_MIN); radio.stopListening(); }

void loop() { delay(5);

radio.stopListening(); int potValue = analogRead(A0); int angleValue = map(potValue, 0, 1024, 0, 23.5); radio.write(&angleValue, sizeof(angleValue));

delay(5); radio.startListening();

}

and this is the receiver code:

Receiver Code

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

RF24 radio(7, 8); // CE, CSN const byte address[6] = "00001"; boolean button_state = 0;

Servo myServo;

void setup() {

Serial.begin(9600);

myServo.attach(5);

radio.begin();

radio.openReadingPipe(0, address); // 00002 radio.setPALevel(RF24_PA_MIN);

}

void loop() {

delay(5); radio.startListening();

if ( radio.available()) { while (radio.available()) {

  int angleV = 0;
  radio.read(&amp;angleV, sizeof(angleV));
 myServo.write(angleV);
  }




delay(5);
radio.stopListening();

}}

timemage
  • 5,181
  • 1
  • 13
  • 25
wael
  • 11
  • 1
  • 2
    i had tried soo many codes from the internet ... that is your problem ... copy & paste programming ... please do yourself a favor and learn what your existing program is actually doing ... you may find that it is actually easy to add another piece of data to the transmission – jsotola May 30 '21 at 23:30

0 Answers0