// Hardware
Components
ESP32
NRF24L01
2x NRF24 Adapter
Capacitor 100µF
Breadboard & Wires
// How It Works
Working Principle
The MPU6050 sensor measures motion and orientation data. The transmitter ESP32 reads the yaw and pitch values and sends them wirelessly through an NRF24L01 module. The receiver ESP32 receives the data and converts it into servo positions. As the sensor moves, both servos follow the movement in real time, creating a wireless control system.
// Source Code
Transmitter Code for ESP32
#include <Wire.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <MPU6050_tockn.h>
RF24 radio(4, 5); // CE, CSN
MPU6050 mpu6050(Wire);
const byte address[6] = "00001";
struct Data {
int yaw;
int pitch;
};
Data data;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // SDA, SCL
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_HIGH);
radio.setDataRate(RF24_250KBPS);
radio.stopListening();
Serial.println("Transmitter Ready");
}
void loop() {
mpu6050.update();
data.yaw = (int)mpu6050.getAngleZ();
data.pitch = (int)mpu6050.getAngleX();
data.yaw = constrain(data.yaw, -90, 90);
data.pitch = constrain(data.pitch, -90, 90);
radio.write(&data, sizeof(data));
Serial.print("Yaw: ");
Serial.print(data.yaw);
Serial.print(" | Pitch: ");
Serial.println(data.pitch);
delay(20);
}
}
// Source Code
Receiver Code for ESP32
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <ESP32Servo.h>
RF24 radio(4, 5); // CE, CSN
const byte address[6] = "00001";
Servo servoYaw;
Servo servoPitch;
struct Data {
int yaw;
int pitch;
};
Data data;
void setup() {
Serial.begin(115200);
servoYaw.attach(25);
servoPitch.attach(26);
servoYaw.write(90);
servoPitch.write(90);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_HIGH);
radio.setDataRate(RF24_250KBPS);
radio.startListening();
Serial.println("Receiver Ready");
}
void loop() {
if (radio.available()) {
radio.read(&data, sizeof(data));
int yawAngle = map(data.yaw, -90, 90, 0, 180);
int pitchAngle = map(data.pitch, -90, 90, 0, 180);
yawAngle = constrain(yawAngle, 0, 180);
pitchAngle = constrain(pitchAngle, 0, 180);
servoYaw.write(yawAngle);
servoPitch.write(pitchAngle);
Serial.print("Yaw: ");
Serial.print(data.yaw);
Serial.print(" -> ");
Serial.print(yawAngle);
Serial.print(" | Pitch: ");
Serial.print(data.pitch);
Serial.print(" -> ");
Serial.println(pitchAngle);
}
}
}