#include Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created // variable to store the servo position float angle = 0; int inbyte = 0; // String inputString = ""; // a string to hold incoming data boolean stringComplete = false; // whether the string is complete void setup() { Serial.begin(9600); myservo.attach(9); // attaches the servo on pin 9 to the servo object myservo.write(angle); //pinMode(A0,INPUT); Serial.print("enter angle \n"); //angle.reserve(4); establishContact(); } void loop() { if(stringComplete) { Serial.println(angle); //angle = int(angle); myservo.write(angle); //Serial.print(angle); delay(1000); angle = 0; stringComplete = false; } } void establishContact() { while (Serial.available() <= 0) { Serial.println("0,0,0"); // send an initial string delay(500); } } void serialEvent() { while (Serial.available()) { // get the new byte: double inChar = Serial.read() ; // add it to the inputString: // inputString += inChar; if (inChar != '\n') { Serial.print("inchar ="); Serial.println(inChar); inChar = inChar - '0'; angle = angle*10 + (inChar); Serial.print("angle ="); Serial.println(angle); stringComplete = false; // if the incoming character is a newline, set a flag // so the main loop can do something about it: } else { stringComplete = true; } } }