Arduino Nano Controlled NRF24L01 Wireless Command Transmitter
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to interface an Arduino Nano with an NRF24L01 wireless transceiver module and a series of tactile switch buttons. The Arduino Nano serves as the central processing unit, reading inputs from the buttons and sending commands wirelessly via the NRF24L01 module. The buttons are used to send specific commands that the Arduino Nano translates into wireless signals. The circuit is powered by a 4 x AAA battery mount, providing the necessary voltage to the Arduino Nano and the NRF24L01 module.
Component List
Arduino Nano
- Microcontroller board based on the ATmega328P
- It has a variety of digital and analog I/O pins
- Capable of serial communication via UART, SPI, and I2C
NRF24L01
- A 2.4GHz wireless transceiver module
- Interfaces with microcontrollers via the SPI protocol
- Used for short-range wireless communication
Tactile Switch Buttons - 12mm Square
- Momentary push buttons used for user input
- Typically have four pins, two of which are electrically connected when the button is pressed
4 x AAA Battery Mount
- A battery holder for four AAA batteries
- Provides power to the circuit
Wiring Details
Arduino Nano
GNDconnected to the ground plane, shared with all tactile buttons, NRF24L01 module, and battery mount negative terminalD2toD6connected to tactile switch buttons for inputD9(CEpin) andD10(CSNpin) connected to the NRF24L01 for SPI communicationD11/MOSI,D12/MISO, andD13/SCKconnected to corresponding SPI pins on the NRF24L01VINconnected to the positive terminal of the battery mount3V3connected to theVCC (3V)pin of the NRF24L01
NRF24L01
CEconnected toD9on the Arduino NanoCSNconnected toD10on the Arduino NanoMOSIconnected toD11/MOSIon the Arduino NanoMISOconnected toD12/MISOon the Arduino NanoSCKconnected toD13/SCKon the Arduino NanoVCC (3V)connected to3V3on the Arduino NanoGNDconnected to the ground plane
Tactile Switch Buttons - 12mm Square
- One side of each button connected to
GND - The other side of each button connected to individual digital pins
D2toD6on the Arduino Nano
4 x AAA Battery Mount
+terminal connected toVINon the Arduino Nano-terminal connected to the ground plane
Documented Code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
// Pin definitions for the tactile push buttons
const int button1Pin = 2; // Forward
const int button2Pin = 3; // Backward
const int button3Pin = 4; // Left
const int button4Pin = 5; // Right
const int button5Pin = 6; // Return to Origin
RF24 radio(9, 10); // NRF24L01 CE, CSN pins
const byte address[6] = "00001";
// Commands
enum Commands {
FORWARD,
BACKWARD,
LEFT,
RIGHT,
STOP,
RETURN_TO_ORIGIN
};
void setup() {
// Set up buttons as inputs
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
pinMode(button4Pin, INPUT_PULLUP);
pinMode(button5Pin, INPUT_PULLUP);
// Start the NRF24L01 radio
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_LOW);
}
void loop() {
// Check button states
if (digitalRead(button1Pin) == LOW) {
sendCommand(FORWARD);
delay(200); // Debounce delay
}
if (digitalRead(button2Pin) == LOW) {
sendCommand(BACKWARD);
delay(200); // Debounce delay
}
if (digitalRead(button3Pin) == LOW) {
sendCommand(LEFT);
delay(200); // Debounce delay
}
if (digitalRead(button4Pin) == LOW) {
sendCommand(RIGHT);
delay(200); // Debounce delay
}
if (digitalRead(button5Pin) == LOW) {
sendCommand(RETURN_TO_ORIGIN);
delay(200); // Debounce delay
}
}
// Function to send commands to the receiver
void sendCommand(Commands cmd) {
radio.stopListening(); // Stop listening before sending
radio.write(&cmd, sizeof(cmd)); // Send the command
radio.startListening(); // Start listening again
}
This code is designed to run on the Arduino Nano. It initializes the NRF24L01 module and sets up the tactile buttons as inputs with internal pull-up resistors. When a button is pressed, the corresponding command is sent wirelessly to the receiver. The sendCommand function handles the transmission of commands to the NRF24L01 module.