//Prosthetic Hand Prototype: 1 ~ 8/29/2023
//Using 10k ohm potentiometers to control the MG996R Servo Motors
//one servo motor for each finger
#include <Servo.h>
//Name of Servos for each finger
Servo thumb_servo; //Thumb finger ~ MG996R Servo Motor
Servo index_servo; //Index finger ~ MG996R Servo Motor
Servo middle_servo; //Middle finger ~ MG996R Servo Motor
Servo ring_servo; //Ring finger ~ MG996R Servo Motor
Servo pinky_servo; //Pinky finger ~ MG996R Servo Motor
//Name and connection to PWM pin on Arduino Uno Board
int servo_pin3= 3; //PWM pin 3 for servo control (output)
int servo_pin5 = 5; //PWM pin 5 for servo control (output)
int servo_pin6 = 6; //PWM pin 6 for servo control (output)
int servo_pin9 = 9; //PWM pin 9 for servo control (output)
int servo_pin10 = 10;//PWM pin 10 for servo control (output)
//Assigning the Potentiometer to Analog Input pins on Arduino Uno Board
int potPin1 = A0; //To control the Thumb motor
int potPin2 = A1; //To control the Index motor
int potPin3 = A2; //To control the Middle motor
int potPin4 = A3; //To control the Ring motor
int potPin5 = A4; //To control the Pinky motor
void setup(){
//when you want to output some information from your Arduino to your computer screen
Serial.begin(9600);
//Assigning the PWM pin to the named Servos
thumb_servo.attach(servo_pin3);
index_servo.attach(servo_pin5);
middle_servo.attach(servo_pin6);
ring_servo.attach(servo_pin9);
pinky_servo.attach(servo_pin10);
}
void loop(){
//Controlling Thumb Finger Motor
int reading1 = analogRead(potPin1);
int angle1 = map(reading1,0,1023, 0, 180);
thumb_servo.write(angle1);
//Controlling Index Finger Motor
int reading2 = analogRead(potPin2);
int angle2 = map(reading2,0,1023, 0, 180);
index_servo.write(angle2);
//Controlling Middle Finger Motor
int reading3 = analogRead(potPin3);
int angle3 = map(reading3,0,1023, 0, 180);
middle_servo.write(angle3);
//Controlling Ring Finger Motor
int reading4 = analogRead(potPin4);
int angle4 = map(reading4,0,1023, 0, 180);
ring_servo.write(angle4);
//Controlling Pinky Finger Motor
int reading5 = analogRead(potPin5);
int angle5 = map(reading5,0,1023, 0, 180);
pinky_servo.write(angle5);
//Serial.println("Potentiometer:");
//Serial.println(angle2);
}