GeldenGolem

DC Motor with potentiometer

Nov 12th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. const int MotorPin = 3;
  2. const int PotPin = A0;
  3. int PotVal=0;
  4. int Speed=0;
  5.  
  6.  
  7.  
  8.  
  9. void setup()
  10. {
  11. pinMode (PotPin, INPUT);
  12. pinMode (MotorPin, OUTPUT);
  13. Serial.begin (9600);
  14.  
  15. }
  16.  
  17. void loop()
  18. {
  19.  
  20. PotVal = analogRead (PotPin);
  21. Speed = map (PotVal, 0, 1023, 0, 255);
  22. Speed= constrain (Speed, 0, 255);
  23. analogWrite (MotorPin, Speed);
  24.  
  25. }
Add Comment
Please, Sign In to add comment