User:Dstaub/adruino motor control/dcmotorcontrol

From Wikiversity
Jump to: navigation, 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.

/*
 Blink
 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

}

NOTE: COPY AND PASTE THIS CODE FROM THE EDIT WINDOW.

Blink.JPG

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:

-Arduino

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

Step1

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

Step2

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.

Step3

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.

Setup2.JPG