Mando Mercs Costume Club

Mandalorian Armor => Equipment & Accessories => Electronics => Topic started by: Kurz on Dec 07, 2019, 04:52 AM

Title: Linear Actuator
Post by: Kurz on Dec 07, 2019, 04:52 AM
Ok guys, I need your help. I need linear motion and not a big fan of adapting a regular servo. Looking around I found this little guy.
(https://i.imgur.com/AzrKi6N.jpg)
Now, I would like to control it with an arduino nano, has anyone any idea on how this thing work? It has 3 pins so I suppose positive, ground and signal like every servo, but I don't know how to write the code for this one. Any help?
Title: Re: Linear Actuator
Post by: LightningLion on Dec 07, 2019, 10:56 AM
Reverse searching your image shows that white wire is for signal, yes.

Arduino Servo reference:
https://www.arduino.cc/en/Reference/Servo

Linear actuator project:
http://learn.robotgeek.com/demo-code/118-arduino-linear-actuator-tutorial-analog-direct-control-of-small-linear-actuator.html

Been a few years since I last played with servos amd I'm feeling particularly dense today but...

See the attach() reference in the first link. Servo library has a default minimum and maximum values related to 0 and 180 degrees for a rotary servo. By trial and error, using WriteMicroseconds you might define the new min and max values your lineal servo actually uses (min 1050 and max 2000 in the example)

Then you could map your desired position (0 to 20mm) with you min and max (microseconds values) as the linear example does.

Code: [Select]
//Includes
#include <Servo.h>

#define minServo 1050 //adjust to actual values
#define maxServo 2000 //adjust to actual values

int ServoPos;
int servoPin = 9; //Or whatever it is
int desiredPosition;
Servo MyServo;

void setup() {

MyServo.attach(servoPin, minServo, maxServo);

}

void loop(){

if (desiredPosition <20) {
desiredPosition++;
} else {
desiredPosition = 0;
}

servoPos = map(desiredPostion, minPos, maxPos, minServo, maxServo)

MyServo.WriteMicroseconds(servoPos)

delay(250);
}

This code should advande your servo 1mm every 250 ms until reaching 20mm, then go back to the start and repeat. You can easily write a sequence or control it with a potentiometer/slider.
Title: Re: Linear Actuator
Post by: Kurz on Dec 07, 2019, 12:38 PM
Thank you so much! I have pretty simple needs, my code will be
Push button ->max extension
Push button -> min extension
I dont think will have trouble adapting the code you kindly shared. Thank you again
Title: Re: Linear Actuator
Post by: LightningLion on Dec 07, 2019, 04:56 PM
Np. Like I said that's from the top of my head, withojt testing. Send me a PM if you find any issue.
Title: Re: Linear Actuator
Post by: Kurz on Dec 09, 2019, 07:24 AM
Thanks Lion! Little guy came in today, didn't expect it was THAT little, even though mesirements were written. Shouldn't be a problem.
(https://i.imgur.com/NYXukmX.jpg)
Title: Re: Linear Actuator
Post by: DCX13 on Dec 15, 2019, 07:11 PM
The signal wire will be the white one. Pos & Neg power are red & black, respectively.
Title: Re: Linear Actuator
Post by: Kurz on Dec 16, 2019, 02:50 AM
The signal wire will be the white one. Pos & Neg power are red & black, respectively.
Yep, that was covered, thank you. Still working on the code and waiting for the 3d print to make everything work.