element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum In need of assistance please
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 8 replies
  • Answers 2 answers
  • Subscribers 412 subscribers
  • Views 903 views
  • Users 0 members are here
  • x
  • joysticks
  • y
  • 2
  • servos
  • and
  • axis
  • arduino
  • 4
  • z
Related

In need of assistance please

Former Member
Former Member over 12 years ago

Hello - Tony here, and I am a totally new person to the whole arduino world.

First my project, my equipment, why I decided to use arduino, what I am attemting to do, a Fritzing diagram, the code I am using, and a Fritzing diagram (jpg format).

 

My project is relatively simple; the ability to pan and tilt 2 cameras that weight .06 ounce.  The cameras are being used to record the weather.  The programming below works, but the problem I am having is that the servos return to the zero (or do we call it the 90° location) when I release the joystick.  The joysticks I am using are the same type used in the Playstation 2 game pads.  They allow for a Z axis which for me, I would like to use as a way to keep a camera pointed in the direction I last positioned it to, until the time I wish to pan or tilt it to a different axis.  I hope I explained it clearly.  Lastly I do not want to use wireless, I wish to have it hard wired as I believe it will cause less interference by other radio frequencies in my area.

 

My equipment or components are as follows:

     Arduino UNO board

     Bread board

     Circuit board

     2 Joysticks (Playstation 2 style with X, Y and Z axis)

     4 TowerPro servo motors SG5010

 

I decided to use arduino, because it was recommended to me by computer / electronic shop personnel.  I have no prior knowledge of coding arduino or any other type of programming.  I was however able to take coding for 1 joystick and 2 servos, and expand it to include an additional joystick and 2 additional servos.  So as stated, I have coding for 4 servos and 2 joysticks, I just cannot and do not understand what I need to do in order to get the Z axis enabled to do what I stated above.

I have included the Fritzing diagram in jpg format so that it may be easier to understand what I have going on.  I apologize to those that are more experienced, that I bring this here, but I really am in need of assistance.

 

The coding:

 

#include <Servo.h>

 

const int servo1 = 3;        // first servo

const int servo2 = 11;      // second servo

const int servo3 = 6;        // third servo

const int servo4 = 10;     // fourth servo

const int joyH = 3;           // L/R Parallax Thumbstick

const int joyV = 4;           // U/D Parallax Thumbstick

const int joyI = 1;             // L/R Parallax Thumbstick

const int joyW = 2;          // U/D Parallax Thumbstick

 

 

int servoVal;           // variable to read the value from the analog pin

 

Servo myservo1;  // create servo object to control a servo

Servo myservo2;  // create servo object to control a servo

Servo myservo3;  // create servo object to control a servo

Servo myservo4;  // create servo object to control a servo

 

 

 

 

void setup() {

 

   // Servo 

   myservo1.attach(servo1);  // attaches the servo

   myservo2.attach(servo2);  // attaches the servo

   myservo3.attach(servo3);  // attaches the servo

   myservo4.attach(servo4);  // attaches the servo

 

   // Inizialize Serial

   Serial.begin(9600);

}

 

 

void loop(){

 

     // Display Joystick values using the serial monitor

     outputJoystick();

 

     // Read the horizontal joystick value  (value between 0 and 1023)

     servoVal = analogRead(joyH);         

     servoVal = map(servoVal, 0, 1023, 0, 179);      // scale it to use it with the servo (result  between 0 and 179 to keep from being jittery)

myservo2.write(servoVal);                          // sets the servo position according to the scaled value   

 

     // Read the horizontal joystick value  (value between 0 and 1023)

     servoVal = analogRead(joyV);          

     servoVal = map(servoVal, 0, 1023, 0, 179);      // scale it to use it with the servo (result  between 0 and 179 to keep from being jittery)

     myservo4.write(servoVal);                           // sets the servo position according to the scaled value

 

     // Read the horizontal joystick value  (value between 0 and 1023)

     servoVal = analogRead(joyI);          

     servoVal = map(servoVal, 0, 1023, 0, 179);      // scale it to use it with the servo (result  between 0 and 179 to keep from being jittery)

     myservo1.write(servoVal);                           // sets the servo position according to the scaled value

 

     // Read the horizontal joystick value  (value between 0 and 1023)

     servoVal = analogRead(joyW);          

     servoVal = map(servoVal, 0, 1023, 0, 179);      // scale it to use it with the servo (result  between 0 and 179 to keep from being jittery)

     myservo3.write(servoVal);                           // sets the servo position according to the scaled value

 

     delay(15);                                       // waits for the servo to get there

 

}

 

 

/**

* Display joystick values

*/

void outputJoystick(){

 

     Serial.print(analogRead(joyH));

     Serial.print ("---");

     Serial.print(analogRead(joyV));

     Serial.println ("----------------");

     Serial.print(analogRead(joyI));

     Serial.print ("---");

     Serial.print(analogRead(joyW));

     Serial.println ("----------------");

 

}

 

 

Thanks for taking the time to help me.  I do appreciate it.

 

Tony

Attachments:
image
  • Sign in to reply
  • Cancel

Top Replies

  • cookieglitch
    cookieglitch over 12 years ago +2 suggested
    If I'm reading this correctly, the problem you are having is that the servos jump back to zero (or 90 or the start position or the default position, whatever you wish to call it.) when you release the…
  • mcb1
    mcb1 over 12 years ago in reply to Former Member +1
    Tony Randazzo wrote: 41 views? and not one person has responded? Tony Your title didn't really give many clues as to the nature or complexity of your problem. There are a very large number of members,…
  • Former Member
    Former Member over 12 years ago in reply to billabott +1
    Hi Bill sorry it took so long to respond back, have been away from the computer. I appreciate your input and have taken your advise on naming the parts Tony P.S. the aka 44 too funny
Parents
  • Former Member
    0 Former Member over 12 years ago

    41 views? and not one person has responded?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to Former Member

    Tony Randazzo wrote:

     

    41 views? and not one person has responded?

    Tony

    Your title didn't really give many clues as to the nature or complexity of your problem.

    There are a very large number of members, some of whom are checking if they are having the same problem.

     

    Not everyone is confident enough to offer advice on what is a resonably complex issue, so yes 43 views without a reply isn't unreasonable.

     

    On the flip side, I note two very good suggestions have been made, without reply.

     

    Johns reply looks very useful for a number of people, and easy to follow.

    I need to keep that one somewhere to implement in the future, so thanks John you've saved me some work.

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to mcb1

    Hi Mark, thanks for your input..I did actually take into account what you said...I guess from what I have heard about element14.com forums, response are quick...but really how quick is quick, you know image.  I do apologize to all for my statement.  I also would again like to thank everyone that is assisting me on this...It is very much appreciated, I have been away from the PC for a few.

     

    Respectfully,

     

    Tony

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 12 years ago in reply to mcb1

    Hi Mark, thanks for your input..I did actually take into account what you said...I guess from what I have heard about element14.com forums, response are quick...but really how quick is quick, you know image.  I do apologize to all for my statement.  I also would again like to thank everyone that is assisting me on this...It is very much appreciated, I have been away from the PC for a few.

     

    Respectfully,

     

    Tony

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube