In this illustration we will going to wire the IRF520 MOSFET (Metal Oxide Semiconductor Field-effect Transistor) Module Board a simple breakout board for driving higher loads. MOSFET enables you to control higher voltage projects on microcontroller. MOSFET is also kind of a switch that isolate the power from the main load, when the power load to the MOSFET it will pass the power from one to another when closed, but if the outer power source is absent your device can still draw power from microcontroller.
In this illustration we will going to use to MOSFET Module board, we connect the power for the device you want to control to the VIN and GND then connect your control a pump, LED, or other DC device, to V+ and V- up to 24v, and ~5A. You can also power this device from your Arduino to 5v VCC connection and GND pin.
Note: Use only one power source do not plug two power source.
Required Components
Arduino UNO/MEGA/PRO/MINI
MOSFET IRF520 Module Board
12v DC Motor / 24v DC Motor
100k/10k Potentiometer / Variable Resistor
Solder Less Bread Board
Jumper Wires
Motor Suppressor is Optional
Wiring Diagram
Arduino Sketch Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/*__________________________________________________________ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 14CORE.com ARDUINO MOSFET MOTOR TEST $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ____________________________________________________________ */ #include "HCMotor.h" //Include HCMotor Code Library #define MOTOR_PIN 6 // Assign to PWM/Digital Pin 6 #define POT_PIN A0 // Set analog pin at A0 for the potentiometer HCMotor HCMotor; // Create an instance of our code library void setup() { HCMotor.Init(); //Initialise our library HCMotor.attach(0, DCMOTOR, MOTOR_PIN); // Attach our motor to 0 to digital pin 6 HCMotor.DutyCycle(0, 100); //Set duty cycle of the PWM Pulse with Modulation signal in 100uS increment to 100uS = 1mS cycle } void loop() { int Speed; Speed = map(analogRead(POT_PIN), 0, 1024, 0, 100); //Reading the A0 pin to determine the position of the pot. //mapping the motor which could be 0 - 1024 and reduce down to match the cyccle range of 0 to 100 HCMotor.OnTime(0, Speed); // Set the duty cycle to match the position } |
Download the Motor Control Library here | Zip
Libs are correctly installed ( yes i closed out the IDE before install) but seems like there is some issues
Arduino: 1.6.5 (Windows 7), Board: “Arduino Leonardo”
D:\Program Files (x86)\Arduino\libraries\HCMotor\HCMotor.cpp: In member function ‘void HCMotor::_MotorTimer2Init(byte, byte)’:
D:\Program Files (x86)\Arduino\libraries\HCMotor\HCMotor.cpp:49:2: error: ‘TCCR2A’ was not declared in this scope
TCCR2A = (1<<WGM21);
^
D:\Program Files (x86)\Arduino\libraries\HCMotor\HCMotor.cpp:49:15: error: 'WGM21' was not declared in this scope
TCCR2A = (1< Preferences.
Make it sure variable TCCR2A is declared. ………….