Control a DC Motor with Arduino UNO R3 (No button)

Category : Electronics

Control a DC Motor with Arduino UNO R3 (No button)

I am a beginner with Arduino micro processor. I have been tinkering around a bit and decided to play with the materials I had home.

This is a simple DC Motor control with Arduino UNO R3 model. This is directly taken from this Instructables tutorial. This articile is  to describe the steps I took in order to have the DC Motor run off an Arduino board. In this scenario I am using a L293DNE Motor driver or H Bridge. It is important to get a little acquainted with different components of  this driver. This driver is able to control up to 2 motors. I am using only 1 motor for now.





-Arduino UNO R3 board : The arduino UNO is the most used and documented board.




  • Microcontroller : ATmega328p
  • Operating Voltage : 5V
  • Input Voltage (recommended) : 7-12V
  • Input Voltage (limits) : 6-20V
  • Digital I/O Pins : 14 (of which 6 provide PWM output)
  • Analog Input Pins : 6
  • DC Current per I/O Pin : 40 mA
  • DC Current for 3.3V Pin : 50 mA
  • Flash Memory : 32 KB (ATmega328) of which 0.5 KB used by bootloader SRAM 2 KB (ATmega328)
  • EEPROM : 1 KB (ATmega328)
  • Clock Speed : 16 MHZ


-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.


-Breadboard and jumper wires : To make wiring easy and clear.





The L293DNE is set on the board. It has 16 pins. There are many pages out there that describes each pin, one those being this one.


-Connect 5v and GND of Arduino to the breadboard

-Connect PIN8 and PIN16 of the H Bridge to 5V on the breadboard

-Connect PIN5 of the H Bridge to GND on the breadboard

-Connect PIN1 of the H Bridge to PIN6 of the Arduino

-Connect PIN2 of the H Bridge to PIN5 of the Arduino

-Connect PIN7 of the H Bridge to PIN4 of the Arduino

-Connect DC Motor on breadboard with each terminal plugged into the breadboard.

-A Terminal of DC motor connected to PIN3 of the H Bridge

-Another Terminal of DC Motor connected to PIN6 of the H Bridge

-Connect Arduino to USB



With the Arduino IDE installed on your laptop, upload below code to the Arduino.


Important is to select the board in TOOLS > BOARD. In my case I selected ARDUINO/GENUINO UNO.

Selecting the right port is key. For USB connection best is to use any port that says CU and/or USB in the port name.


The below sketch will generate the following behaviour: The motor should now run first in the clockwise (CW) direction for 3 seconds and then counter-clockwise (CCW) for 3 seconds. There should be a delay of 1 second.



const int pwm = 6;

const int in_1 = 5; const int in_2 = 4;

void setup() { pinMode(pwm,OUTPUT); pinMode(in_1,OUTPUT); pinMode(in_2,OUTPUT); }

void loop() {

//for clock wise motion

digitalWrite(in_1,HIGH); digitalWrite(in_2,LOW); analogWrite(pwm,255);

//delay for 3 sec Clock wise motion


//for break

digitalWrite(in_1,HIGH); digitalWrite(in_2,HIGH); delay(200);

//for anticlock wise

digitalWrite(in_1,LOW); digitalWrite(in_2,HIGH); delay(3000);

//for break

digitalWrite(in_1,HIGH); digitalWrite(in_2,HIGH); delay(200);