Skip to content

Instantly share code, notes, and snippets.

@hhayley
Last active May 8, 2018 12:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhayley/2fba1662c896e23fd758643a9463ab43 to your computer and use it in GitHub Desktop.
Save hhayley/2fba1662c896e23fd758643a9463ab43 to your computer and use it in GitHub Desktop.
/*
Actuonix PQ12 Micro Linear actuator with Arduino
https://www.robotshop.com/en/firgelli-technologies-pq12-actuator-12v-pot.html
H-Bridge(L293NE) / 12v power supply
potentiometer (P+->5V / P->A0 / P-->GND)
M+, M- -> motor pins
~D9 : Enable pin (control speed)
D10,11 : motor control pins
by Hayeon Hwang (03/04/2018)
*/
int speedPin = 9; // H-bridge enable pin for speed control
int motor1APin = 10; // H-bridge leg 1
int motor2APin = 11; // H-bridge leg 2
int ledPin = 13; // status LED
int positionfeed = 0;
int speed_value; // value for motor speed
int targetpos = 600;
void setup() {
// set digital i/o pins as outputs:
pinMode(speedPin, OUTPUT);
pinMode(motor1APin, OUTPUT);
pinMode(motor2APin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(speedPin, HIGH);
Serial.begin(9600);
}
void loop() {
positionfeed = analogRead(A0);
// Serial.println(positionfeed);
int error = targetpos - positionfeed;
digitalWrite(ledPin, HIGH); // status LED is always on
// if (positionfeed > 900) {
// digitalWrite(motor1APin, LOW); // set leg 1 of the H-bridge high
// digitalWrite(motor2APin, HIGH);
// } else if (positionfeed < 50){
// digitalWrite(motor1APin, HIGH); // set leg 1 of the H-bridge high
// digitalWrite(motor2APin, LOW);
// }
Serial.println(error);
if (error < -5) {
digitalWrite(motor1APin, LOW); // set leg 1 of the H-bridge high
digitalWrite(motor2APin, HIGH);
} else if (error > targetpos - 50) {
digitalWrite(motor1APin, HIGH); // set leg 1 of the H-bridge high
digitalWrite(motor2APin, LOW);
}
speed_value_motor1 = 100; // half speed
analogWrite(speedPin, speed_value); // output speed as
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment