User:Dstaub/adruino motor control/dcmotorcontrol

From Wikiversity
Jump to navigation Jump to search

Below is one of the simplest ways to get a small motor to function. This first tutorial will spin a small DC motor on and off for a repeated amount of seconds in one direction. All you need is...

-Arduino/ Usb cable

-Small DC Motor (less than 5v)

-2 wires

Step 1

Connect one wire to any pin # (in this case pin 10)

Step 2

Connect the second wire to GND

Step 3

attach the two wires to the leads on the motor (it dosnt matter where + and - connect to the motor)

Step 4

Upload the simple 'Blink' code found within the Arduino program or from below.

 Turns on a motor for one second, then off for one second, repeatedly.

 This example code is in the public domain.

// use pin 10 as the output pin // give it a name: int motor = 13;

// the setup routine runs once when you press reset: void setup() {

 // initialize the digital pin as an output.
 pinMode(motor, OUTPUT);     


// the loop routine runs over and over again forever: void loop() {

 digitalWrite(motor, HIGH);   // turn the motor on (HIGH is the voltage level)
 delay(1000);               // wait for a second
 digitalWrite(motor, LOW);    // turn the motor off by making the voltage LOW
 delay(1000);               // wait for a second




Now lets say you have a bigger motor that requires more than the 5v the Arduino outputs, here is where we get into transistors. A transistor is basically an electronic switch and in this case it can handle more voltage rather than if the signals were put through the arduino. In this tutorial we will be using a 'TIP-120' transistor.

You will need:


-Bread Board

-DC Motor

-9V Battery

-TIP-120 transistor

-1K resistor

TIP circut.JPG

This setup is a little more tricky than the previous but still a simple setup.


Connect the 1k resistor from your designated digital pin (in this case pin 2) to the middle lead on the transistor.


Connect the GND wire of the motor to the left lead on the transistor and the positive lead of the motor to positive on the battery.


Finally connect the negative end of the battery to GND on your Arduino also connect it to the right lead on your transistor.

From here you should be able to upload the previous blink code to the Arduino and get the same results only difference being you can now use it to control higher voltage motors.