Reader small image

You're reading from  Arduino BLINK Blueprints

Product typeBook
Published inMay 2016
PublisherPackt
ISBN-139781785284182
Edition1st Edition
Tools
Right arrow
Author (1)
Utsav Shah
Utsav Shah
author image
Utsav Shah

Utsav Shah is an instrumentation engineer who loves to work on the latest hardware as well as software technologies. He has been featured on India's leading website http://yourstory.in and Ahmedabad Mirror (Times Group) for his research work on "Converting sign language into speech" using a Leap Motion controller. Apart from his regular work at Infosys Limited, he manages activities of Infosys Robotics Club. In his leisure time, he loves to read books and work on cutting-edge technologies.
Read more about Utsav Shah

Right arrow

Controlling a DC motor using Arduino


In this chapter, we will get to know how to control a DC motor with Arduino.

You can also run the DC motor by using the same code as the LED blink. We can consider the motor as an LED. As discussed earlier, a DC motor is a two-wired motor. One wire is the positive supply and other is ground. If we connect the positive terminal of the motor to the positive terminal of the battery, and the negative terminal of the motor to the negative terminal of the battery, the motor will run in one direction, and if we reverse the connection, the motor will run in the reverse direction.

By connecting the motor to two digital pins of the Arduino, we can control the direction of the motor. In the following basic code, we will run the motor in one direction for five seconds and then we will reverse the direction of the motor. Connect pin 3 and pin 4 of the Arduino with the two wires of the motor:

int motorPos = 3;
int motorNeg = 4;

void setup() {
  pinMode(motorPos, OUTPUT...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Arduino BLINK Blueprints
Published in: May 2016Publisher: PacktISBN-13: 9781785284182

Author (1)

author image
Utsav Shah

Utsav Shah is an instrumentation engineer who loves to work on the latest hardware as well as software technologies. He has been featured on India's leading website http://yourstory.in and Ahmedabad Mirror (Times Group) for his research work on "Converting sign language into speech" using a Leap Motion controller. Apart from his regular work at Infosys Limited, he manages activities of Infosys Robotics Club. In his leisure time, he loves to read books and work on cutting-edge technologies.
Read more about Utsav Shah