I was trying to control pan tilt wirelessly using NRF24L01+ , two potentiometer and arduino uno. I was using this code:-
Transmitter
Receiver
The problem what I am facing with this code is only one servo motor is controlled that too with both potentiometer instead of one potentiometer for each servo. Please help me for fixing this issue.
Transmitter
Code:
#include <SPI.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte addresses[] = {"1Node"};
struct dataStruct {
int angleValue_1;
int angleValue_2;
} myData;
void setup() {
radio.begin();
radio.setChannel(83);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_LOW);
radio.openWritingPipe(addresses[0]);
radio.stopListening();
}
void loop() {
int potValue_1 = analogRead(A0);
int potValue_2 = analogRead(A1);
myData.angleValue_1 = map(potValue_1, 0, 1023, 0, 180);
myData.angleValue_2 = map(potValue_2, 0, 1023, 0, 180);
radio.write( &myData, sizeof(myData));
}
Code:
#include <SPI.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(9, 10); // CE, CSN
const byte addresses[] = "1Node";
const byte pipe = 1;
Servo myServo_1;
Servo myServo_2;
struct dataStruct {
int angleValue_1;
int angleValue_2;
} myData;
void setup() {
myServo_1.attach(7);
myServo_2.attach(8);
radio.begin();
radio.setChannel(83);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_LOW);
radio.openReadingPipe(pipe, addresses[0]);
radio.startListening();
}
void loop() {
if (radio.available()) {
while (radio.available()) {
radio.read( &myData, sizeof(myData) );
myServo_1.write(myData.angleValue_1);
myServo_2.write(myData.angleValue_2);
}
}
}