# Linear motion guide (lightweight)

by Lehaiver Sep 27, 2014

### Thing Apps Enabled

Good job!

Do you use MGN12 linear rail for profile 3030?

Thank you,
Regards!

For everyone that has made this linear motion, here is a arduino code which I made. You are able to move the table via serial-monitor. Just upload this code and open the serial-monitor. Set the monitor to ''new line''. The table will first home to the end switch, after that enter step value. Which is max 21250 in my case. You might change this max value for your particular device. Feel free to customize the code for your needs.

const int dirPin = 2;
const int stepPin = 3;
const int endSwitch = 4;

int homing = 0;
int maxSteps = 0;

boolean endSwitchstate = 0;
void setup() {

// Sets pins to output/input
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(endSwitch, INPUT);
digitalWrite(dirPin, HIGH);

Serial.begin(9600);

}

unsigned int steps = 0; // Max value is 21250
char incomingByte;

void loop() {

if (Serial.available() > 0) { // something came across serial
//integerValue = 0; // throw away previous integerValue
while (1) { // force into a loop until 'n' is received
if (incomingByte == '\n') break; // exit the while(1), we're done receiving
if (incomingByte == -1) continue; // if no characters are in the buffer read() returns -1
steps *= 10; // shift left 1 decimal place
// convert ASCII to integer, add, and shift left 1 decimal place
steps = ((incomingByte - 48) + steps);
}
Serial.println(steps); // Do something with the value
}

endSwitchstate = digitalRead(endSwitch); // Homing loop
if (endSwitchstate == 0 && homing == 0) {

``````digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(100);
digitalWrite(stepPin, LOW);
delayMicroseconds(100);``````

}
else
{
homing = 1; // Set homing to true if reached
}

if (homing == 1) // If home position has reached do steps filled in via serial-monitor

``````if (steps > 0 && maxSteps != 21250) {
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(100);
digitalWrite(stepPin, LOW);
delayMicroseconds(100);
steps --; maxSteps ++;
}``````

}

this would be great for a project I'm working on :D
only problem is that I use 2020 profile ... it would be great if you could make a vertion of this for 2020 profile :)

Linear motion guide 2020
Linear Motion Guide 2020 (double precision)

Nice job! Where can buy these aluminium profile?

http://www.consta.fi/media/Consta_Systems_PDF_Catalogue.pdf
It is one of the most used shopfitting profiles in Europe