NRF24L01+ servo hold position with joystick

I am trying to build a robot arm that holds a laser pointer and I have a code that keeps the servo from returning to center when the joystick is released but it is one single code. Does anyone have a TX and RX code that will allow the servo to hold its position when the joystick is released? I looked online but I can’t find anything. Much thanks.

What does that mean?

Post any code you have so far. Say why it doesn't work, or what more you'd like it to do.

Allowing the servo arm to do, or not do, anything is completely separate, logically, from receiving or transmitting data.

a7

Please explore this link: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum

I apologize, this is the first time I have asked for help on this forum as I am new to Arduino's. What I mean by "single code" is a single sketch. I am wanting to use a pair of Nano's with a pair of NRF24L01 +'s to control the robot arm. I need 2 sketches. One to transmit (TX) and one to receive (RX) correct? The only code I have found that will keep the servos from returning to center with the joystick is not written for the NRF24L01+'s. I'm just trying to figure out what part of the code goes to a TX sketch and the RX sketch.

#include <Servo.h> //Servos library and declaration

Servo myservo1;
Servo myservo2;

int a, b, X, Y; //Variables needed later
int YAxis = 1; //Declaring where the X axis and Y axis of the joystick pins are wired
int XAxis = 0; //Of course analog inputs

void setup() {
  Serial.begin(9600); //Setting the Serial monitor baude rate and launching
  pinMode(XAxis, INPUT); //Declaring the pin modes and servo pins
  myservo1.attach(8);
  pinMode(YAxis, INPUT);
  myservo2.attach(9);
}

void loop() {

  a = myservo1.read(); //Reading the previous servos positions is an important step so we can know where they should position next
  b = myservo2.read();
  X = analogRead(XAxis); //Reading the joystick values
  Y = analogRead(YAxis);

  if (X > 550) { //Here we didn't do any calibration so the joystick has three positions (Left|Resting|Right)
    a = a - 1; //it depends on the value we read we can know in which direction the stick is pointing and I left the resting position big actually it's just 1 value
    myservo1.write(a); //we inject the new value
    delay(50); //You can make the delay big or short or act on a=a-x to make big steps or short steps
  }
  if (X < 450) {
    a = a + 1; //Here we did the opposit operation to move to the opposit direction
    myservo1.write(a);
    delay(50);
  }
  if (Y > 600) { //Here we didn't do any calibration so the joystick has three positions (Up|Resting|Down) ditto
    b = b + 1;
    myservo2.write(b);
    delay(50);
  }
  if (Y < 450) {
    b = b - 1;
    myservo2.write(b);
    delay(50);
  }
}

I'm confused, but that's my resting state.

I suggest you leave the joystick aside, and get two Arduinos each with an NRF24L01+ taking to each other.

Even if they aren't saying much more than "Hello World!".

Getting this radio set to work has frustrated the best of the heavies. It is essential that you find and work from complete and correct example code for this.

Here's one that is poplular, google for and look at a few others and see what you learn.

NRF24L01 tutorial

Please remember, the joystick logic is an entirely separate matter from getting the radios to work.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.