esha492

DC motor with potentiometer

Oct 7th, 2017
67
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 =10;
  2. const int PotPin=A0;
  3. int PotVal=0;
  4. int Speed=0;
  5.  
  6.  
  7.  
  8. void setup ()
  9. {
  10. pinMode(MotorPin, OUTPUT);
  11. pinMode (PotPin, INPUT);
  12. Serial.begin (9600);
  13.  
  14. }
  15.  
  16. void loop()
  17. {
  18. PotVal = analogRead (PotPin);
  19.  
  20. Speed= map(PotVal, 0, 1023, 0, 255);
  21. Speed= constrain(Speed, 0, 255);
  22. Serial.println (Speed);
  23. analogWrite (MotorPin, Speed);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment