Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Ingo Lohs
Published © LGPL

Lego Elevator

Give the axis of an inkjet printer a new job.

BeginnerProtip1 hour8,402

Things used in this project

Hardware components

Pololu 1135 - Sharp GP2Y0D810Z0F
www.pololu.com #1135
×1
Arduino UNO
Arduino UNO
or equal device
×1
Jumper wires (generic)
Jumper wires (generic)
×1
DFRobot DRI0001 - Motor Shield for Arduino
www.dfrobot.com #DRI0001
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Lego elevator

C/C++
int sharpState = 0;

int EN1 = 5;
int IN1 = 4;

void Motor1(int pwm, boolean reverse) {
analogWrite(EN1, pwm); //set pwm control, 0 for stop, and 255 for maximum speed

if (reverse) {
digitalWrite(IN1, HIGH);
}
else {
digitalWrite(IN1, LOW);
}
}

void setup() {
}

void loop() {

  sharpState = digitalRead(3), BIN;
    
    if (sharpState == HIGH) {
    Motor1(240, true); // play around this values to make it slower/faster
  } else {
    Motor1(100, false);
  }
}

Credits

Ingo Lohs

Ingo Lohs

182 projects • 194 followers
I am well over 50 years and come from the middle of Germany.
Thanks to Jonah & Lucas.

Comments