Motor Speed Controller

On this page, I will show you how to control a DC motor or something with a high power. You can control relays, motors, high brightness lights, and more. All you need to do it is a transister! I made a video for the motor, and I'll make a video for relays soon. In this project, I'll be using the following items:
 
-Transister (I'll use the NPN 2N2222 from Radioshack. http://www.radioshack.com/product/index.isp?productId=2062586)
-Diode
-Resister (I'm using 1K Ohm.)
-Motor (Or something you want to run.)
-Arduino (I'm using Uno.)
-External battery
-Potentiometer (For speed control. You don't need it if you want to just turn it on or off.)
-Anything else you want like breadboards and jumpers
 
Using the diagram below, wire up your Arduino like that. Notice, you want the diode going from Negative to Positive on the motor. Your going to want to use the Negative side of the battery for the transister. If you want a vary the speed of your motor, add the data pin of a potentiometer to pin A0.
 
------------------------------------------------------
Sorry, I didn't put the potentiometer in the diagram when I made it.
------------------------------------------------------
 
 
Programming:
 
Here is the code your going to want to use for this layout. It's actually quite simple for this operation.
 
-----------------------------------
 
int potpin = A0;
int val;

void setup() {}

void loop() {
  val = analogRead(potpin);
  val = map(val, 0, 1023, 0, 225);
  analogWrite(3, val);
  delay(15);
}
//Copyright 2011 AKSoapy29
 
-----------------------------------
 
There you go!! That should be all you need to know to control your DC Motor! If you have any questions, send me a PM on the Arduino Forums! Here's the link: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?action=viewprofile;username=Soapy29


Video:
 
Comments