I'm using a Firgelli micro linear actuator (http://learn.robotgeek.com/demo-code/119-arduino-linear-actuator-tutorial-button-control-of-a-small-linear-actuator.html). I'm trying to get my code so that when you press a button the actuator will increase to a set length and stay there until the button is pressed again. Right now, I can get the button to register an action but once in a while the actuator will just activate by itself, moving up and down with no input. I'm not sure why it's doing this.
//Includes
#include <Servo.h>
//Defines
#define LINEAR50PIN 9 //Linear Actuator Digital Pin
#define KNOB_PIN 0 //knob Analog Pin
//max/min pulse values in microseconds for the linear actuators
#define LINEAR50_MIN 1800 //
#define LINEAR50_MAX 1200 //
Servo LINEAR50; // create servo objects to control the linear actuators
int knobValue; //variables to hold the last reading from the analog pins
int linear50Value = 180; //current positional value being sent to the linear actuator.
int speed = 10;
void setup()
{
//initialize servos
LINEAR50.attach(LINEAR50PIN, LINEAR50_MIN, LINEAR50_MAX); // attaches/activates the linear actuator as a servo object
//Analog pins do not need to be initialized
//use the writeMicroseconds to set the linear actuators to their default positions
LINEAR50.writeMicroseconds(linear50Value);
}
void loop()
{
/**************linear actuator Positions *******************************/
//read the values from the analog sensors
knobValue = analogRead(KNOB_PIN);
linear50Value = map(knobValue, 0, 1023, LINEAR50_MAX, LINEAR50_MIN); //Map analog value from the sensor to the linear actuator
//use the writeMicroseconds to set the servos to their new positions
LINEAR50.writeMicroseconds(linear50Value);
}