continuos servo+joystick+potentiometer?

Hi to all!
i just need to control the speed of my continuos 360 servo, the joystick is good because i can control the movements left or right, but now i would like to add a potentiometer to control the speed! Could somebody help me adding the code to my sketch?

// Arduino 07 -  Servo, Serial Monitor, and Joystick
//
//This program controls a servo motor continuously 
//according to the input provided from a joystick
//and shows joystick input and output to servo on the screen 
//of an attached computer, via the Arduino Serial Monitor.
// ---------------------------------------------------------------------------

#include <Servo.h>
#define SERVO_PIN 9
#define GROUND_JOY_PIN A3            //joystick ground pin will connect to Arduino analog pin A3
#define VOUT_JOY_PIN A2              //joystick +5 V pin will connect to Arduino analog pin A2
#define XJOY_PIN A1                  //X axis reading from joystick will go into analog pin A1
Servo myservo ;

void setup() 
{
  Serial.begin(9600);
  pinMode(VOUT_JOY_PIN, OUTPUT) ;    //pin A3 shall be used as output
  pinMode(GROUND_JOY_PIN, OUTPUT) ;  //pin A2 shall be used as output
  digitalWrite(VOUT_JOY_PIN, HIGH) ; //set pin A3 to high (+5V)
  digitalWrite(GROUND_JOY_PIN,LOW) ; //set pin A3 to low (ground)
  myservo.attach(9); 
}

void loop() 
{
  delay(300);                    
  int joystickXVal = analogRead(XJOY_PIN) ;  //read joystick input on pin A1
  Serial.print(joystickXVal);                //print the value from A1
  Serial.println(" = input from joystick");  //print "=input from joystick" next to the value
  Serial.print((joystickXVal+520)/10);       //print a from A1 calculated, scaled value
  Serial.println(" = output to servo");      //print "=output to servo" next to the value
  Serial.println() ;
myservo.write(((joystickXVal+570)/10)-13);      //write the calculated value to the servo  
}

You are already controlling the speed of the servo with the joystick.

but when i touch the joystick the servo starts to go faster..i just need to reduce or modulate the speed..because some times could be ok to go faster, but in other occasions i need to go slower!

So, you want the potentiometer to define a ratio, which you then apply to the joystick-derived value.

That's pretty easy.

   int aVal = analogRead(somePin);
   float rat = aVal / 1023;

   myservo.write((aVal*((joystickXVal+570)/10)-13));

thanks!!
where i have to add this code? Or i need to delete some string on mi code before add this?

Don't you recognize the myservo.write() statement?

i tried to join your code to mine but doesn't work..i assigned A0 as potpin but nothing happen..can you please post me the complete code with your changes? thanksss

So show us what you tried, including a diagram of how everything is connected, and we'll help you make it work. But we don't usually just write the complete program for you...you'll never learn anything like that.

Steve

robyr1, I think there are some things that you are not picking up.

  1. a Joystick is a potentiometer. You are already reading its value. You are already sending various values to the servo.

  2. continuous rotation servos often have little speed control. This varies by make and model. Some have a little speed control, and many have virtually no speed control.

The best way to determine how your servo behaves is with the knob tutorial. You can even use your joystick as the pot in the tutorial.

thanks guys! with a simple potentiometer and without the joystick the servo starts to rotate itself but i can set the speed..the problem is with a joystick only, i don't know how to add the code of the potentiometer and tune it..

could somebody help me?

Answer the questions in reply #7 first.

here is the diagram, the code i posted above!

You just said that with a simple potentiometer it controls the speed. Where is the code that does that?

You also said that you tried to include the code that PaulS provided for you but you haven't posted that attempt either.

Your diagram doesn't show any potentiometer just a servo and joystick.

We're not going to be able to help you if you just ignore everything anyone suggests or asks.

Steve

I posted my code above! with this code i can control the 360 servo with a joystick, my question about the code of PaoulS is: where shoud i have to add his code with mine? and also i don't understand wich pin pot i have to use!

Post the code that worked using a potentiometer.

You can modify that to show the range of values you get out of the pot.
Then you can run similar code to show the range of values you get out of the joystick.
Once you have those 2 ranges, you can change the values used in the map() function and your joystick should provide the same behavior as the pot.

robyr1:
I posted my code above! with this code i can control the 360 servo with a joystick, my question about the code of PaoulS is: where shoud i have to add his code with mine? and also i don't understand wich pin pot i have to use!

