Arduino Nano Controlled Robotic Vehicle with NRF24L01 Wireless Communication
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to wirelessly control a DC motor and a servo motor using two Arduino Nano microcontrollers and NRF24L01 transceiver modules. One Arduino Nano acts as a transmitter, reading input from an analog joystick and sending the data to the receiver. The other Arduino Nano acts as a receiver, controlling the DC motor through an L298N motor driver and a servo motor based on the received joystick data. The circuit is powered by a 12V battery, with a step-down module to provide the appropriate voltage levels to the components.
Component List
Microcontrollers
- Arduino Nano: A compact microcontroller board based on the ATmega328P, featuring digital and analog I/O pins.
Communication Modules
- NRF24L01: A 2.4GHz wireless transceiver module used for short-range communication between the transmitter and receiver.
Motors
- DC Motor: An electric motor that runs on direct current (DC) electricity.
- Servo: A rotary actuator or linear actuator that allows for precise control of angular or linear position.
Motor Driver
- L298N DC Motor Driver: A high-power motor driver capable of driving DC and stepper motors.
Power Supply
- 12V Battery: Provides the main power source for the motor driver and the step-down module.
- LM2596 Step Down Module: A voltage regulator that steps down the input voltage to a lower level.
Input Devices
- Analog Joystick (Wokwi Compatible): A manual control input device that provides two-dimensional input by measuring the position of a joystick in the vertical and horizontal axes.
Wiring Details
Arduino Nano (Transmitter)
- D2: Connected to L298N DC motor driver IN1.
- D3: Connected to L298N DC motor driver ENB.
- D4: Connected to L298N DC motor driver IN4.
- D5: Connected to L298N DC motor driver IN3.
- D6: Connected to Servo PWM.
- D7: Connected to L298N DC motor driver IN2.
- D8: Connected to NRF24L01 CSN.
- D9: Connected to NRF24L01 CE.
- D10: Connected to L298N DC motor driver ENA.
- D11/MOSI: Connected to NRF24L01 MOSI.
- D12/MISO: Connected to NRF24L01 MISO.
- VIN: Connected to L298N DC motor driver 5V.
- GND: Common ground with NRF24L01, 12V Battery, L298N DC motor driver, and LM2596 Step Down Module.
- 3V3: Connected to NRF24L01 VCC (3V).
- D13/SCK: Connected to NRF24L01 SCK.
- A0: Connected to Analog Joystick VERT.
- A1: Connected to Analog Joystick HORZ.
Arduino Nano (Receiver)
- D8: Connected to NRF24L01 CSN.
- D9: Connected to NRF24L01 CE.
- D11/MOSI: Connected to NRF24L01 MOSI.
- D12/MISO: Connected to NRF24L01 MISO.
- GND: Common ground with NRF24L01.
- 3V3: Connected to NRF24L01 VCC (3V).
- D13/SCK: Connected to NRF24L01 SCK.
- 5V: Connected to Analog Joystick VCC.
- A0: Connected to Analog Joystick VERT.
- A1: Connected to Analog Joystick HORZ.
NRF24L01
- IRQ (not used): Not connected.
- MOSI: Connected to Arduino Nano D11/MOSI.
- CSN: Connected to Arduino Nano D8.
- VCC (3V): Connected to Arduino Nano 3V3.
- GND: Common ground with Arduino Nano.
- CE: Connected to Arduino Nano D9.
- SCK: Connected to Arduino Nano D13/SCK.
- MISO: Connected to Arduino Nano D12/MISO.
DC Motor
- Pin 1: Connected to L298N DC motor driver OUT1 or OUT4.
- Pin 2: Connected to L298N DC motor driver OUT2 or OUT3.
Servo
- GND: Connected to LM2596 Step Down Module OUT-.
- VCC: Connected to LM2596 Step Down Module OUT+.
- PWM: Connected to Arduino Nano D6.
L298N DC Motor Driver
- OUT1, OUT2, OUT3, OUT4: Connected to DC Motor pins.
- 12V: Connected to 12V Battery +.
- GND: Common ground with Arduino Nano, NRF24L01, 12V Battery, and LM2596 Step Down Module.
- 5V: Connected to Arduino Nano VIN.
- ENA, ENB: Connected to Arduino Nano D10 and D3 respectively.
- IN1, IN2, IN3, IN4: Connected to Arduino Nano D2, D7, D5, and D4 respectively.
LM2596 Step Down Module
- OUT-: Connected to Servo GND.
- OUT+: Connected to Servo VCC.
- IN-: Common ground with Arduino Nano, NRF24L01, 12V Battery, and L298N DC motor driver.
- IN+: Connected to 12V Battery +.
Analog Joystick (Wokwi Compatible)
- GND: Connected to Arduino Nano GND.
- VCC: Connected to Arduino Nano 5V.
- VERT: Connected to Arduino Nano A0.
- HORZ: Connected to Arduino Nano A1.
- SEL: Not connected.
Documented Code
Transmitter Code (Arduino Nano)
//transmitter
// Library: TMRh20/RF24 (https://github.com/tmrh20/RF24/)
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
RF24 radio(9, 8); // CE, CSN
const byte address[10] = "ADDRESS01";
int joyX = A0; // Joystick X-axis connected to analog pin A0
int joyY = A1; // Joystick Y-axis connected to analog pin A1
struct DataPackage {
int x;
int y;
};
DataPackage data;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
pinMode(joyX, INPUT);
pinMode(joyY, INPUT);
}
void loop() {
data.x = analogRead(joyX); // Read X-axis value
data.y = analogRead(joyY); // Read Y-axis value
radio.write(&data, sizeof(data));
// Print joystick data for debugging
Serial.print("X: ");
Serial.print(data.x);
Serial.print(" | Y: ");
Serial.println(data.y);
delay(100); // Adjust delay as needed
}
Receiver Code (Arduino Nano)
// Libraries for RF24 and Servo control
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <Servo.h>
RF24 radio(9, 8); // CE, CSN
const byte address[10] = "ADDRESS01";
const int motorPin1 = 3; // Pin to control first DC motor (PWM-capable)
const int motorPin2 = 10; // Pin to control second DC motor (PWM-capable)
const int motorDirPin1 = 4; // Direction control pin for first motor
const int motorDirPin2 = 7; // Direction control pin for second motor
const int servoPin = 6; // Pin to control servo
Servo myServo; // Servo motor object
int motorSpeed1 = 0; // Speed of the first DC motor
int motorSpeed2 = 0; // Speed of the second DC motor
struct DataPackage {
int x;
int y;
};
DataPackage data;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
myServo.attach(servoPin); // Attach servo to the specified pin
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorDirPin1, OUTPUT);
pinMode(motorDirPin2, OUTPUT);
}
void loop() {
if (radio.available()) {
radio.read(&data, sizeof(data));
// Map joystick Y-axis to motor speeds
motorSpeed1 = map(data.y, 0, 1023, -255, 255);
motorSpeed2 = map(data.y, 0, 1023, -255, 255);
int motorDirection1 = (motorSpeed1 >= 0) ? HIGH : LOW;
int motorDirection2 = (motorSpeed2 >= 0) ? HIGH : LOW;
digitalWrite(motor