int motorPin = 3; // set the pin that controls the motor. this is the one that attachs to the resistor void setup() { pinMode(motorPin, OUTPUT); Serial.begin(9600); // open the serial monitor so that you can input the speed value while (! Serial); Serial.println("Speed 0 to 255"); } void loop() { if (Serial.available()) // as long as the Serial monitor is available, enter the motor speed { int speed = Serial.parseInt(); if (speed >= 0 && speed <= 255) // check to make sure that the value entered falls in the actual range { analogWrite(motorPin, speed); // this writes the speed value to the motor, causing it to rotate } } }