2 Simple Motor with variable spped from pot input
4 This sketch use a transistor and a diode
5 in order to poer a 5v ~150mAh directly from the board.
6 Hard thing is to find a suitable motor!
9 This version uses a pot as throttle control,
12 Optimized for a minimum throttle value in order to keep the motor off
15 const int analogInPin = A0;
16 const int motorPin = 9;
20 const int minMotValue = 50 ; // Minimum power requiement of my own motr,
21 // This is going to differ from motor to motor
24 pinMode(motorPin, OUTPUT);
25 Serial.begin(9600); // Debuggin
29 potValue = analogRead(analogInPin);
30 motValue = potValue / 4 ; // Simple mapping 1024 -> 255
32 if (motValue > minMotValue) { // Minimum motor spped check
33 analogWrite(motorPin,motValue); // Change the PWM speed of the motor
35 analogWrite(motorPin,LOW) ;
39 Serial.print("Pot value = " );
40 Serial.print(potValue);
41 Serial.print("\t Motor speed = ");
42 Serial.println(motValue);
43 delay(3); // Pause, helps to stabilize the input,
44 // slows the serial output