I want to move my feedback linear actuator automatically without using push buttons
The stroke of linear actuator is 4 inches
The maximum analog at 4 inches is 951
The minimum analog at 0 inches is 44
so i can have maximum of just 1 inch and move it automatically to this position
I send you my code using 2 push buttons
float pos; // Actuator Position
void setup() {
pinMode(A1, INPUT); // Configure Analog In pin 1 as an Input
pinMode(10, OUTPUT); // Configure pin 10 as an Output
pinMode(11, OUTPUT); // Configure pin 11 as an Output
pinMode(2, INPUT_PULLUP); // Input for Button
pinMode(3, INPUT_PULLUP); // Input for Button
Serial.begin(9600);
}
void loop() {
if(digitalRead(2) == HIGH & digitalRead(3) == LOW){
// Retract Actuator
analogWrite(10, 0);
analogWrite(11, 255);
pos = readPotentiometer(); // Print position value to the Serial Display
Serial.println(pos);
delay(1);
}
else if(digitalRead(2) == LOW & digitalRead(3) == HIGH){
// Extend Actuator
analogWrite(10, 255);
analogWrite(11, 0);
pos = readPotentiometer();
Serial.println(pos); // Print position value to the Serial Display
delay(1);
}
else{
// Stop Actuator
analogWrite(10, 0);
analogWrite(11, 0);
}
}
/Function to Read Potentiometer and Convert it to Inches/
float readPotentiometer(void){
return analogRead(A1);
}Preformatted text