Q: Communicating over Serial to an Arduino not working? Im trying to power a 360 servo via serial commands
when I use
servo1.writeMicroseconds(1000);
the servo turns clockwise at full power, replacing 1000 with 1500 stops it, and 2000 makes it go anticlockwise.
The Serial.write(val); to debug also gives a weird answer, when I use the value of 1, the board receives it as:
--> 49
--> 10
Board is an Arduino Mega 2560
#include <Servo.h>
Servo servo1;
int val = 1500;

void setup() {
servo1.attach(7);
servo1.writeMicroseconds(val);
Serial.begin(9600); 
}

void loop(){

if(Serial.available()){ 

int val = Serial.read();
Serial.write(val);
servo1.writeMicroseconds(val);

}
} 


A: Don't use Serial.write(). It's for writing bytes. Instead use Serial.println(...) which will print a line and handle multiple input types.
Another recommendation is don't use Serial.read() for just integers. Use Serial.parseInt() as described here
