Difference between revisions of "Lesson 40--Microduino DC Motor Drive (Potentiometer PWM control speed)"

From Microduino Wiki
Jump to: navigation, search
 
Line 15: Line 15:
 
**Potentiometer                one
 
**Potentiometer                one
 
**NPN transistor              one
 
**NPN transistor              one
**2.2k registor                 one
+
**2.2k resistor                 one
 
**Diode                        one
 
**Diode                        one
 
**USB cable                    one
 
**USB cable                    one
Line 21: Line 21:
 
==Schematic==
 
==Schematic==
 
[[File:第四十课-Microduino电位器PWM调速直流电机.jpg|600px|center|thumb]]
 
[[File:第四十课-Microduino电位器PWM调速直流电机.jpg|600px|center|thumb]]
Desription:
+
Description:
  
 
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:  
 
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:  
Line 38: Line 38:
 
void loop() {
 
void loop() {
 
  potValue = analogRead(potPin);  //Read the value of potentiometer
 
  potValue = analogRead(potPin);  //Read the value of potentiometer
  motorValue = map(potValue, 0, 1023, 0, 255);//Mapp to a value among 0~255
+
  motorValue = map(potValue, 0, 1023, 0, 255);//Map to a value among 0~255
 
  analogWrite(motorPin, motorValue);//Output PWM to motor
 
  analogWrite(motorPin, motorValue);//Output PWM to motor
 
  //Display
 
  //Display
Line 52: Line 52:
  
 
==Debug==
 
==Debug==
Step 1:Copy the code to IDE and compile it
+
Step 1: Copy the code to IDE and compile it
  
Step 2:Set up circuit, as follows:
+
Step 2: Set up circuit, as follows:
 
[[File:第四十课-Microduino电位器PWM调速直流电机连接图.jpg|600px|center|thumb]]
 
[[File:第四十课-Microduino电位器PWM调速直流电机连接图.jpg|600px|center|thumb]]
  
Step 3:Run program
+
Step 3: Run program
  
Step 4:Adjust potentiometer, and check the speed of the motor
+
Step 4: Adjust potentiometer, and check the speed of the motor
  
 
==Result==
 
==Result==

Latest revision as of 08:57, 12 September 2016

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 resistor one
    • Diode one
    • USB cable one

Schematic

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

Description:

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);//Map 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