Announcement

Collapse
No announcement yet.

Arduino - DC Motor Controller

Collapse
X
Collapse

  • Arduino - DC Motor Controller

    PES-2604 is an easy-to-use DC motor controller for Arduino Uno and Mega.
    Library and example for the DC motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

    This tutorial shows how to use the DC motor controller with an example of PhpocExpansion library for Arduino.


    Hardware Required

    Note that: we can use DC motor controller to control:
    • DC motor with two-phase encoder.
    • DC motor with one-phase encoder. However, in this case, we cannot get the rotating direction of DC motor.
    • DC motor without encoder. However, in this case, we cannot get position, speed, and rotating direction of DC motor.



    Note that: Power supply for Arduino and power supply for DC motor should be separate. In case of DC motor requires very low current and low voltage, it can be use the same power with Arduino.



    Wiring
    • Stack PHPoC Shield or PHPoC WiFi Shield on Arduino
    • Stack DC motor controller PES-2604 on PHPoC Shield or PHPoC WiFi Shield
    • Connect the terminal block of DC motor controller to DC motor and power supply for DC motor as follows:
      • Terminal Block - VM <----> (+) wire - power supply for DC motor
      • Terminal Block - GND <----> (-) wire - power supply for DC motor
      • Terminal Block - M1+ <----> (+) wire - DC motor
      • Terminal Block - M1- <----> (-) wire - DC motor
    • (Optional) Connect the encoder port of DC motor controller to encoder pin of DC motor as follows:
      • Encoder 1 - 5V <----> Vcc - Encoder of DC motor
      • Encoder 1 - GND <----> GND - Encoder of DC motor
      • Encoder 1 - 1A <----> A phase - Encoder of DC motor
      • Encoder 1 - 1B <----> B phase - Encoder of DC motor

      Encoder 1 is located on the upper row of encoder port. More detail is here




    The DC motor controller can connect and control/monitor two DC motors simultaneously. This tutorial present the use of one DC motor. Adding the another DC motor is similar.

    Install Arduino IDE

    If you have not install Arduino IDE yet, please download and install Arduino IDE .





    Install Library
    • Run Arduino IDE.
    • Navigate to Sketch > Include Library > Manage Libraries

    • Search "Phpoc Expansion" on search bar of the Library Manager.

    • Select the PhpocExpansion library and press the [Install] button.

    • Restart Arduino IDE for the next step.



    Source Code
    • Connect Arduino to PC via usb cable
    • Open Arduino IDE
    • Open "ExpansionDCMotor" example
    • Compile the example code and uploads to Arduino by clicking "Upload" button on Arduino IDE
    • Open "Serial Monitor" tool on Arduino IDE to see the output log:

      (position, period and speed depend on motor, encoder and power supply )

    Code Explanation

    At the beginning
    we need to create and DC motor object:
    Code:
    ExpansionDCMotor dcm1(expansionId, 1);
    where 1 is the first motor, expansionId is address of expansion board that are set via DIP switch on expansion board. By using the different expansionId, we can stack multiple expansion board on a single Arduino Uno or Mega.
    You can change it and map it to the below to know the value.




    Note that: DC Motor Controller is one of the expansion boards. List of expansion for arduino is available here

    In setup() function
    • Phpoc.begin() and Expansion.begin() functions must be used to initial PHPoC [WiFi] Shield and expansion board, repectively.
    • Serial.println(dcm1.getName()) function is used optionally to get name of expansion board and print it to serial.
    • There are some functions has been commented.
      Code:
      	//dcm1.setPolarity(-1);
      	//dcm1.setDirection(-1);
      	//dcm1.setDecay(1);
      	//dcm1.setEncoderPolarity(-1);
      	//dcm1.setEncoderPosition(100000);
      	//dcm1.setEncoderPSR(32);
      	//dcm1.setFilterFrequency(5000);
      	//dcm1.setFilterPNC(0);
      These functions are optional and used for advanced setting. Refer to PHPoC Shield Expansion Library Reference for more information about these functions.
    • dcm1.setPeriod(10000); function is used to set PWM period.


    In loop() function
    There are some functions are used.
    • dcm1.setWidth(width): set duration of the high-voltage level in a PWM cycle to control DC motor. If width is 0, DC motor stops rotating.
      Duty cycle of PWM = width in setWidth() / period in setPeriod().
    • dcm1.getEncoderPosition(): get encoder position, unit is pulse
    • dcm1.getEncoderPeriod(): get encoder period, unit is microsecond per pulse.
      when encoder period is known, speed of DC motor can be calculated as follows:
      speed = 1000000 / period
      Unit is pulse per second.



    See Also


    References
      Posting comments is disabled.

    Categories

    Collapse

    Latest Articles

    Collapse

    • Arduino - RS-485 Expansion Board
      support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 03:45 PM
    • Arduino - RS-422 Expansion Board
      support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 03:44 PM
    • Arduino - RS-232 Expansion Board
      support
      PES-2606 is an easy-to-use RS-232 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS-232.
      Especially, Arduino does NOT use UART pins to communicate with RS-232 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS-232 expansion boards (up to 14) without using Arduino UART pins.

      Library and example for the RS-232 expansion board...
      11-13-2018, 03:43 PM
    • Arduino - Stepper Motor Controller
      support
      PES-2605 is an easy-to-use stepper motor controller for Arduino Uno and Mega, which uses micro-stepping method to precisely control stepper motor.
      Library and example for the stepper motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the step motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 03:41 PM
    • Arduino - DC Motor Controller
      support
      PES-2604 is an easy-to-use DC motor controller for Arduino Uno and Mega.
      Library and example for the DC motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the DC motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 03:40 PM
    • Arduino - Digital Input Board
      support
      PES-2602 is an easy-to-use 4-port Input Expansion Board for Arduino Uno and Mega, which allows Arduino to monitor state of DC electric device. In addition, it can monitor NPN, PNP and dry contact(relay).
      Library and example for the 4-port input expansion board are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use 4-port input expansion board with an example of PhpocExpansion library for Arduino.

      ...
      11-13-2018, 03:39 PM
    Working...
    X