Difference between revisions of "The Use of DC Motor"

From Microduino Wiki
Jump to: navigation, search
(Created page with " {| style="width: 800px;" |- | ==Outline== N20 direct current speed reduction motor: Compared with the ordinary DC motor, it is equipped with gear speed reduction box, which o...")
 
 
(One intermediate revision by one other user not shown)
Line 4: Line 4:
 
|
 
|
 
==Outline==
 
==Outline==
N20 direct current speed reduction motor: Compared with the ordinary DC motor, it is equipped with gear speed reduction box, which offers lower rotation rate and larger torque, enhancing the use rate of the DC motor in the automation industry.   
+
Direct current speed reduction motor: Compared with the ordinary DC motor, it is equipped with gear speed reduction box, which offers lower rotation rate and larger torque, enhancing the use rate of the DC motor in the automation industry.   
  
 
==Specification==
 
==Specification==
Line 32: Line 32:
  
 
=== Wire Connection of DC Motor ===
 
=== Wire Connection of DC Motor ===
*Connect a DC motor to (OUT1A,OUT1B) and the other motor to (OUT2A,OUT2B);  
+
*Connect a DC motor to (OUT1A, OUT1B) and the other motor to (OUT2A, OUT2B);  
 
*DC motor control pin:  
 
*DC motor control pin:  
 
<source lang="cpp">
 
<source lang="cpp">
Line 43: Line 43:
 
</source>
 
</source>
 
===Preparation  
 
===Preparation  
*Setup 1:Connect a motor to the Motor module as the diagram showed above;  
+
*Setup 1: Connect a motor to the Motor module as the diagram showed above;  
 
[[File: _304_DozingDonkey _Motor.jpg|600px|center]]
 
[[File: _304_DozingDonkey _Motor.jpg|600px|center]]
*Setup 2:You can install accessories in the motor and the axis according to project needs, and then fix them on other materials.  
+
*Setup 2: You can install accessories in the motor and the axis according to project needs, and then fix them on other materials.  
 
[[File: _304_DozingDonkey _Motor1.jpg|400px|center]]
 
[[File: _304_DozingDonkey _Motor1.jpg|400px|center]]
*Setup 3:Connect the activated battery box with BM module.  
+
*Setup 3: Connect the activated battery box with BM module.  
 
[[File:CoreUSB_Ble_steup2.jpg|600px|center]]
 
[[File:CoreUSB_Ble_steup2.jpg|600px|center]]
*Setup 4:Connect all devices to a computer with a USB cable.
+
*Setup 4: Connect all devices to a computer with a USB cable.
 
[[file:mCookie-n20-pc.JPG|600px|center]]
 
[[file:mCookie-n20-pc.JPG|600px|center]]
  
Line 121: Line 121:
 
* Open Arduino IDE and copy the following codes to IDE.
 
* Open Arduino IDE and copy the following codes to IDE.
 
<source lang="cpp">
 
<source lang="cpp">
//( D6,D8) controls motor (1A,1B)  
+
//( D6, D8) controls motor (1A, 1B)  
 
#define OUT1A 6
 
#define OUT1A 6
 
#define OUT1B 8
 
#define OUT1B 8
//( D5,D7) controls motor (2A,2B)  
+
//( D5, D7) controls motor (2A, 2B)  
 
#define OUT2A 5
 
#define OUT2A 5
 
#define OUT2B 7
 
#define OUT2B 7

Latest revision as of 23:59, 29 March 2017

Outline

Direct current speed reduction motor: Compared with the ordinary DC motor, it is equipped with gear speed reduction box, which offers lower rotation rate and larger torque, enhancing the use rate of the DC motor in the automation industry.

Specification

Speed Reduction DC Motor

  • Electrical specification
    • Operation voltage: 5V
  • Tech parameters

Development

Equipment

Module Number Function
mCookie-CoreUSB 1 Core board
mCookie-Motor 1 DC motor drive board
mCookie-BM 1 Power supply
  • Other Hardware Equipment
    • DC motor
    • One USB cable

Wire Connection of DC Motor

  • Connect a DC motor to (OUT1A, OUT1B) and the other motor to (OUT2A, OUT2B);
  • DC motor control pin:
//(D6,D8) controls (1A,1B) motor 
#define OUT1A 6
#define OUT1B 8
//(D5,D7) controls (2A,2B) motor  
#define OUT2A 
#define OUT2B 7

