Control a Small Linear Actuator With Arduino
30,027
158
16
Featured
Introduction: Control a Small Linear Actuator With Arduino
This Arduino Linear Actuator Tutorial shows how to control a Firgelli Small Linear Actuator using an Arduino compatible board and various input sensors, including a Slider and Rotation Knob for direct control, Joystick for incremental movement, and three buttons with preset positions (preset in the code with each position assigned to a button, so when a user pushes a button the small linear actuator moves to that position).
For Arduino Linear Actuator projects the small linear actuators by Firgelli are excellent. These linear actuators have an internal controller which allows them to be operated just like a servo. By using the Arduino Servo Library we can simply send out the desired position to the actuator and it moves to the position.
Step 1: Project Parts List
All of these parts can be found together in the RobotGeek Arduino Linear Actuator Experimenter's Kit, or obtained individually.
- 1x RobotGeek Large Workbench
- 1x Geekduino Mount / Hardware
- 1x RobotGeek Geekduino
- 1x RobotGeek Sensor Shield V2
- 1x USB To Micro USB Cable
- 1x 6v2a Power Supply
- 10x 300mm 3-pin Sensor Cables
- 25x 3pin Couplers
- 8x Rubber Bumper / Feet for the Workbench
- 1x Linear actuator, (100:100), (100:210), (50:100), or (50:210)
- 1x RobotGeek Rotation Knob
- 1x RobotGeek Joystick
- 3x RobotGeek Pushbutton
- 1x RobotGeek Slider
Step 2: Wiring
Device | Sensor Shield Port |
---|---|
Linear Actuator (white/red/black cable) | Digital 6 Option: Preset Position - Button |
Linear Actuator (white/red/black cable) | Digital 9 Option: Analog Direct - Rotation Knob |
Linear Actuator (white/red/black cable) | Digital 10 Option: Analog Direct - Slider |
Linear Actuator (white/red/black cable) | Digital 11 Option: Incremental Control - Joystick |
Push Button 1 | Digital 2 |
Push Button 2 | Digital 4 |
Push Button 3 | Digital 7 |
Rotation Knob | Analog 0 |
Joystick (Vertical) | Analog 1 |
Slider | Analog 2 |
PWM Voltage Jumpers on Sensor Shield | Both set to VIN |
Notice that you'll have to physically plug the linear actuator into different ports in order to move it with the different controls. If you have multiple linear actuators, you can control up to 4 simultaneously with this code.
Step 3: Upload the Code to Your Arduino
You can find this Demonstration Code in the RobotGeek Libraries and Tools under:
RobotGeekSketches -> Demos -> LinearActuator -> linearActuatorExpDemo -> linearActuatorExpDemo.ino
This code will get us through the next three sections. You will be asked to plug the linear actuator into different pins based on the section of the tutorial you're working on.
/*********************************************************************************** * RobotGeek Linear Actuator Experimenter's Kit Demo * ________ * | \---------\___________________________ * __| | ||--------------------|__ * (o | FIRGELLI | o ||____________________| o) * |__________________/--------------------------|| * * * The following sketch will allow you to control a Firgelli Linear actuator using * the RobotGeek Slider, RobotGeek Knob, RobotGeek Joystick, and RobotGeek Pushbuttons * * http://www.robotgeek.com/robotgeek-experimenters-kit-linear-actuator * * * Wiring * Linear Actuator - Digital Pin 6, 9, 10, and/or 11 * * Knob - Analog Pin 0 * Joystick - Analog Pin 1 * Slider - Analog Pin 2 * * Pushbutton - Digital Pin 2 * Pushbutton - Digital Pin 4 * Pushbutton - Digital Pin 7 * * Jumpers for pins 3/5/6 and 9/10/11 should be set to 'VIN' * * * Control Behavior: * Moving the slider or knob will move the linear actuator keeping absolute position. * Moving the joystick will move the linear actuator incrementally. * Pressing one of the buttons will move the linear actuator to a predetermined position. * ***********************************************************************************/ //Includes #include //Servo Library can be used for Firgelli Mini Linear Actuators //Linear Actuator Pins const int LINEARPIN_BUTTON = 6; //Linear Actuator on Digital Pin 6 const int LINEARPIN_KNOB = 9; //Linear Actuator on Digital Pin 9 const int LINEARPIN_SLIDER = 10; //Linear Actuator on Digital Pin 10 const int LINEARPIN_JOYSTICK = 11; //Linear Actuator on Digital Pin 11 //Analog Input Pins const int KNOB_PIN = 0; //Knob on Analog Pin 0 const int JOYSTICK_PIN = 1; //Joystick (vertical) on Analog Pin 1 const int SLIDER_PIN = 2; //Slider on Analog Pin 2 //Digital Input Pins const int BUTTON1_PIN = 2; //Button 1 on Digital Pin 2 const int BUTTON2_PIN = 4; //Button 2 on Digital Pin 4 const int BUTTON3_PIN = 7; //Button 3 on Digital Pin 7 //Generic deadband limits - not all joystics will center at 512, so these limits remove 'drift' from joysticks that are off-center. const int DEADBAND_LOW = 482; //decrease this value if drift occurs, increase it to increase sensitivity around the center position const int DEADBAND_HIGH = 542; //increase this value if drift occurs, decrease it to increase sensitivity around the center position //Max/min pulse values in microseconds for the linear actuators const int LINEAR_MIN = 1050; const int LINEAR_MAX = 2000; // variables will change: int button1State = 0; // variable for reading the pushbutton status int button2State = 0; // variable for reading the pushbutton status int button3State = 0; // variable for reading the pushbutton status Servo linearKnob, linearSlider, linearButton, linearJoystick; // create servo objects to control the linear actuators int knobValue, sliderValue, joystickValue; //variables to hold the last reading from the analog pins. The value will be between 0 and 1023 int valueMapped; // the joystick values will be changed (or 'mapped') to new values to be sent to the linear actuator. //variables for current positional value being sent to the linear actuator. int linearValue_Knob = 1500; int linearValue_Slider = 1500; int linearValue_Button = 1500; int linearValue_Joystick = 1500; int speed = 2; void setup() { //initialize linear actuators as servo objects linearKnob.attach(LINEARPIN_KNOB); // attaches/activates the linear actuator as a servo object linearSlider.attach(LINEARPIN_SLIDER); // attaches/activates the linear actuator as a servo object linearButton.attach(LINEARPIN_BUTTON); // attaches/activates the linear actuator as a servo object linearJoystick.attach(LINEARPIN_JOYSTICK); // 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 linearKnob.writeMicroseconds(linearValue_Knob); linearSlider.writeMicroseconds(linearValue_Slider); linearButton.writeMicroseconds(linearValue_Button); linearJoystick.writeMicroseconds(linearValue_Joystick); } void loop() { //Preset Positions for Button Control // if the pushbutton is pressed set the linear value button1State = digitalRead(BUTTON1_PIN); if (button1State == HIGH) { // set the position value linearValue_Button = 1300; } button2State = digitalRead(BUTTON2_PIN); if (button2State == HIGH) { // set the position value linearValue_Button = 1500; } button3State = digitalRead(BUTTON3_PIN); if (button3State == HIGH) { // set the position value linearValue_Button = 1700; } //Analog Direct Control //read the values from the analog sensors knobValue = analogRead(KNOB_PIN); sliderValue = analogRead(SLIDER_PIN); linearValue_Knob = map(knobValue, 0, 1023, LINEAR_MAX, LINEAR_MIN); //Map analog value from the sensor to the linear actuator linearValue_Slider = map(sliderValue, 0, 1023, LINEAR_MAX, LINEAR_MIN); //Map analog value from the sensor to the linear actuator //Incremental Joystick Control joystickValue = analogRead(JOYSTICK_PIN); //read the values from the joystick //only update if the joystick is outside the deadzone (i.e. moved oustide the center position) if(joystickValue > DEADBAND_HIGH || joystickValue < DEADBAND_LOW) { valueMapped = map(joystickValue, 0, 1023, speed, -speed); //Map analog value from native joystick value (0 to 1023) to incremental change (speed to -speed). linearValue_Joystick = linearValue_Joystick + valueMapped; //add mapped joystick value to present Value linearValue_Joystick = constrain(linearValue_Joystick, LINEAR_MIN, LINEAR_MAX); // } //Use the writeMicroseconds to set the linear actuator to its new position linearKnob.writeMicroseconds(linearValue_Knob); linearSlider.writeMicroseconds(linearValue_Slider); linearButton.writeMicroseconds(linearValue_Button); linearJoystick.writeMicroseconds(linearValue_Joystick); delay(10); }
Step 4: Analog Direct Control
For this section:
To use the Rotation Knob, plug your Linear Actuator into Digital Pin 9
To use the Slider, plug your Linear Actuator into Digital Pin 10
So what's going on here? We're mapping the absolute position from the analog sensors to the actuator position. It makes sense, you move the rotation knob or slider into a position, and the linear actuator matches that position.
Want to see some nonsense? Plug your Joystick into Analog Pin 0
, and your Linear Actuator into Digital Pin 9
. The joystick always returns to center position, causing the linear actuator to match and return to its center value. Not really all that useful if you wanted to use the joystick to move the linear actuator to a position other than center, which leads us to our next section. Make sure to return your sensors to their original pins before moving on.
If you would like a sketch that covers only this section of the tutorial, you can find it here.
Step 5: Incremental Control
For this section:
To use the Joystick, plug your Linear Actuator into Digital Pin 11
So what's going on here? This time, instead of mapping directly to the value of the joystick, we are using the joystick to increment the position of the linear actuator, allowing us to let go of the joystick and have the linear actuator stay where we put it last.
If you would like a sketch that covers only this section of the tutorial, you can find it here.
Step 6: Preset Controls
For this section:
To use the Buttons, plug your Linear Actuator into Digital Pin 6
So what's going on here? In this part, we are using button presses that send the linear actuator to pre-defined positions. This is simple and incredibly useful for when you know what position you'd like the linear actuator to be in under a circumstance defined by an input.
If you would like a sketch that covers only this section of the tutorial, you can find it here.
Step 7: What's Next?
Now you know three ways to control your linear actuator. Can you think of projects that would benefit from this? Do you have a box that you'd like to automatically open? How would you use a linear actuator to do that? All the muscles in the human body are biological linear actuators. Could you make a robotic arm that mimics this? What about making a table that can tilt? We'd love to hear about your project! Go forth and create!
16 Comments
Question 1 year ago
Would you be able to help with programming for the section in step 4, where the joystick always returns to center position causing the linear actuator to match and return to its center value?
Question 4 years ago on Introduction
Do you know how you would change the code to have the actuator go to a specified distance, pause and return with the click of a button or no button at all.
5 years ago
Wiring of sensor shield port is shown, but what about the wiring of arduino, it is not shown.
6 years ago
$90 actuators :-(
Not for the average hobbyist.
I'll stick with servos.
Reply 5 years ago
It depends what's being built. There are hundreds of applications that require linear motion and these are less expensive then 95% of what's on the market.
6 years ago
Is there any way to make the actuators move faster?
Reply 5 years ago
There are several different models with different gearing options.
6 years ago
This genius! especially the mechanism.
Cheaper and prolly way more powerful than using air pressure.
Reply 6 years ago
Using a motorized linear actuator such as this one is less complicated, lighter, and certainly quieter than using a compressed air system for linear actuation. There are still cool things being done with air pressure and robotics though! Have you seen the Air Muscle? https://www.instructables.com/id/How-to-make-air-muscles!/ It's pretty cool, but you need a pretty big air compressor if you're going to use more than one of them.
6 years ago
HaHaHa in my Opinion it is a little bit overkill using so many parts to squeeze a Ball, I would give it to my daughter she will squeeze, bite, throw.. it the whole day, or maybe in a few month my daughter would like to play with electronic stuff, she already play with all my projects....
Reply 6 years ago
Aww, she's adorable, and way better suited for squeezing a ball than a linear actuator. Your project looks cool! Is that a Raspberry Pi computer she's using?
Reply 6 years ago
Yes it's in my instructables....
6 years ago
Awsome, Thanks
Reply 6 years ago
Thank you!
6 years ago
Great Instructable! Kinda high end for our projects but great to know where to look if we ever have the need.
Reply 6 years ago
Thank you! Yeah, linear actuators are pretty expensive to begin with, and we only carry well tested, quality checked ones, so that doesn't help much on entry level costs.