..... except for powering the servos from the Arduino 5V pin, that's not good at all.
What you'll find with the code you have there, and which may or may not be a problem in your application, is that when you let go of the joystick the servos will centre. That may or may not be what you want.
There's a technique put forward by Delta_G in Reply #12 here, which uses the joystick position to be the servo direction not position. So when you let go, the mid-point of the joystich rather than centering the servo, leaves it where it was. Works very well, quite cunning.
manor_royal:
..... except for powering the servos from the Arduino 5V pin, that's not good at all.
What you'll find with the code you have there, and which may or may not be a problem in your application, is that when you let go of the joystick the servos will centre. That may or may not be what you want.
There's a technique put forward by Delta_G in Reply #12 here, which uses the joystick position to be the servo direction not position. So when you let go, the mid-point of the joystich rather than centering the servo, leaves it where it was. Works very well, quite cunning.
I just came back to post here to ask the question you just answered!
I'm going to follow your link and try to make this work!
Re: Powering the servos from the Arduino 5V pin ... how to resolve this issue you're pointing out?
I copied and pasted a code I found on here to allow my Pan/Tilt to respond to my thumb joystick movements and NOT return to neutral when I release the joystick.
In other words, as it stands now, I have to hold the joystick in a certain X,Y position for the Pan/Tilt to stay at that position.
Is it possible to get the Servos (2 of them) to move to the desired position and then STOP in that position when I release the thumb joystick?
I.e. I press and hold "left" till my pan reaches my actor and I release the joystick and it stays in that spot.
My current code is below. ANY HELP is appreciated!!!
// letsarduino.com
// [Project 11] - 2 Servos Using a Joystick
// (thumbstick) + Arduino
#include <Servo.h>
int ServoHorizontalPin = 3;
int ServoVerticalPin = 4;
int HorizontalPotPin = A0;
int VerticalPotPin = A1;
int ServoH_Min = 0;
int ServoH_Max = 180;
int ServoV_Min = 0;
int ServoV_Max = 180;
Servo HorizontalServo;
Servo VerticalServo;
int HorizontalPotValue;
int HorizontalServoPosition;
int VerticalPotValue;
int VerticalServoPosition;
void setup()
{
HorizontalServo.attach(ServoHorizontalPin);
VerticalServo.attach(ServoVerticalPin);
}
void loop()
{
HorizontalPotValue = analogRead(HorizontalPotPin);
VerticalPotValue = analogRead(VerticalPotPin);
HorizontalServoPosition = map(HorizontalPotValue, 0, 1023, ServoH_Min , ServoH_Max);
VerticalServoPosition = map(VerticalPotValue, 0, 1023, ServoH_Min , ServoH_Max);
HorizontalServo.write(HorizontalServoPosition);
VerticalServo.write(VerticalServoPosition);
delay(20);
}
Unfortunately, I'm too unfamiliar with code to implement the linked code into my Arduino Uno.
I'm not sure if I totally delete my code and just enter this new code in and then BOOM BAM, its ready to go?
Obviously I somehow have to tell the Uno where my 2 servo leads are connected so deleting my entire code would delete this information ... at least I think this is correct.
I'm still new to all this ... sorry for the noob Q's.
Connect joystick gnd directly to gnd of UNO, not the protoboard. (there are two gnd sockets on the UNO)
Servo current in the protoboard will possibly cause interference with joystick performance.
Tom..