===Preparation

  • Setup 1: Connect a motor to the Motor module as the diagram showed above;
304 DozingDonkey Motor.jpg
  • Setup 2: You can install accessories in the motor and the axis according to project needs, and then fix them on other materials.
304 DozingDonkey Motor1.jpg
  • Setup 3: Connect the activated battery box with BM module.
CoreUSB Ble steup2.jpg
  • Setup 4: Connect all devices to a computer with a USB cable.

Experiment 1: Connection and disconnection control

6 8 5 7 1A 1B 2A 2B Function
Low Low Low Low Off Off Off Off Close (Stop habitually)
High Low High Low High Low High Low Rotate clockwise
Low High Low High Low High Low High Rotate counter clockwise
High High High High Low Low Low Low Halt
  • Open Arduino IDE and copy the following codes to IDE.
#define OUT1A 6
#define OUT1B 8
#define OUT2A 5
#define OUT2B 7

void setup()
{
  pinMode(OUT1A, OUTPUT);
  pinMode(OUT1B, OUTPUT);
  pinMode(OUT2A, OUTPUT);
  pinMode(OUT2B, OUTPUT);
}

void loop()
{
head();
delay(2000);
back();
delay(1000);
stop();
delay(500);
}

void head()
{
  digitalWrite(OUT1A, HIGH);
  digitalWrite(OUT1B, LOW);
  digitalWrite(OUT2A, HIGH);
  digitalWrite(OUT2B, LOW);
}
void back()
{
  digitalWrite(OUT1A, LOW);
  digitalWrite(OUT1B, HIGH);
  digitalWrite(OUT2A, LOW);
  digitalWrite(OUT2B, HIGH);
}
void stop()
{
  digitalWrite(OUT1A, LOW);
  digitalWrite(OUT1B, LOW);
  digitalWrite(OUT2A, LOW);
  digitalWrite(OUT2B, LOW);
}
  • Select the right port from Tools→Serial Port in Arduino IDE after compiling, then download program.
Upload.JPG
  • After download, you'll see the DC motor rotates forward 2s, reverse 1s and stops for 0.55s.

=Debugging

  • Control the rotation of the motor by the " digitalWrite(pin, xx);" function outputting high and low level signals.

Experiment 2: PWM Motor Speed Control

  • Open Arduino IDE and copy the following codes to IDE.
//( D6, D8) controls motor (1A, 1B) 
#define OUT1A 6
#define OUT1B 8
//( D5, D7) controls motor (2A, 2B) 
#define OUT2A 5
#define OUT2B 7

void setup()
{
  pinMode(OUT1A, OUTPUT);
  pinMode(OUT1B, OUTPUT);
  pinMode(OUT2A, OUTPUT);
  pinMode(OUT2B, OUTPUT);
}

void loop()
{
  for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5)
    //Loop statement. Along with PWM rate increases, you can change brightness level by controlling fadeValue. 
  {
    analogWrite(OUT1A, fadeValue);  //Write rate level into the motor 
    digitalWrite(OUT1B, LOW);
    analogWrite(OUT2A, fadeValue);
    digitalWrite(OUT2B, LOW);
    delay(100);                       //Delay time of rate. (The unit is ms)
  }
  for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5)
    // Loop statement. Along with PWM rate decreases, you can change brightness level by controlling fadeValue.
  {
    digitalWrite(OUT1A, LOW);
    analogWrite(OUT1B, fadeValue);  // Write rate level into the motor
    digitalWrite(OUT2A, LOW);
    analogWrite(OUT2B, fadeValue);
    delay(100);                     // Delay time of rate. (The unit is ms)
  }
  delay(1000);
}
  • Select the right port from Tools→Serial Port in Arduino IDE after compiling, then download program.
Upload.JPG
  • Open the serial monitor after download and input angle (0-180) in the serial input box, then click "Send".
  • From the result you can see that the speed is increasingly fast to the upmost and then slow download and finally circulates.

Program Debugging

  • Adopt "for" function to control cyclic speed change
  • Adopt " analogWrite(pin, XX);" function to control speed.
    • pin: It has to be PWM control pin, which can be D5,D6,D7,D8 for mCookie-CoreUSB.
    • XX: The value range is 0-225. The larger is value is, the quicker the speed becomes. ==Project==

Video