Project Overview:

This project allows you to control four motors simultaneously using a single button. When the button is pressed, all motors stop. When the button is released, all motors start running.

Components List:

Circuit Connection:

Motor Control with Button using Arduino


  1. Button Setup:
  • Connct one side of the push button to digital pin 13 on the Arduino.
  • Connect the other side to GND.
  • Use a 10kΩ pull-up resistor between pin 13 and 5V, or configure the pin with INPUT_PULLUP in the code.
  1. Motor Setup:
  • Connect the motors to digital pins 2 through 5.
  • If you’re using transistors:
  • Connect the base of each transistor to a corresponding Arduino pin (2–5) through a 1kΩ resistor.
  • Connect the emitter to GND.
  • Connect the collector to one terminal of the motor.
  • Connect the other terminal of each motor to the power supply.
  • Place a diode parallel to each motor to prevent back EMF damage.
  • Alternatively, use a motor driver module to interface the motors with the Arduino.

Project Code:

int boton = 13;  // Button pin
int motor1 = 2; // Motor 1 pin
int motor2 = 3; // Motor 2 pin
int motor3 = 4; // Motor 3 pin
int motor4 = 5; // Motor 4 pin

void setup() {
pinMode(boton, INPUT_PULLUP); // Set button pin as input with pull-up resistor
pinMode(motor1, OUTPUT); // Set motor pins as outputs
pinMode(motor2, OUTPUT);
pinMode(motor3, OUTPUT);
pinMode(motor4, OUTPUT);
}

void loop() {
int estadoBoton = digitalRead(boton); // Read the state of the button

if (estadoBoton == LOW) { // Button is pressed (LOW due to pull-up)
// Turn off all motors
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
digitalWrite(motor3, LOW);
digitalWrite(motor4, LOW);
} else {
// Turn on all motors
digitalWrite(motor1, HIGH);
digitalWrite(motor2, HIGH);
digitalWrite(motor3, HIGH);
digitalWrite(motor4, HIGH);
}
}

Explanation of the Code:

  1. Setup Function:
  • Configures pin 13 as an input with a pull-up resistor for the button.
  • Sets pins 2 through 5 as outputs to control the motors.
  1. Loop Function:
  • Button Press: When the button is pressed (reads LOW due to pull-up configuration), all motors are turned off.
  • Button Release: When the button is released (reads HIGH), all motors are turned on.

Summary:

This simple project demonstrates how to control multiple motors using a single button with Arduino. It can be used as a basis for projects like a remote-controlled car or other applications where multiple motors need to be controlled simultaneously.

No comments

Theme images by Dizzo. Powered by Blogger.