Control a DC Motor with Arduino UNO R3 With button
This is pretty much a follow up of another article ( see Control a DC Motor with Arduino UNO R3 (No button) ). In this case we will be adding 2 new items on the board. A potentiometer and a breadboard friendly push button.
In this scenario the motor will be running into a direction, while button is pressed, the motor will run on the opposite direction.
WHAT DO YOU NEED?
-Arduino UNO R3 board : The arduino UNO is the most used and documented board.
-L293D motor driver : Also known as a H BRIDGE. Motor driver act as an interface between Arduino and the motors . H-bridge is the simplest circuit for controlling a low current rated motor.
-5V DC motor : You have plenty of them. I have the most simple one will do for this example.
- A potentiometer
-A breadboard friendly push button
-Breadboard and jumper wires : To make wiring easy and clear.
-Connect 5v and GND of Arduino to the breadboard
-Connect A0 -analog pin of Arduino to middle wire of the Potentiometer
-Connect Potentiometer to GND and 5v
-Connect PIN7 of arduino to Push button
-Connect Push button to GND
-Connect DC Motor to PIN3 and PIN6 of the L293D
-Connect 5V to PIN8 and PIN16 of the L293D
-Connect GND to PIN4 of the L293D
-Connect PIN11 of the arduino to PIN1 of the L293D
-Connect PIN10 of the arduino to PIN2 of the L293D
-Connect PIN9 of the arduino to PIN7 of the L293D
ARDUINO SKETCH :
Adafruit Arduino - Lesson 15. Bi-directional Motor
int enablePin = 11;
int in1Pin = 10;
int in2Pin = 9;
int switchPin = 7;
int potPin = 0;
int speed = analogRead(potPin) / 4;
boolean reverse = digitalRead(switchPin);
void setMotor(int speed, boolean reverse)
digitalWrite(in1Pin, ! reverse);