How do I disable button until another button is clicked before

I have made a project that creates automatic blinds. I have one button to make the blinds go up, then another button makes the blinds go down. The only problem is I do not want the wrong button being pressed and the blind gets rolled too far up or down and ruined. So, Can someone please tell me how to disable the UP button until the DOWN button is pressed and the blind is down? Then disable the DOWN button until the UP button is pressed and the blind is up? I will attach my basic program. The program is fully working now, but I would like to add this extra function to save my blind in case something goes wrong! Alternatively I could have a switch at the top and bottom of the blind that deactivates the according switch. PS*Blind is another word for curtain in Australia

Any tips or solutions would be much appreciated!

Thanks very much,

Jack Allen :slight_smile:


const int buttonPin = 2; //UP Button
const int MotorPin = 8; //UP
const int buttonPin2 = 3;//DOWN button
const int MotorPin2 = 9;// DOWN

// variables will change:
int buttonState = 1;
int buttonState2 = 1;

void setup() {
pinMode(MotorPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(MotorPin2, OUTPUT);
pinMode(buttonPin2, INPUT);

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);

if (buttonState == HIGH) {

digitalWrite(MotorPin, HIGH);
} else {
digitalWrite(MotorPin, LOW);
if (buttonState2 == HIGH) {

digitalWrite(MotorPin2, HIGH);
} else {
digitalWrite(MotorPin2, LOW);

Use a boolean variable. Set it to true when the blinds have been pulled up. Only read the down button when the boolean is true. Note that you need to know that the blinds have been rolled up and at the moment that depends on using delay() with a fixed period. That will not be very reliable and it would be better to use limit switches so that you can detect the state of the blinds

Thanks so much... I will use the limit switches. :slight_smile: