This circuit integrates an Arduino Nano microcontroller with a KY-023 Dual Axis Joystick Module, an NRF24L01 wireless transceiver module, an electrolytic capacitor, and a 9V battery. The Arduino Nano reads the joystick's position and button state, then transmits this information wirelessly via the NRF24L01 module. The electrolytic capacitor is used to stabilize the power supply to the NRF24L01, which is sensitive to power fluctuations. The 9V battery provides the power source for the circuit.
GND
connected to the ground plane.D7
connected to NRF24L01 MOSI
.D8
connected to NRF24L01 MISO
.D9
connected to NRF24L01 CE
.D10
connected to NRF24L01 CSN
.D11/MOSI
connected to NRF24L01 SCK
.VIN
connected to 9V Battery +
.5V
connected to both KY-023 Joystick Modules +5V
.A3
connected to one KY-023 Joystick Module VRy
.A2
connected to one KY-023 Joystick Module VRx
.A1
connected to the other KY-023 Joystick Module VRy
.A0
connected to the other KY-023 Joystick Module VRx
.3V3
connected to Electrolytic Capacitor +
and NRF24L01 VCC (3V)
.GND
connected to the ground plane.+5V
connected to Arduino Nano 5V
.VRx
connected to Arduino Nano A0
or A2
.VRy
connected to Arduino Nano A1
or A3
.SW
(not wired in this circuit).GND
connected to the ground plane.MOSI
connected to Arduino Nano D7
.CSN
connected to Arduino Nano D10
.VCC (3V)
connected to Electrolytic Capacitor +
and Arduino Nano 3V3
.CE
connected to Arduino Nano D9
.SCK
connected to Arduino Nano D11/MOSI
.MISO
connected to Arduino Nano D8
.-
connected to the ground plane.+
connected to Arduino Nano 3V3
and NRF24L01 VCC (3V)
.-
connected to the ground plane.+
connected to Arduino Nano VIN
.#include <SPI.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN pins
const int joyXPin = A0; // Joystick X-axis connected to A0
const int joyYPin = A1; // Joystick Y-axis connected to A1
const int buttonPin = 2; // Joystick button connected to pin 2
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(buttonPin, INPUT_PULLUP); // Set the button pin as input with pull-up resistor
radio.begin();
radio.openWritingPipe(0xF0F0F0F0E1LL);
radio.setPALevel(RF24_PA_HIGH);
radio.setDataRate(RF24_1MBPS);
}
void loop() {
int xValue = analogRead(joyXPin); // Read X-axis value
int yValue = analogRead(joyYPin); // Read Y-axis value
bool buttonState = digitalRead(buttonPin); // Read button state
// Print joystick values to serial monitor
Serial.print("X: ");
Serial.print(xValue);
Serial.print(" Y: ");
Serial.print(yValue);
Serial.print(" Button: ");
Serial.println(buttonState == LOW ? "Pressed" : "Released");
const char text[] = "Hello from Nano!";
radio.write(&text, sizeof(text));
Serial.println("Message Sent");
delay(1000); // 1 second delay
}
This code initializes the NRF24L01 module and sets up the Arduino to read the joystick's position and button state. It then sends a message wirelessly and prints the joystick values to the serial monitor.