## Simple DC Motor code? Without motor shield? Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Simple DC Motor code? Without motor shield?

Ok so here's the setup, I have 2 dc motors, 1 in the back for forward/backward and 1 in the front for steering left and right. I just started arduino so Im still in the noob range, but what I had in mind is to control how far or how long each motor will run and then repeat so it runs on a pre-programmed track almost. For example, I would like it to go forward using the forward/backwards motor for say 3 seconds on a certain speed and then turn left using the left and right motor for a certain time on a certain speed then going forward again to achieve that turn. Is there already a code like this? As well, I would like to use a Dual-H bridge how ever its spelt.

Thanks!
-Ethan
1EAS1

Posts: 18
Joined: Mon Feb 04, 2013 10:06 pm

Re: Simple DC Motor code? Without motor shield?

Even if you don't use the motor shield itself, you can look at the circuit and the code for suggestions on what to do.

The simplest way to drive a DC motor is just to turn on the power. A half bridge controls power to the motor by creating low-resistance connections to the high or low voltage rails, depending on what you tell it to do.

To make a DC motor turn either direction, connect each wire to its own half bridge. Send half-bridge A HIGH and half-bridge B LOW to make the motor turn one direction, A LOW and B HIGH to make the motor turn the other direction.

To control the motor's speed, you turn the power on and off quickly, using a technique called "pulse-width modulation" or "PWM". Over the long term, a half-bridge that's HIGH 80% of the time and LOW the remaining 20% of the time gives the motor 80% as much power as one that's HIGH all the time.

The Motor Shield has all the hardware and software issues worked out, but like I said, even if you don't use the device itself, the circuit diagrams and the library code give you an example of stuff that's known to work.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.