Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano Based NRF24L01 Wireless Joystick Controller

View and Edit Project In Cirkit DesignerImage of Arduino Nano Based NRF24L01 Wireless Joystick Controller

Circuit Documentation

Summary

This circuit is designed to function as a 6-channel transmitter, primarily intended for remote control applications. It utilizes an Arduino Nano as the central microcontroller to process input signals from a potentiometer and two KY-023 Dual Axis Joystick Modules. These inputs are then transmitted wirelessly via an NRF24L01 module, with an NRF24L01 Adapter and an Electrolytic Capacitor to stabilize the power supply to the NRF24L01. A toggle switch is used to control the power flow, and a rocker switch is connected to an LED through a resistor to indicate the power status. The entire circuit is powered by two 3.7V batteries connected in parallel.

Component List

Wiring Details

Arduino Nano

NRF24L01 and Adapter

Electrolytic Capacitor

Potentiometer

KY-023 Dual Axis Joystick Modules

Toggle Switch

3.7V Batteries

Rocker Switch

LED (Red)

Resistor

Documented Code

// 6 Channel Transmitter
// Tutorial Video https://youtu.be/731I4PEUxWU

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t pipeOut = 0xE9E8F0F0E1LL;   //IMPORTANT: The same as in the receiver 0xE9E8F0F0E1LL
RF24 radio(9, 10); // select CE,CSN pin
struct Signal {
  byte throttle;
  byte pitch;
  byte roll;
  byte yaw;
  byte aux1;
  byte aux2;
};
Signal data;
void ResetData() 
{
  data.throttle = 12;   // Motor stop (Signal lost position)
  data.pitch = 127;     // Center (Signal lost position)
  data.roll = 127;      // Center (Signal lost position)
  data.yaw = 127;       // Center (Signal lost position)
  data.aux1 = 127;      // Center (Signal lost position)
  data.aux2 = 127;      // Center (Signal lost position)
}
void setup()
{
  radio.begin();
  radio.openWritingPipe(pipeOut);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_HIGH);
  radio.stopListening();
  ResetData();
 
}
int mapJoystickValues(int val, int lower, int middle, int upper, bool reverse)
{
  val = constrain(val, lower, upper);
  if ( val < middle )
  val = map(val, lower, middle, 0, 128);
  else
  val = map(val, middle, upper, 128, 255);
  return ( reverse ? 255 - val : val );
}
void loop()
{
  // Control Stick Calibration
  // Setting may be required for the correct values of the control levers
  data.throttle = mapJoystickValues( analogRead(A0), 12, 524, 1020, true );   // "true" or "false" for signal direction
  data.roll = mapJoystickValues( analogRead(A3), 12, 524, 1020, true );       // "true" or "false" for servo direction
  data.pitch = mapJoystickValues( analogRead(A2), 12, 524, 1020, false );     // "true" or "false" for servo direction
  data.yaw = mapJoystickValues( analogRead(A1), 12, 524, 1020, false );       // "true" or "false" for servo direction

  data.aux1 = mapJoystickValues( analogRead(A6), 12, 524, 1020, true );       // "true" or "false" for servo direction
  data.aux2 = mapJoystickValues( analogRead(A7), 12, 524, 1020, true );       // "true" or "false" for servo direction
  radio.write(&data, sizeof(Signal));
}

This code is responsible for reading the analog values from the potentiometer and joystick modules, mapping these values to a range suitable for radio transmission, and sending the structured data wirelessly using the NRF24L01 module. The ResetData function initializes the control signals to their neutral or 'signal lost' positions. The mapJoystickValues function is used to map the raw analog readings to a standardized range, with optional reversal of the signal direction. The loop function continuously reads the joystick and potentiometer values, maps them, and transmits the data.