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

Arduino-Controlled Wireless Servo and DC Motor System

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Wireless Servo and DC Motor System

Circuit Documentation

Summary

This circuit is designed to facilitate wireless communication between two microcontroller units (MCUs) using NRF24L01 transceiver modules. The primary MCU, an Arduino UNO, controls a servo motor and a DC motor via an L298N motor driver. The secondary MCU, an Arduino Nano, interfaces with two KY-023 Dual Axis Joystick Modules to capture user inputs. The Arduino UNO receives the joystick positions wirelessly and translates them into motor control signals. The DC motor's speed and direction are controlled by the L298N driver, while the servo's position is adjusted directly by the Arduino UNO.

Component List

Microcontrollers

Communication Modules

Motor and Driver

Power Supply

Actuators

Sensors and Input Devices

Wiring Details

Arduino UNO

L298N DC Motor Driver

Arduino Nano

KY-023 Dual Axis Joystick Module

Documented Code

Arduino UNO Code

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

Servo myservo;

// Set the CE and CSN pins
RF24 radio(9, 10);

// Create a pipe for communication
const byte address[6] = "00001"; 

int motorPin1 = 4;
int motorPin2 = 5; 
int mappedServoValue;
int mappedMotorValue;

// Structure to hold the received variables
struct DataPackage {
  int motorValue;
  int servoValue;
};

DataPackage data;

void setup() {
  Serial.begin(9600);
  myservo.attach(3);

  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);

  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  
  // Initialize the NRF24L01 module
  radio.begin();
  
  // Open the same pipe as the transmitter for reading
  radio.openReadingPipe(0, address);
  
  // Set the radio in receiver mode
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening(); // Start listening for data
}

void loop() {
  if (radio.available()) { // Check if data is available
    radio.read(&data, sizeof(data)); // Read the incoming data structure

    mappedMotorValue = map(data.motorValue,500,1023,0,255);
    if (data.motorValue > 510) {
      analogWrite(6,mappedMotorValue);
    }
    else {
      analogWrite(6,0);
    }

    mappedServoValue = map(data.servoValue,0,1023,180,0);
    if (mappedServoValue >= 0){
      myservo.write(mappedServoValue);
    }
    else {
      myservo.write(90);
    }

    // Print the received variables
    Serial.print("MOTOR: ");
    Serial.print(data.motorValue);
    Serial.print(" -> ");
    Serial.print(mappedMotorValue);
    Serial.print("   \tSERVO: ");
    Serial.print(data.servoValue);
    Serial.print(" -> ");
    Serial.println(mappedServoValue);
  }
}

Arduino Nano Code

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

// Set the CE and CSN pins
RF24 radio(9, 10);

// Create a pipe for communication
const byte address[6] = "00001"; 

// Structure to hold the received variables
struct DataPackage {
  int motorValue;
  int servoValue;
};

DataPackage data;

#define MOTOR_PIN  A4 // Arduino pin connected to VRX pin
#define SERVO_PIN  A3 // Arduino pin connected to VRY pin

int xValue = 0; // To store value of the X axis
int yValue = 0; // To store value of the Y axis

void setup() {
  Serial.begin(9600) ;

  // Initialize the NRF24L01 module
  radio.begin();
  
  // Set the address to the pipe for writing
  radio.openWritingPipe(address);
  
  // Set the radio in transmitter mode
  radio.setPALevel(RF24_PA_MIN);
}

void loop() {
  // read analog X and Y analog values
  data.motorValue = analogRead(MOTOR_PIN);
  data.servoValue = analogRead(SERVO_PIN);

  // Set module to transmit mode
  radio.stopListening();

  // Send the data structure
  bool success = radio.write(&data, sizeof(data));
  
  if (success) {
    Serial.print("[SENT]\t");
  } else {
    Serial.print("[NOT SENT]\t");
  }

  // print data to Serial Monitor on Arduino IDE
  Serial.print("MOTOR: ");
  Serial.print(data.motorValue);
  Serial.print("\tSERVO: ");
  Serial.println(data.servoValue);

  delay(100);
}

This documentation provides an overview of the circuit, including the components used, their wiring connections, and the embedded code for the microcontrollers. The code sections are documented to reflect the functionality of each microcontroller within the circuit.