int motorPin = 3; int speed=200; void setup() { pinMode(motorPin, OUTPUT); Serial.begin(9600); while (! Serial); Serial.println("Enter a speed from 1 to 255 | Write 256 to STOP"); } void loop() { if (Serial.available()) { int get_serial = Serial.parseInt(); if (get_serial > 0 && get_serial <= 255) { speed=get_serial; analogWrite(motorPin, speed); Serial.println(get_serial); } if (get_serial == 256) { analogWrite(motorPin, 0); Serial.println("STOP"); } } }