Trending

How to make a motor driver for arduino using MOSFET


Introduction- 

A motor driver or motor shield is an electronic device that allows you to control the speed and the direction of the motors using a micro-controller. It also allows you to connect separate power supply for the motors.

MOSFET-

A MOSFET(Metal oxide semiconductor field-effect transistor) is a semiconductor device which is widely used for switching and amplification of the electronic signals.

Now, without going into deep about the working of the MOSFET, we can represent it as a switch.

Pin-outs for the power MOSFET-





Connections for the motor driver- 

1. Connect the digital pin of the Arduino to the gate of the MOSFET.
2. Connect the ground of the Arduino and the power supply to the source of the MOSFET.
3. Connect a 10k ohm resistor between Arduino digital pin and ground to protect the micro-controller.
4. Connect the power supply +ve to the motor and then connect the -ve terminal of the motor to the drain of the MOSFET.

The circuit schematic is given below-



Example code for motor speed control-

int motor = 9;           
int mspeed = 0;    
int rpmvalue = 5;    

void setup()
{
  
  pinMode(motor, OUTPUT);
  
}

void loop()
{
  
  analogWrite(motor, mspeed);

  
  mspeed = mspeed + rpmvalue;

  if (mspeed <= 0 || mspeed >= 255) 
  {
    rpmvalue = -rpmvalue;
  }
  
  delay(30);
}


Example for ON/OFF switch control for motor-


void setup()
{
  pinMode( 9, OUTPUT);
}

void loop() {
  digitalWrite(9, HIGH);   // turn the motor
  delay(1000);                        // wait for a second
  digitalWrite(9, LOW);    // turn of the motor
  delay(1000);                       //  wait for a second
}

1 comment: