Stepper motor to lock and unlock a deadbolt

I am designing a product for my class using an Arduino board, a stepper motor, and a transmitter with receiver switch. My goal is to be able to close the switch have it turn the lock once then wait until I change the signal. There is an A button on the transmitter and a B button, one closes and the other opens the switch. Eventually I want A to Lock and B to unlock. I’m sparing a lot of the details but basically everything works, I get the motor to turn once in the correct direction responding to my input but then it doesn’t respond to another change in the signal. I do not understand why it will not keep looping? I am not very knowledgeable about Arduino but I am trying my best! Any help would be appreciated.

deadbolt.ino (944 Bytes)

    if (switchState == LOW)
      switchState = digitalRead(pinSwitch);

Why do you use the state of the pin before you read the state of the pin?

      while (switchState == LOW);

If switchState ever IS LOW, this is an infinite loop.

You should ALWAYS have curly braces for the body of if statements, for loops, and while statements, to make it clear that nothing happens.

      while (switchState == LOW)
         ; // Do nothing, ever.


    if (switchState == HIGH);

should be

    if (switchState == HIGH)
       ; // Do nothing

Of course, it is highly unlikely that THIS is what you meant.

Your code looks like it was typed by a drunken monkey. Put EVERY { on a line BY ITSELF. Put EVERY } on a line BY ITSELF. Use Tools + Auto Format, and get that monkey into a treatment program.

I think you ought to look at using a servo instead of a stepper.
The servo will , size for size, have much more torque.
The stepper doesn’t have any way of knowing it’s position, if it slips you will lose knowledge of its position.