O'Reilly logo

Arduino: Building exciting LED based projects and espionage devices by Marco Schwartz, Utsav Shah, Samarth Shah, Adith Jagdish Boloor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required