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