You have one line of code that controls the servo. Replace that one line with the 4 lines of code I posted.

Connect the pot to whichever analog pin makes your heart go pitter-patter. Just use that same pin number in the analogRead() call.

PaulS:
You have one line of code that controls the servo. Replace that one line with the 4 lines of code I posted.

Connect the pot to whichever analog pin makes your heart go pitter-patter. Just use that same pin number in the analogRead() call.

Thanks PaulS, tried to follow your suggestions, can you please take a look to this code?

// Arduino 07 -  Servo, Serial Monitor, and Joystick
//
//This program controls a servo motor continuously 
//according to the input provided from a joystick
//and shows joystick input and output to servo on the screen 
//of an attached computer, via the Arduino Serial Monitor.
// ---------------------------------------------------------------------------

#include <Servo.h>
#define SERVO_PIN 9
#define GROUND_JOY_PIN A3            //joystick ground pin will connect to Arduino analog pin A3
#define VOUT_JOY_PIN A2              //joystick +5 V pin will connect to Arduino analog pin A2
#define XJOY_PIN A1                  //X axis reading from joystick will go into analog pin A1
Servo myservo ;

void setup() 
{
  Serial.begin(9600);
  pinMode(VOUT_JOY_PIN, OUTPUT) ;    //pin A3 shall be used as output
  pinMode(GROUND_JOY_PIN, OUTPUT) ;  //pin A2 shall be used as output
  digitalWrite(VOUT_JOY_PIN, HIGH) ; //set pin A3 to high (+5V)
  digitalWrite(GROUND_JOY_PIN,LOW) ; //set pin A3 to low (ground)
  myservo.attach(9); 
}

void loop() 
{
  delay(300);                    
  int joystickXVal = analogRead(XJOY_PIN) ;  //read joystick input on pin A1
  Serial.print(joystickXVal);                //print the value from A1
  Serial.println(" = input from joystick");  //print "=input from joystick" next to the value
  Serial.print((joystickXVal+520)/10);       //print a from A1 calculated, scaled value
  Serial.println(" = output to servo");      //print "=output to servo" next to the value
  Serial.println() ;
   int aVal = analogRead(A0);
   float rat = aVal / 1023;

   myservo.write((aVal*((joystickXVal+570)/10)-13));
 }

but doesn't work good because the servo now turns continuosly..and i lost the control of it!

Maybe try changing the aVal in the write() to rat instead.

Steve

Nothing! i tried to change into "rat", but i still have the same problem: the servo turns it self!

#include <Servo.h>



// Arduino 07 -  Servo, Serial Monitor, and Joystick
//
//This program controls a servo motor continuously 
//according to the input provided from a joystick
//and shows joystick input and output to servo on the screen 
//of an attached computer, via the Arduino Serial Monitor.
// ---------------------------------------------------------------------------

#include <Servo.h>
#define SERVO_PIN 9
#define GROUND_JOY_PIN A3            //joystick ground pin will connect to Arduino analog pin A3
#define VOUT_JOY_PIN A2              //joystick +5 V pin will connect to Arduino analog pin A2
#define XJOY_PIN A1                  //X axis reading from joystick will go into analog pin A1
Servo myservo ;

void setup() 
{
  Serial.begin(9600);
  pinMode(VOUT_JOY_PIN, OUTPUT) ;    //pin A3 shall be used as output
  pinMode(GROUND_JOY_PIN, OUTPUT) ;  //pin A2 shall be used as output
  digitalWrite(VOUT_JOY_PIN, HIGH) ; //set pin A3 to high (+5V)
  digitalWrite(GROUND_JOY_PIN,LOW) ; //set pin A3 to low (ground)
  myservo.attach(9); 
}

void loop() 
{
  delay(300);                    
  int joystickXVal = analogRead(XJOY_PIN) ;  //read joystick input on pin A1
  Serial.print(joystickXVal);                //print the value from A1
  Serial.println(" = input from joystick");  //print "=input from joystick" next to the value
  Serial.print((joystickXVal+520)/10);       //print a from A1 calculated, scaled value
  Serial.println(" = output to servo");      //print "=output to servo" next to the value
  Serial.println() ;
   int aVal = analogRead(A0);
   float rat = aVal / 1023;

   myservo.write((rat*((joystickXVal+570)/10)-13));
 }