/* Robotic hand servo initial postion setting code by NARP (Noor Ahmed Raza Pirwani while doing FAB diploma from FABLAB Khairpur noorahmedpirwani@gmail.com) The code is designed to connect a motor with Arduino board while setting pin of arduino in a_servo.attach (write servo pwm pin here in code). The code is used to found the best position of robotic hand servo which I used in my another code to set initial position of motor 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 // twelve servo objects can be created on most boards int pos_a = 10; // variable to store the servo position void setup() { a_servo.attach(6); // attaches the servo on pin 9 to the servo object a_servo.write(pos_a); 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 < 170 ) { // 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 > 10 ) { // 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 } } }