Arduino Leonardo with Motor Shield and DC motor

The Motor shield is a Velleman pka03, placed on top of the Arduino Leonardo. img

Lego piece with a smalled hole drilled through the center, attached with glue onto the metal rod of the motor. The motor is a RF-300FA-12350 which runs fine on the 5 Volt the Arduino provides. img

When an integer is entered in the Serial Monitor of the Arduino Software, the motor starts running. Maximum speed is set when 255 is entered.

void setup() {  
    Serial.begin(9600);   
    while (!Serial) {    
        ; // wait for serial port to connect. Needed for Leonardo only  
    }    
    
    pinMode(12, OUTPUT);  
    pinMode(9, OUTPUT); 
} 

void loop() {    
    // Wait until input is given.  
    if (Serial.available() > 0) {          
        
        // Read the number entered, and print it out.      
        int speed = Serial.parseInt();      
        Serial.println(speed);            
        
        // Start spinning the motor at the speed entered.      
        analogWrite(3, speed);  
    }  
    
    delay(10); 
}