Button turns Motor ON and a trigger event turns the Motor OFF

Description: When a Push-Button is pressed, the motor turns ON. And when the SPDT Micro Limit Switch is triggered, there is a 1.5 second delay before the motor turns OFF.

Button turns Motor ON and trigger event turns it OFF

Supplies:

1 – Breadboard 400 Points
1 – Arduino Nano
1 – Metal Push-Button 12mm   >> Link <<
1 – SPDT Micro Limit Switch   >> Link <<
2 – 10k Resistors
1 – 5V N20 DC Gear Motor   >> Link <<
1 – 1N4004 Rectifier Diode   >> Link <<

Arduino Code:

#define motor 6
#define button 16
#define trigger 10

void setup() {

  pinMode(motor, OUTPUT);
  pinMode(button, INPUT);
  pinMode(trigger, INPUT);

}

void loop() {

  int buttonVal = digitalRead(button);

  if(buttonVal == HIGH) {
  digitalWrite(motor, HIGH);
  
}

  int triggerVal = digitalRead(trigger);

  if(triggerVal == HIGH) {

  delay(1500);
  digitalWrite(motor, LOW);

}
}

Leave a Comment

1 + 6 =