Hello forum,
During Covid-19, I decided to start a project involving Arduino (Uno and nano). This would be my first time messing around with electronics, and I wanted to build an RC plane.
I managed to do enough research to have 2 servos working wirelessly (using the NRF24l01 antenna version), it was working wonderfully. However, when I changed to code to accommodate 3 servos, it did not work anymore. When I plugged the receiving circuit (nano) into power, the servos would go to the correct position (to the position the input told them) and stay there, no matter how much I moved my input devices on the transmitting board (uno) the servos did nothing. However, once in a blue moon it would work, the servos would move when I told them, but then they would stop working again if I moved the wires too much. I don't know if the problem lays in the wiring or the code, or even power, but since I'm new, and there are people who are better at this than me, I thought I might post this message and my code to see if anyone had any advice.
The codes should be attachments below
Transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>int angleValue[3];
RF24 radio(7, 8 ); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};void setup() {
radio.begin();
radio.openWritingPipe(addresses[1]); // 00002
radio.openReadingPipe(1, addresses[0]); // 00001
radio.setPALevel(RF24_PA_MIN);
}void loop() {
delay(5);radio.stopListening();
angleValue[0] = analogRead(A0);
angleValue[1] = analogRead(A1);
angleValue[2] = analogRead(A2);
angleValue[0] = map(angleValue[0], 0, 1023, 0, 180);
angleValue[1] = map(angleValue[1], 0, 1023, 0, 180);
angleValue[2] = map(angleValue[2], 0, 1023, 0, 180);
radio.write(&angleValue, sizeof(angleValue));
{
Serial.println(angleValue[0]);
Serial.println(angleValue[1]);
Serial.println(angleValue[2]);
}
}
Receiver :
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>Servo servo1;
Servo servo2;
Servo servo3;RF24 radio(7, 8 ); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
int angleV[3];void setup() {
servo1.attach(5);
servo2.attach(6);
servo3.attach(3);
radio.begin();
radio.openWritingPipe(addresses[0]); // 00001
radio.openReadingPipe(1, addresses[1]); // 00002
radio.setPALevel(RF24_PA_MIN);
}void loop() {
delay(5);
radio.startListening();
if ( radio.available()) {
while (radio.available()) {
radio.read(&angleV, sizeof(angleV));
servo1.write(angleV[0]);
servo2.write(angleV[1]);
servo3.write(angleV[2]);
}
{
Serial.println(angleV[0]);
Serial.println(angleV[1]);
Serial.println(angleV[2]);
}}
}