To control small DC motor you will need:
motor, max 5v
PN2222 Transistor
1N4001 diode
270 Ω Resistor (red,
purple, brown stripes)
Connection scheme:
Add this code to arduino. You can control the speed of motor by sending values between 0 - 255 from serial monitor. However i noticed my DC motor doesnt work if the speed isn't between 150 - 255.
int motorPin = 3;
void setup()
{
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
while (! Serial);
Serial.println("Speed 0 to 255");
}
void loop()
{
if (Serial.available())
{
int speed = Serial.parseInt();
if (speed >= 0 && speed <= 255)
{
analogWrite(motorPin, speed);
}
}
}
Project found from: http://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors/overview
Ei kommentteja:
Lähetä kommentti