0% found this document useful (0 votes)
4 views1 page

NRF24L01 Servo Motor Control Code

This document contains a code for a receiver using an nRF24L01 radio module and a servo motor. It initializes motor control pins and sets up the radio to listen for incoming data, which controls the speed of a motor and the angle of a servo. The loop function processes the received data to adjust motor speed and servo position accordingly.

Uploaded by

wsckg2wjzz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

NRF24L01 Servo Motor Control Code

This document contains a code for a receiver using an nRF24L01 radio module and a servo motor. It initializes motor control pins and sets up the radio to listen for incoming data, which controls the speed of a motor and the angle of a servo. The loop function processes the received data to adjust motor speed and servo position accordingly.

Uploaded by

wsckg2wjzz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// RECEIVER

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

RF24 radio(9, 10); // CE, CSN


Servo myServo;

const byte address[6] = "00001";

// Motor control pins


const int motorPinA = 6; // IN1
const int motorPinB = 7; // IN2
const int enablePin = 5; // ENA (PWM pin)

// Servo pin
const int servoPin = 3;

void setup() {
[Link](9600);

pinMode(motorPinA, OUTPUT);
pinMode(motorPinB, OUTPUT);
pinMode(enablePin, OUTPUT);

[Link](servoPin);

[Link]();
[Link](0, address);
[Link](RF24_PA_LOW);
[Link]();
}

void loop() {
if ([Link]()) {
int data[2];
[Link](&data, sizeof(data));

int speedVal = constrain(data[0], 0, 255); // Forward speed only


int servoVal = map(data[1], 0, 1023, 0, 180); // Servo angle

// Motor forward only


digitalWrite(motorPinA, HIGH);
digitalWrite(motorPinB, LOW);
analogWrite(enablePin, speedVal);

// Move servo
[Link](servoVal);
}
}

You might also like