Coding help required for a new coder

Hi everyone,

I am working on a cool project and haven't used Arduino before, so any and all help would be appreciated.

I'm creating a 2-axis, joystick-controlled with 2 digital outputs over 2.4ghz control to power 2x 12v DC motors. I will use either PWM or RS232 control to drive the Sabertooth regenerative dual motor driver. The Arduino nano R3 is connected to a Sabertooth 2x32 set for either serial or analog control.

Diagram flowchart:
Joy stick and two digital inputs/Nano R3 -> 2.4ghz wireless Tx -> Rx 2.4ghz Nano R3 -> Sabertooth motor drive board -> 2x 12vdc motor as axis.

Does anybody have any code that could help me get started with this project?

Thank you for your help!

Which 2.4Ghz radio modules?
I’d start with them. Get a very simple relay system working. Press a button one end, light a LED the other.
Step 2, add the joysticks as input.
Step 3, add the motors as outputs.

Thanks for the reply!

The 2.4ghz relay is an automation bros. Wireless Module with Antenna (NRF24L01+PA+LNA) 1000 Meters Long Distance
(Wireless Module with Antenna (NRF24L01+PA+LNA) 1000 Meters Long Distance | eBay)

Appreciate the suggestions, I am having trouble developing a simple relay system, is there any code you could send me to help?

For context, this is my attempt so far, but it has been frustrating to get anything to connect properly...

[size=0.8em]Code: [url=https://arduinogetstarted.com/tools/arduino-code-highlighter]see how to post code[/url] [/size]

---



```
[size=0.8em]/* Transmitter Code
  Code to read Joystick position and transmit it with a RF24L01+ to a receiver
*/

#include <SPI.h>
#include <RF24.h>

// Radio Configuration

RF24 radio(9, 10);
byte addresses[][6] = {"1Node", "2Node"};
bool radioNumber = 1;
bool role = 1;  //Control transmit 1/receive 0

// Decide where you are going to plug the joystick into the circuit board.

int UpDown_Pin = 0;        // Plug Joystick Up/Down into Analog pin 0
int LeftRight_Pin = 1;      // Plug Joystick Left/Right into Analog pin 1

// Create variables to read joystick values

float UpDown_Input ;      // Variable to store data for Up/Down input from joystick
float LeftRight_Input ;    // Variable to store data for for Left/Right input from joystick

// Create variables to transmit servo value

int UpDown_Output;      // Expected range 0 - 1023
int LeftRight_Output;    // Expected range 0 - 1023

// These variables allow for math conversions and later error checking as the program evolves.

int Up_Limit = 800;      // High ADC Range of Joystick ForeAft
int Down_Limit = 220;        // Low ADC Range of Joystick ForeAft
int Right_Limit = 800;      // High ADC Range of Joystick LeftRight
int Left_Limit = 226;      // Low ADC Range of Joystick LeftRight

// constants won't change. They're used here to set pin numbers:
bool SpotButton = 7;
bool SpeedButton = 8;
const int SpeedLed = 4;

const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int SpotButtonState = 0;        // variable for reading the pushbutton status
int SpeedButtonState = 0;

void [color=#5E6D03]setup/color {
  // put your setup code here, to run once:
  Serial.[color=#D35400]begin/color;                  // Get ready to send data back for debugging purposes
  radio.[color=#D35400]begin/color;                        // Get the transmitter ready
  radio.setPALevel(RF24_PA_LOW);        // Set the power to low
  radio.openWritingPipe(addresses[1]);  // Where we send data out
  radio.openReadingPipe(1, addresses[0]); // Where we receive data back
  // initialize the Spotlight pin as an output:
  pinMode(SpotButton, INPUT);
  // initialize the Speed Button pin as an input:
  pinMode(SpeedButton, INPUT);
  pinMode (SpeedLed, OUTPUT);
}

void [color=#5E6D03]loop/color {
  // put your main code here, to run repeatedly:
  Serial.[color=#D35400]println/color;
  UpDown_Input = [color=#D35400]analogRead/color ;            // Read the Up/Down joystick value
  Serial.[color=#D35400]println/color;
  LeftRight_Input = [color=#D35400]analogRead/color ;        // Read the Left/Right joystick value

//  Serial.print(UpDown_Output);
  radio.stopListening();                                // Stop listening and begin transmitting
  [color=#D35400]delay/color;                                            // quite a long delay -- causes jittering of servo
  if (radio.write(&UpDown_Output, [color=#00979C]sizeof/color), Serial.println("sent UpDown"));            //Send UpDown data
  if (radio.write(&LeftRight_Output, [color=#00979C]sizeof/color), Serial.println("sent LeftRight"));      //Send LeftRight data
  radio.startListening();                                // Get ready to receive confirmation from receiver

// read the state of the pushbutton value:
  SpotButtonState = [color=#D35400]digitalRead/color;
  SpeedButtonState = [color=#D35400]digitalRead/color;

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (SpeedButtonState = HIGH)
    // turn LED on:
    digitalWrite(SpeedLed, HIGH);
  else
    // turn LED off:
    digitalWrite(SpeedLed, LOW);

}

// Function to convert and scale the Fore/Aft data

float convertUpDownToServo(float y) {
  int result;
  result = ((y - Down_Limit) / (Up_Limit - Down_Limit) * 180);
  return result;
}

// Function to convert and scale the Left / Right data
// Can be replaced with Map function
float convertLeftRightToServo(float x) {
  int result;
  result = ((x - Left_Limit) / (Right_Limit - Left_Limit) * 180);
  return result;
}[/size]
```

|

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to.

A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. The high-power nRF24s (with the external antenna) will definitely need an external power supply. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

If you have a pair of the low-power nRF24s (with the PCB antenna) I suggest you start your learning with them and leave the high-power modules (which are code compatible) for later. If you must use high-power modules make sure they are separated by at least 3 metres.

...R

PS ... When posting code please use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor See How to use the forum