Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save esimonetti/8201a9f1261cf2f5e6de to your computer and use it in GitHub Desktop.
Save esimonetti/8201a9f1261cf2f5e6de to your computer and use it in GitHub Desktop.
Control a DC motor speed with Arduino and a MOSFET - Increasing speed
const int motorpin = 5;
int motor_speed = 0;
void setup()
{
Serial.begin(57600);
pinMode(motorpin, OUTPUT);
}
void loop()
{
for(motor_speed = 0; motor_speed <= 255; motor_speed += 5)
{
printSpeed(motor_speed);
analogWrite(motorpin, motor_speed);
delay(250);
}
delay(5000);
}
void printSpeed(int motor_speed)
{
Serial.print("Current Speed: ");
Serial.println(motor_speed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment