Connect Arduino Motor Button.
Connect Arduino Motor Button.
Hardware Setup:
Gather Components:
Arduino board (e.g., Arduino Uno)
DC motor
L293D motor driver IC
Push button
Breadboard
Resistors (for LEDs)
LEDs (one red and one green)
Jumper wires
Connect Motor Driver IC (L293D):
Place the L293D IC on the breadboard.
Connect the pins of the L293D as follows:
Pin 1 (Enable 1) to Arduino digital pin (e.g., 9)
Pin 2 (Input 1) to Arduino digital pin (e.g., 8)
Pin 7 (Vcc1) to Arduino 5V
Pin 8 (GND) to Arduino GND
Repeat the same connections for the second motor (if using)
Connect DC Motor:
Connect one terminal of the motor to one of the output pins of the L293D (e.g., Out
1 or Out 2).
Connect the other terminal of the motor to the positive terminal of the power
supply.
Connect the negative terminal of the power supply to the GND of the Arduino.
Connect Push Button:
Connect one terminal of the push button to any digital pin of the Arduino (e.g.,
pin 2).
Connect the other terminal of the push button to GND.
Connect LEDs:
Connect the anode (longer leg) of the red LED to a current-limiting resistor and
then to a digital pin of the Arduino (e.g., pin 6).
Connect the cathode (shorter leg) of the red LED to GND.
Repeat the same connections for the green LED.
Power Supply:
Connect Arduino to your computer via USB.
Ensure that the DC motor power supply voltage matches the specifications of the
motor and L293D.
Software Setup:
Install Arduino IDE:
If you haven't already, download and install the Arduino IDE from the official
website.
Write Arduino Sketch (Code):
Open the Arduino IDE.
Write the following code:
arduino
Copy code
// Define pin numbers
const int motorPin1 = 8; // Input 1 of L293D
const int motorPin2 = 9; // Enable 1 of L293D
const int buttonPin = 2; // Push button pin
const int redLedPin = 6; // Red LED pin
const int greenLedPin = 7; // Green LED pin
// Variables
int buttonState = 0; // Current state of the button
int lastButtonState = 0; // Previous state of the button
int cntr = 0; // Counter for button presses
void setup() {
// Initialize motor pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
void loop() {
// Read the state of the push button
buttonState = digitalRead(buttonPin);
// Variables
int buttonState = 0; // Current state of the button
int lastButtonState = 0; // Previous state of the button
int cntr = 0; // Counter for button presses
void setup() {
// Initialize motor pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
void loop() {
// Read the state of the push button
buttonState = digitalRead(buttonPin);