Created
March 4, 2015 03:54
-
-
Save esimonetti/117e4922f8f469cc3f7b to your computer and use it in GitHub Desktop.
Control a DC motor speed with Arduino and a MOSFET - Three speeds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int motorpin = 5; | |
const int divider = 3; | |
int motor_speed = 0; | |
void setup() | |
{ | |
Serial.begin(57600); | |
pinMode(motorpin, OUTPUT); | |
} | |
void loop() | |
{ | |
for(motor_speed = 0; motor_speed <= 255; motor_speed += (int)(255/divider)) | |
{ | |
printSpeed(motor_speed); | |
analogWrite(motorpin, motor_speed); | |
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