Uploaded by Gintoki Sakata

Me Arm Robot Arm

advertisement
Me Arm Robot Arm
Servos must be calibrated and tested
Use 4 servo (metal head ones recommended )
#include <Servo.h>
// Define the servos
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
// Define the
int pot1Pin =
int pot2Pin =
int pot3Pin =
potentiometers
A0;
A1;
A2;
// Define the joystick pins
int joystickXPin = A3;
int joystickYPin = A4;
// Variables to store the potentiometer and joystick values
int pot1Value;
int pot2Value;
int pot3Value;
int joystickXValue;
int joystickYValue;
void setup() {
// Attach the servos to their PWM pins
servo1.attach(9);
servo2.attach(10);
servo3.attach(11);
servo4.attach(6);
}
void loop() {
// Read the values of the potentiometers and map them to servo angles
pot1Value = analogRead(pot1Pin);
int servo1Angle = map(pot1Value, 0, 1023, 0, 180);
pot2Value = analogRead(pot2Pin);
int servo2Angle = map(pot2Value, 0, 1023, 0, 180);
pot3Value = analogRead(pot3Pin);
int servo3Angle = map(pot3Value, 0, 1023, 0, 180);
// Read the values of the joystick and map them to servo angles
joystickXValue = analogRead(joystickXPin);
int servo4AngleX = map(joystickXValue, 0, 1023, 0, 180);
joystickYValue = analogRead(joystickYPin);
int servo4AngleY = map(joystickYValue, 0, 1023, 0, 180);
// Set the servo positions based on the mapped values
servo1.write(servo1Angle);
servo2.write(servo2Angle);
servo3.write(servo3Angle);
servo4.write(servo4AngleX); // Use the X axis of the joystick to control the
fourth servo
delay(5);
}
Download