Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano-Based Battery-Powered Drone Controller with NRF24L01 and MPU6050

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Battery-Powered Drone Controller with NRF24L01 and MPU6050

Circuit Documentation

Summary

This circuit is designed to interface an Arduino Nano with an NRF24L01 wireless transceiver and an InvenSense MPU6050 accelerometer and gyroscope sensor. The circuit is powered by a 3.7V LiPo battery. The Arduino Nano reads data from the MPU6050 sensor and transmits it wirelessly using the NRF24L01 module.

Component List

  1. Arduino Nano

    • Description: A small, complete, and breadboard-friendly board based on the ATmega328P.
    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
  2. NRF24L01

    • Description: A wireless transceiver module for low-power, high-speed communication.
    • Pins: IRQ (not used), MOSI, CSN, VCC (3V), GND, CE, SCK, MISO
  3. InvenSense MPU6050

    • Description: A 6-axis motion tracking device that combines a 3-axis gyroscope and a 3-axis accelerometer.
    • Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT
  4. 3.7V LiPo Battery

    • Description: A rechargeable lithium polymer battery.
    • Pins: +Ve, GND

Wiring Details

Arduino Nano

NRF24L01

InvenSense MPU6050

3.7V LiPo Battery

Code Documentation

Arduino Nano Code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <MPU6050.h>

// NRF24L01 Pins
#define CE_PIN 9
#define CSN_PIN 10

RF24 radio(CE_PIN, CSN_PIN);
const byte address[6] = "00001"; // Communication address

// Variables for MPU6050
MPU6050 mpu;
int16_t ax, ay, az, gx, gy, gz;
float pitch, roll, yaw;

// Variables for throttle and control
int throttle = 0; // Throttle value (0 to 255)
int data[4];      // Array to store [throttle, yaw, pitch, roll]

void setup() {
  // Initialize Serial for debugging
  Serial.begin(9600);

  // Initialize MPU6050
  Wire.begin();
  mpu.initialize();
  if (!mpu.testConnection()) {
    Serial.println("MPU6050 connection failed");
    while (1); // Stop if the connection fails
  }

  // Initialize RF24
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_LOW);
  radio.stopListening();

  // Debug message
  Serial.println("Controller is ready!");
}

void loop() {
  // Read MPU6050 data
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  // Calculate pitch and roll
  pitch = atan2(ax, sqrt(ay * ay + az * az)) * 180 / PI;
  roll = atan2(ay, sqrt(ax * ax + az * az)) * 180 / PI;
  yaw = gx / 131.0; // Approximate yaw from gyroscope

  // Debugging sensor data
  Serial.print("Pitch: "); Serial.print(pitch);
  Serial.print(" Roll: "); Serial.print(roll);
  Serial.print(" Yaw: "); Serial.println(yaw);

  // Map pitch, roll, and yaw to control values (0-255)
  data[0] = throttle; // Throttle remains constant for now
  data[1] = map(yaw, -90, 90, 0, 255);
  data[2] = map(pitch, -90, 90, 0, 255);
  data[3] = map(roll, -90, 90, 0, 255);

  // Send data to the drone
  bool success = radio.write(&data, sizeof(data));
  if (success) {
    Serial.println("Data sent!");
  } else {
    Serial.println("Data send failed.");
  }

  delay(50); // Small delay for stability
}

This code initializes the MPU6050 sensor and the NRF24L01 transceiver, reads sensor data, calculates pitch, roll, and yaw, maps these values to control values, and sends the data wirelessly to a receiver.