Arduino Incremental Motor Speed Control
In this Arduino project you can use a single button switch to step through incremental motor speed increases. Each time you press the button the motor steps up to the next speed level for a total of 5 set speeds and stop.
hey man great vid but do u have any ideia how to save servo motion on sd
card from reading of poteintometer
and a push botton to play and another to record
//Incrementing Motor Speed Control
const int MOTOR = 9; //Motor connected to digital pin 9
const int BUTTON = 2; //Button connected to pin 2
boolean lastButton = LOW; //Variable containing the previous
//button state
boolean currentButton = LOW; //Variable containing the current
//button state
int speedIncrement = 0;
void setup()
{
pinMode (MOTOR, OUTPUT); //Set the MOTOR pin as an output
pinMode (BUTTON, INPUT); //Set button as an input
}
/*
* Debouncing Funtion
* Pass it the previous button state,
* and get back the current debounced button state.
*/
boolean debounce(boolean last)
{
boolean current = digitalRead(BUTTON); //Read the button state
if (last != current) //if it’s different
{
delay(5); //wait 5ms
current = digitalRead(BUTTON); //read it again
}
return current;
}
/*
*Motor Speed Selection
*Pass a number for the Motor speed and set it
*/
void setSpeed(int increment)
{
//speed one
if (increment == 1)
{
analogWrite(MOTOR, 110);
}
else if (increment == 2)
{
analogWrite(MOTOR, 150);
}
else if (increment == 3)
{
analogWrite(MOTOR, 180);
}
else if (increment == 4)
{
analogWrite(MOTOR, 200);
}
else if (increment == 5)
{
analogWrite(MOTOR, 255);
}
//OFF
else
{
analogWrite(MOTOR, 0);
}
}
void loop()
{
currentButton = debounce(lastButton); //read debounce state
if (lastButton == LOW && currentButton == HIGH) //if it was pressed
{
speedIncrement++; //Increment motor speed
}
lastButton = currentButton; //reset button value
//if cycled through all speed increments
//reset the speed to 0
if (speedIncrement == 6) speedIncrement = 0;
setSpeed(speedIncrement);
}
yea that what i mean
i made a robot arm controled with 5 potetnmeter with 5 servos
i wanna to add a sd card to record on it the reads of potentmeter and
replay it
well its very good to another project but not this bec i meant to use sd
card to use with other projects
thank you so much , :)