This circuit is designed to control a set of four "Motor amarillo motorreductor hobby" motors using an L298N DC motor driver module. The system is controlled by an Arduino Nano microcontroller, which interfaces with an nRF24L01 wireless transceiver module for remote control capabilities. A toggle switch is used to control the power supply to the motor driver, and a red LED is included for status indication. The power source for the circuit is a 7.4V battery.
vcc
and GND
. The vcc
of two motors are connected to OUT4
and OUT3
of the L298N motor driver, while the GND
of the same two motors are connected to OUT2
and OUT1
respectively.D2
to D7
are used to control the L298N motor driver and the nRF24L01 module.VIN
is connected to the 5V
pin of the L298N motor driver to power the Arduino Nano.GND
is connected to the common ground of the circuit.3V3
powers the nRF24L01 module.D13/SCK
, D11/MOSI
, and D12/MISO
are used for SPI communication with the nRF24L01 module.OUT1
, OUT2
, OUT3
, and OUT4
are connected to the motors.ENA
and ENB
are connected to D3
and D9
on the Arduino Nano for enabling the motor outputs.IN1
, IN2
, IN3
, and IN4
are connected to D4
, D5
, D6
, and D7
on the Arduino Nano for controlling motor direction.12V
is connected to the L2
pin of the toggle switch to control power to the motors.GND
is connected to the common ground of the circuit.VCC
is connected to 3V3
on the Arduino Nano.GND
is connected to the common ground of the circuit.CE
, CSN
, SCK
, MOSI
, and MISO
are connected to D8
, D10
, D13/SCK
, D11/MOSI
, and D12/MISO
on the Arduino Nano respectively.cathode
is connected to GND
on the Arduino Nano.anode
is connected to D2
on the Arduino Nano.COM
is connected to the positive terminal of the 7.4V battery.L2
is connected to the 12V
input of the L298N motor driver.#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
int ENA = 3;
int ENB = 9;
int MotorA1 = 4;
int MotorA2 = 5;
int MotorB1 = 6;
int MotorB2 = 7;
RF24 radio(8, 10);
const byte address[6] = "00001";
struct data {
int xAxis;
int yAxis;
};
data receive_data;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0,address);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
radio.startListening();
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(MotorA1, OUTPUT);
pinMode(MotorA2, OUTPUT);
pinMode(MotorB1, OUTPUT);
pinMode(MotorB2, OUTPUT);
}
void loop() {
while(radio.available()) {
radio.read(&receive_data, sizeof(data));
if(receive_data.yAxis > 400) {
digitalWrite(MotorA1, LOW);
digitalWrite(MotorA2, HIGH);
digitalWrite(MotorB1, HIGH);
digitalWrite(MotorB2, LOW);
analogWrite(ENA, 150);
analogWrite(ENB, 150);
} else if(receive_data.yAxis < 320) {
digitalWrite(MotorA1, HIGH);
digitalWrite(MotorA2, LOW);
digitalWrite(MotorB1, LOW);
digitalWrite(MotorB2, HIGH);
analogWrite(ENA, 150);
analogWrite(ENB, 150);
} else if(receive_data.xAxis < 320){
digitalWrite(MotorA1, HIGH);
digitalWrite(MotorA2, LOW);
digitalWrite(MotorB1, HIGH);
digitalWrite(MotorB2, LOW);
analogWrite(ENA, 150);
analogWrite(ENB, 150);
} else if(receive_data.xAxis > 400){
digitalWrite(MotorA1, LOW);
digitalWrite(MotorA2, HIGH);
digitalWrite(MotorB1, LOW);
digitalWrite(MotorB2, HIGH);
analogWrite(ENA, 150);
analogWrite(ENB, 150);
} else {
digitalWrite(MotorA1, LOW);
digitalWrite(MotorA2, LOW);
digitalWrite(MotorB1, LOW);
digitalWrite(MotorB2, LOW);
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}
}
}
This code is responsible for setting up the Arduino Nano to communicate with the nRF24L01 module and control the L298N motor driver based on the received wireless signals. It initializes the SPI communication, sets up the radio, and configures the motor control pins. The loop
function listens for incoming data and controls the motors accordingly.