Noob. How to connect 2 servos andy Thumb Joystick

I'm brand new to Arduino. Excuse my lack of knowledge.

I'm attempting to build a Pan/Tilt module to my jib.

I purchased an Arduino UNO and 2 servo motors as well as a Thumb Joystick
https://www.osepp.com/electronic-modules/sensor-modules/67-joystick-module

I also purchased a power supply (4 AA batteries) that hook up to the Arduino.

I'm trying to use the X axis for PAN and Y axis for tilt.

Is it even possible to hookup 2 servos and a Thumb Joystick to control the 2 servos?

If so ... could someone point me in the right direction on how to do so?

I have searched the web and found some conflicting results.

ANY help is appreciated and any directions on hookup as well as Arduino code is appreciated.

thanks!

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

Have you tried any code?
If you look in the IDE
Files
Examples
Servo

You will find some sample code to try.

Thanks.. Tom.. :slight_smile:

So I found this and got it to work.

[code]
// 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(10);    
}

[/code]

Here's my hookup

First off ... am I on the right track?

Hookup looks good. Check out the map() function to map the values you get from the analog input to the values the servos want to see.

0..1023 -> 0..180

This will do it in about 4-5 lines of code. The stuff you have looks too complicated to me.

-jim lee

jimLee:
Hookup looks good.

..... 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?

Is this correct?

Pan-Tilt Arduino 1_bb.pdf (619 KB)

Hi,
The gnd (-ve) of both supplies need to be connected together so you have a gnd reference for the servo signal.

Tom... :slight_smile:

Like so?

Pan-Tilt Arduino 2_bb.pdf (602 KB)

dallaskruse:
Like so?

Yep

Thanks so much.

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);    
}

Thanks for the reply. Much appreciated.

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.

Hi,
OPs picture.

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.. :slight_smile:

Tom, thanks for the pointers!

I just got back from my root canal and am going to try and get this thing to work properly!

I appreciate all the help thus far for this beginner.