NRF24L01 PART-3 || CONTROLING SERVOS


NRF24L01 PART-3 || CONTROLING SERVOS

CIRCUIT DIAGRAM :


TRANSMITTER CODE:


#include <SPI.h> #include <nRF24L01.h> #include <RF24.h> #define servo1 A3 #define servo2 A4 #define servo3 A5 RF24 radio(9, 10); // CE, CSN const byte address[6] = "mkinventions100"; int SERVOS = 0; void setup() { radio.begin(); radio.openWritingPipe(address); radio.setPALevel(RF24_PA_MIN); radio.stopListening(); } void loop() { int SERVOS[3]; SERVOS[0] = map(analogRead(servo1), 0, 1023, 0, 179); SERVOS[1] = map(analogRead(servo2), 0, 1023, 0, 179); SERVOS[2] = map(analogRead(servo3), 0, 1023, 0, 179); radio.write(&SERVOS, sizeof(SERVOS)); delay(5); }


RECEIVER CODE:

#include <SPI.h> #include <nRF24L01.h> #include <RF24.h> #include <Servo.h> Servo myservo1; Servo myservo2; Servo myservo3; RF24 radio(9, 10); // CE, CSN const byte address[6] = "mkinventions100"; const int servo1 = 2; const int servo2 = 3; const int servo3 = 4; int SERVOS = 0; void setup() { myservo1.attach(servo1); myservo2.attach(servo2); myservo3.attach(servo3); radio.begin(); radio.openReadingPipe(0, address); radio.setPALevel(RF24_PA_MIN); radio.startListening(); } void loop() { delay(5); if ( radio.available()) { SERVO(); } } void SERVO(){ while (radio.available()) { int SERVOS[3]; radio.read(&SERVOS, sizeof(SERVOS)); myservo1.write(SERVOS[0]); myservo2.write(SERVOS[1]); myservo3.write(SERVOS[2]); } }


Post a Comment

0 Comments