Small DC 3V-6V Hobby Motor 2000RPM If the DC motors seem to 'cut out' or 'skip', solder a ceramic or disc 1uF capacitor between the motor tabs (on the motor itself!) as it helps to reduce noise and interference This small hobby DC motor can be controlled using 1. IRF520 MOSFET module 2. Transistor 3. LS9110S H-Bridge It must not be connected directly to an output of the board because it draws too much current. Model 130 Weight: 17g Axial length of 38mm outside diameter: 20mm Support Voltage 3V to 6V DC No Loading : 3V Current : 0.14A locked - rotor current is 0.92A 6V Current : 0.18A locked - rotor current is 1.5A
Example1 Using a Transistor This example uses a common transistor to provide enough current to drive the motor Components Needed: Board, breadboard and wires TIP120 transistor (can handle up to 5A with heat-sink) 100k Potentiometer, 470 ohm resistor IN4001 diode general purpose or 6V external battery 1A Pin A0 (Input) 10K Potentiometer SIG Pin 3 (Output) 470 Ohm Resistor Base External battery, Diode (Anode) Collector, Motor ve, Diode (Cathode) Extn Collector, Motor +ve Code Example1 // Driving a small 3V-6V DC Motor using a transistor // Note: the motor draws up to 1.5A at 6V so must be powered by an external PSU and also must not // be connected directly to an output pin of the // The 470 ohm to the base of the transistor protects the output pin of the from supplying too // much current when the transistor is ON */ #include <.h> const int PotPin = A0; const int MotorPin = 3;
int MotorSpeedVal; void setup() { pinmode( MotorPin,OUTPUT); void loop() { // read analog input (0-1023) and divide by 4 to generate output in range 0-255 // 0 will be off, 255 will correspond to a PWM of 100% MotorSpeedVal = analogread( PotPin ) / 4; // an alternative way is to use the map function // MotorSpeedVal = map(analogread(potpin), 0, 1023, 0, 255) // write the value to the transistor which controls the motor analogwrite( MotorPin, MotorSpeedVal ); Example 2 Using IRF520 MOSFET Module In this example we will use a 10K potentiometer to control the speed of the motor, and an IRF520 MOSFET Module to provide enough current for the motor. Components Needed: Board IRF520 MOSFET Module Breadboard and wires 100k Potentiometer or 6V external battery 1A
MOSFET CONNECTIONS SIG PWM from Vin V- Connect to motor V+ Connect to motor Circuit Diagram Pin 3 (Output PWM) 6V Battery +ve 6V Battery ve IRF520 Board SIG Vin Motor +ve V+ Motor ve V- Pin A0 (Input) 100K Potentiometer Sig Code Example2 // Driving a small 3V-6V DC Motor using the IRF520 Module board // Note: the motor draws up to 1.5A at 6V so must be powered by an external PSU and also must not // be connected directly to an output pin of the /* Connections wire as follows Pin 3 (Output PWM) 6V Battery +ve 6V Battery ve IRF520 Board SIG Vin Motor +ve V+ Motor ve V- */ Pin A0 (Input) 100K Potentiometer Sig #include <.h> const int PotPin = A0; const int MotorPin = 3;
int MotorSpeedVal; void setup() { pinmode( MotorPin,OUTPUT); void loop() { // read analog input (0-1023) and divide by 4 to generate output in range 0-255 MotorSpeedVal = analogread( PotPin ) / 4; // write the value to the IRF520 which controls the motor analogwrite( MotorPin, MotorSpeedVal ); Example 3-1 Using the LS9110S H-Bridge The board has 6 male pins and 2 double terminals. The motors connect to the 2 terminals. In the middle of the male pins are the and pins. This is the input voltage for the L9110 chips. Some H-bridges like the L293 and L298 require a logic voltage and a separate voltage for the motors, the L9110 does not. You only have to supply it one voltage (between 2.5 and 12V). The other 4 pins control the direction and speed of the motors. Pin A-IA and A-IB control motor A, and Pin B-IA and B-IB control motor B. To control motor A you set pin A-IA high and pin A-IB low, to change the direction you just set pin A-IA low and pin A-IB high. Same thing for motor B. To control the speed of both motors 4 PWM pins are required; instead of just setting a pin high you pwm it.
Connections Motor +ve Motor ve 100K SIG 100K 100K LS9110S Board Battery 6V Motor A PWR Motor A 6V A-IA Pin 3 A-IB Pin 5 Pin A0 Code Example 3_1_LS9110S // Driving a small 3V-6V DC Motor using the LS9110S Module board // Note: the motor draws up to 1.5A at 6V so must be powered by an external PSU and also must not // be connected directly to an output pin of the // Example 3_1, simple forward direction /* Connections wire as follows LS9110S Board Battery 6V Motor +ve Motor A PWR Motor ve Motor A 6V A-IA Pin 3 A-IB Pin 5 100K SIG Pin A0 100K 100K */ #include <.h> /* choose PW pins for MotorPinA and B */ const int PotPin = A0; const int MotorPinA = 5; const int MotorPinB = 6; int MotorSpeedVal; void setup() { pinmode( MotorPinA,OUTPUT); pinmode( MotorPinB,OUTPUT); void loop() { // read analog input (0-1023) and divide by 4 to generate output in range 0-255 MotorSpeedVal = analogread( PotPin ) / 4; // write the value to the two pins of the LS9110S which controls the motor // forward direction // set MotorPinB low for forward and control speed via MotorPinA analogwrite(motorpinb, 0);
analogwrite( MotorPinA, MotorSpeedVal ); // NOTE: MPA=High, MPB = Low, forward, MPA=Low, MPB=High, reverse The LS9110S is capable of reversing the direction of the motor. This is controlled by the A-IA and A-IB levels for Motor A. In the next example, a push button is used to reverse the direction of the motor. Example 3-2 Using the LS9110S H-Bridge - Reversing This example uses a Push Button to reverse the direction of the motor. Each time the button is pressed, the motor will reverse direction. Code Example 3_2_LS9110S // Driving a small 3V-6V DC Motor using the LS9110S Module board // Note: the motor draws up to 1.5A at 6V so must be powered by an external PSU and also must not // be connected directly to an output pin of the // Example 3_2, reversing direction using a push button /* Connections wire as follows LS9110S Board Battery 6V Motor +ve Motor A PWR Motor ve Motor A 6V A-IA Pin 3 A-IB Pin 5 100K SIG Pin A0
*/ 100K 100K Push Button Push Button to Pin 4 and then via 2.2K Ohm to #include <.h> /* choose PW pins for MotorPinA and B */ const int PotPin = A0; const int PBPin = 4; const int MotorPinA = 5; const int MotorPinB = 6; // define constants for Forward and Reverse const int FORWARD = 1; const int REVERSE = 0; int MotorSpeedVal; int state = FORWARD; // the current state of the motor direction int reading; // the current reading from the PBpin int previous = LOW; // the previous reading from the PBpin // the follow variables are long's because the time, measured in milliseconds, // will quickly become a bigger number than can be stored in an int long time = 0; // the last time the output pin was toggled long debounce = 200; // the debounce time void setup() { pinmode(pbpin, INPUT); pinmode( MotorPinA,OUTPUT); pinmode( MotorPinB,OUTPUT); // initialize and start the motor forward // read analog input (0-1023) and divide by 4 to generate output in range 0-255 MotorSpeedVal = analogread( PotPin ) / 4; // write the value to the two pins of the LS9110S which controls the motor // forward direction // set MotorPinB low for forward and control speed via MotorPinA analogwrite(motorpinb, 0); analogwrite( MotorPinA, MotorSpeedVal ); // NOTE: MPA=High, MPB = Low, forward, MPA=Low, MPB=High, reverse void loop() { // read analog input (0-1023) and divide by 4 to generate output in range 0-255 MotorSpeedVal = analogread( PotPin ) / 4; // read the PBPin state reading = digitalread(pbpin); // if the input just went from LOW and HIGH and we've waited long enough // to ignore any noise on the circuit, then we need to reverse direction if (reading == HIGH && previous == LOW && millis() - time > debounce) { if (state == HIGH) state = LOW;
else state = HIGH; time = millis(); if ( state == LOW ) { // reverse // write the value to the two pins of the LS9110S which controls the motor // forward direction // set MotorPinA low for Reverse and control speed via MotorPinB analogwrite(motorpina, 0); analogwrite( MotorPinB, MotorSpeedVal ); // NOTE: MPA=High, MPB = Low, forward, MPA=Low, MPB=High, reverse else { // forward // write the value to the two pins of the LS9110S which controls the motor // forward direction // set MotorPinB low for Forward and control speed via MotorPinA analogwrite(motorpinb, 0); analogwrite( MotorPinA, MotorSpeedVal ); // NOTE: MPA=High, MPB = Low, forward, MPA=Low, MPB=High, reverse previous = reading; Example 4 Using the L293D Motor Control H-Bridge Shield The H-bridge is provided with a library class and that is used to control the motor. Connections Remove the EXTN PWR jumper on the L293D board Connect up external power to the L293D board Power the from USB or its own Power Supply Source Motor +ve Motor ve Battery 6V +ve Battery 6V L293D Board M1 PWR M1 EXT PWR EXT PWR
If you would like to have the powered from USB and the motors powered from a DC power supply, plug in the USB cable. Then connect the motor supply to the PWR_EXT block on the shield. Do not place the jumper on the shield. This is a suggested method of powering your motor project If you would like to have 2 separate DC power supplies for the and motors. Plug in the supply for the into the DC jack, and connect the motor supply to the PWR_EXT block. Make sure the jumper is removed from the motor shield. Code Example 4 // Driving a small 3V-6V DC Motor using the L293D Module board // Note: the motor draws up to 1.5A at 6V so must be powered by an external PSU and also must not // be connected directly to an output pin of the /* wire the motor to MC1 on the L293D board and plug the L293D shield into the board Remember to supply external power to the L293D board Copy the AFMotor library */ #include <.h> #include <AFMotor.h> AF_DCMotor motor(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Motor test!"); motor.setspeed(200); // set the speed to 200/255 void loop() { Serial.print("forward"); motor.run(forward); // turn it on going forward delay(2000); Serial.print("reverse"); motor.run(backward); // the other way delay(2000); Serial.print("stop"); motor.run(release); // stopped delay(2000);