Arduino stepper motor elevator.

Ok heres my code so far.

#include "Stepper_28BYJ_48.h"

const int buttonPin1= 2;    
    

int floorState = 3;
Stepper_28BYJ_48 stepper(6, 5, 4, 3);

void setup() {
  pinMode(buttonPin1, INPUT);
  Serial.begin(9600);
}

void loop() {
int buttonState1;         
  buttonState1 = digitalRead(buttonPin1);


  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState1 == HIGH) {

  if (floorState == 3){
    stepper.step(-1);
    int floorState = 1;
  }
}
 

}

I need to be able to push a button once and it execute the stepper motor to move like 2 steps down. I have wired everything up and when I press the button it just turns off after I unpress it. Any help.

I would suggest you look at some of the stepper examples in the IDE (File->Examples->Stepper) to get an idea of how to control a stepper motor. Having it move 1 step isn't going to accomplish much.

You also do not need to declare 'floorState' again inside your if() statement. That creates a new variable, separate from your global 'floorState' variable and then it immediately goes out of scope when the if() statement is over. Just assign a value to it 'floorState = 1' without the 'int' part. I'm not really sure what this code will accomplish because once you change the value of 'floorState' the if() statement will never execute again.

Wish people would sober up before making videos, makes me sea sick. >:(

JCA79B:
Wish people would sober up before making videos, makes me sea sick. >:(

What video? I think I found it in this Thread. I have suggested that the Threads be merged.

...R

PS ... I find it helps to hold my laptop in my hands and move it in time to counteract the movement of the camera. :slight_smile: