// Filename: DC_motor_speed_control.ino // Use potentiometer input to set the speed of a DC motor // Output to the motor is PWM int motorPin = 3; // pin connected to the DC motor int potPin = 1; // analog input connected to the potentiometer void setup( ) { pinMode(motorPin, OUTPUT); } void loop( ) { int PWMoutput, potReading; potReading = analogRead(potPin); PWMoutput = map(potReading, 0, 1023, 0, 255 ); analogWrite(motorPin, PWMoutput); }