Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ONLY WRITE THE CODE Design a garage door controller for an Arduino controller. T

ID: 2291946 • Letter: O

Question

ONLY WRITE THE CODE

Design a garage door controller for an Arduino controller. The behavior of the garage door controller is as follows, . There is an open button (GPIO 1) and a close button (GPIO 2) outside of the garage to control the process . When the open_button is pushed the door will move up and when the close_button is pushed the door will move down. MotorUP (GPIO 3) and Motor Down(GPIO 4) are the actuators to perform the movement. If either of buttons is pushed once while moving, the door will stop, a second push will start motion again in the requested direction. There is a top_limit_switche (GPIO 5) and a bottom limit switche(GPIO 6) to indicate the top and bottom of the garage Consider the Emergency stop ES (GPIO 6) for the design Consider the occasion of fault in motors . . Never allow the motor in either of directions to operate more than 10s.

Explanation / Answer

Arduino Code:

const int open_button = 1;   

const int close_button = 2;

const int top_limit_switche = 5;

const int botttom_limit_switche = 6;  

const int MotorUP = 3;   

const int MotorDown = 4;   

int motor_state = 0; // 0 : stop mode, 1: motor up mode, 2: motor down mode

void setup()

{

// initialize the LED pin as an output:

pinMode(MotorUP, OUTPUT);

pinMode(MotorDown, OUTPUT);

// initialize the pushbutton pin as an input:

pinMode(open_button, INPUT);

pinMode(close_button, INPUT);

pinMode(top_limit_switche, INPUT);

pinMode(botttom_limit_switche, INPUT);

}

void loop()

{

if (digitalRead(open_button) == HIGH)

{

motor_state = 1; // Motor state UP

}

else

{

motor_state = 0; // Motor state stop

}

if (digitalRead(close_button) == HIGH)

{

motor_state = 2; // Motor state Down

}

else

{

motor_state = 0; // Motor state stop

}

if (digitalRead(top_limit_switche) == HIGH)

{

motor_state = 0; // Motor state stop

}

if (digitalRead(botttom_limit_switche) == HIGH)

{

motor_state = 0; // Motor state stop

}

if(motor_state == 2) // Motor Down Mode

{

digitalWrite(MotorDown, HIGH);

digitalWrite(MotorUP, LOW);

}

else if (motor_state == 1) // Motor Stop mode

{

digitalWrite(MotorDown, LOW);

digitalWrite(MotorUP, HIGH);

}

else // Motor Stop mode

{

digitalWrite(MotorDown, LOW);

digitalWrite(MotorUP, LOW);

}