Lesson 40--Microduino DC Motor Drive (Potentiometer PWM control speed)

来自Microduino Wikipedia
跳转至: 导航搜索
Language English

Objective

This tutorial will teach you how to control the speed of a DB motor via the potentiometer.

Equipment

  • Microduino-Core
  • Microduino-FT232R
  • Other equipment
    • Breadboard Jumper one box
    • Breadboard one piece
    • DC motor one
    • Potentiometer one
    • NPN transistor one
    • 2.2k registor one
    • Diode one
    • USB cable one

Schematic

第四十课-Microduino电位器PWM调速直流电机.jpg

Desription:

When connect the NPN transistor, Base (B) connects with 2.2K resistor, emitter (E) connects the GND and collector (C) connects to motor. As follows:

第四十课-Microduino电位器PWM调速直流电机NPN三极管连接.jpg

Program

int potPin = A0; //Potentiometer input pin
int motorPin = 9;//Motor pin
int potValue = 0;//Define the value of potentiometer
int motorValue = 0;//Define the value of motor
void setup() {
 Serial.begin(9600);
}
void loop() {
 potValue = analogRead(potPin);  //Read the value of potentiometer
 motorValue = map(potValue, 0, 1023, 0, 255);//Mapp to a value among 0~255
 analogWrite(motorPin, motorValue);//Output PWM to motor
 //Display
 Serial.print("potentiometer = " );     
 Serial.print(potValue);
 Serial.print("\t motor = ");
 Serial.println(motorValue);
 delay(2);    
}

Debug

Step 1:Copy the code to IDE and compile it

Step 2:Set up circuit, as follows:

第四十课-Microduino电位器PWM调速直流电机连接图.jpg

Step 3:Run program

Step 4:Adjust potentiometer, and check the speed of the motor

Result

Twist potentiometer to adjust the motor's speed

Video

http://v.youku.com/v_show/id_XNjgyMzYwMTQw.html