/* Robotic hand 6 servos operation by NARP (Noor Ahmed Raza Pirwani while doing FAB diploma from FABLAB Khairpur noorahmedpirwani@gmail.com) This code is designed to run the Robotic hand which has 6 servos. The code requires motor calbrating code by NARP to set intial positions of motors. After setting initial positions, in void setup set the pins of motors. The code is working when it gets instruction from serial (we are using bluetooth device along to get instruction from serial). The code has no right issues so feel free to use it. */ #include char val; // variable to receive data from the serial port Servo a_servo; // create servo object to control a servo Servo b_servo; // create servo object to control a servo Servo c_servo; // create servo object to control a servo Servo d_servo; // create servo object to control a servo Servo e_servo; // create servo object to control a servo Servo f_servo; // create servo object to control a servo int pos_a = 10; // variable to store the servo position int pos_b = 10; // variable to store the servo position int pos_c = 10; // variable to store the servo position int pos_d = 10; // variable to store the servo position int pos_e = 10; // variable to store the servo position int pos_f = 10; // variable to store the servo position void setup() { a_servo.attach(3); // attaches the servo on pin 9 to the servo object a_servo.write(pos_a); b_servo.attach(5); // attaches the servo on pin 9 to the servo object b_servo.write(pos_b); c_servo.attach(6); // attaches the servo on pin 9 to the servo object c_servo.write(pos_c); d_servo.attach(9); // attaches the servo on pin 9 to the servo object d_servo.write(pos_d); e_servo.attach(10); // attaches the servo on pin 9 to the servo object e_servo.write(pos_e); f_servo.attach(11); // attaches the servo on pin 9 to the servo object f_servo.write(pos_f); Serial.begin(9600); // start serial communication at 9600bps } void loop() { if( Serial.available() ) // if data is available to read { val = Serial.read(); // read it and store it in 'val' } if( val == 'A' ) { // if 'A' was received if( pos_a < 165 ) { // goes from 0 degrees to 180 degrees // in steps of 1 degree pos_a =pos_a+5; a_servo.write(pos_a); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'a' ) { // if 'a' was received if( pos_a > 15 ) { // goes from 180 degrees to 0 degrees // in steps of 1 degree pos_a =pos_a-5; a_servo.write(pos_a); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'B' ) { // if 'B' was received if( pos_b < 165 ) { // goes from 0 degrees to 180 degrees // in steps of 1 degree pos_b =pos_b+5; b_servo.write(pos_b); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'b' ) { // if 'b' was received if( pos_b > 15 ) { // goes from 180 degrees to 0 degrees // in steps of 1 degree pos_b =pos_b-5; b_servo.write(pos_b); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'C' ) { // if 'C' was received if( pos_c < 165 ) { // goes from 0 degrees to 180 degrees // in steps of 1 degree pos_c =pos_c+5; c_servo.write(pos_c); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'c' ) { // if 'c' was received if( pos_c > 15 ) { // goes from 180 degrees to 0 degrees // in steps of 1 degree pos_c =pos_c-5; c_servo.write(pos_c); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'D' ) { // if 'D' was received if( pos_d < 165 ) { // goes from 0 degrees to 180 degrees // in steps of 1 degree pos_d =pos_d+5; d_servo.write(pos_d); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'd' ) { // if 'd' was received if( pos_d > 15 ) { // goes from 180 degrees to 0 degrees // in steps of 1 degree pos_d =pos_d-5; d_servo.write(pos_d); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'E' ) { // if 'E' was received if( pos_e < 165 ) { // goes from 0 degrees to 180 degrees // in steps of 1 degree pos_e =pos_e+5; e_servo.write(pos_e); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'e' ) { // if 'e' was received if( pos_e > 15 ) { // goes from 180 degrees to 0 degrees // in steps of 1 degree pos_e =pos_e-5; e_servo.write(pos_e); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'F' ) { // if 'E' was received if( pos_f < 165 ) { // goes from 0 degrees to 180 degrees // in steps of 1 degree pos_f =pos_f+5; f_servo.write(pos_f); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } else if( val == 'f' ) { // if 'e' was received if( pos_f > 15 ) { // goes from 180 degrees to 0 degrees // in steps of 1 degree pos_f =pos_f-5; f_servo.write(pos_f); // tell servo to go to position in variable 'pos' delay(10); // waits 15ms for the servo to reach the position } } val='0';