Circuit Documentation
Summary
This circuit is designed to control a DC motor and a servo motor using two Arduino boards (UNO and Nano) and wireless communication via NRF24L01 modules. The Arduino UNO acts as the receiver, controlling the motors based on the data received from the transmitter, which is the Arduino Nano. The Nano reads analog values from a dual-axis joystick module and sends these values wirelessly to the UNO. The UNO then maps these values to control the speed and direction of the DC motor using an L298N motor driver and the position of the servo motor.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- Used as the main controller for receiving data and controlling the motors
NRF24L01 (Receiver)
- 2.4GHz wireless transceiver module
- Connected to the Arduino UNO for receiving control signals
DC Motor
- Electric motor that converts electrical energy into mechanical energy
- Controlled by the L298N motor driver
L298N DC Motor Driver
- Dual H-bridge motor driver module
- Drives the DC motor based on signals from the Arduino UNO
Battery AAx4 6V
- Power source for the motor driver and the DC motor
Servo
- Rotary actuator that allows for precise control of angular position
- Controlled directly by the Arduino UNO
Arduino Nano
- Small, complete, and breadboard-friendly microcontroller board based on the ATmega328P
- Used as the transmitter to send control signals to the Arduino UNO
NRF24L01 (Transmitter)
- 2.4GHz wireless transceiver module
- Connected to the Arduino Nano for sending control signals
KY-023 Dual Axis Joystick Module (x2)
- Analog joystick with a push-button
- Used to capture user input for controlling the motors
Wiring Details
Arduino UNO
3.3Vto NRF24L01 VCC (Receiver)5Vto Servo VCCGNDto NRF24L01 GND (Receiver), Servo GND, L298N GND, and Battery GNDD13to NRF24L01 SCK (Receiver)D12to NRF24L01 MISO (Receiver)D11to NRF24L01 MOSI (Receiver)D10to NRF24L01 CSN (Receiver)D9to NRF24L01 CE (Receiver)D6to L298N ENBD5to L298N IN3D4to L298N IN4D3to Servo PWM
NRF24L01 (Receiver)
- Connected as detailed above in the Arduino UNO section
DC Motor
pin 1to L298N OUT4pin 2to L298N OUT3
L298N DC Motor Driver
OUT3andOUT4to DC Motor12Vto Battery VCCGNDto Battery GNDENBto Arduino UNO D6IN3to Arduino UNO D5IN4to Arduino UNO D4
Battery AAx4 6V
VCCto L298N 12VGNDto L298N GND
Servo
VCCto Arduino UNO 5VGNDto Arduino UNO GNDPWMto Arduino UNO D3
Arduino Nano
3V3to NRF24L01 VCC (Transmitter)GNDto NRF24L01 GND (Transmitter), KY-023 GND (x2)5Vto KY-023 +5V (x2)D9to NRF24L01 CE (Transmitter)D10to NRF24L01 CSN (Transmitter)D11/MOSIto NRF24L01 MOSI (Transmitter)D12/MISOto NRF24L01 MISO (Transmitter)D13/SCKto NRF24L01 SCK (Transmitter)A0to KY-023 VRx (Joystick 1)A1to KY-023 VRx (Joystick 2)
NRF24L01 (Transmitter)
- Connected as detailed above in the Arduino Nano section
KY-023 Dual Axis Joystick Module (x2)
GNDto Arduino Nano GND+5Vto Arduino Nano 5VVRxto Arduino Nano A0 (Joystick 1) and A1 (Joystick 2)
Documented Code
Arduino UNO Code (Receiver)
#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 (Transmitter)
#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 a description of each component, wiring details, and the embedded code for the microcontrollers. The code sections are documented to explain the functionality of the receiver and transmitter in the wireless control system.
