DC Motor Interfacing with ARM MBED

Overview of DC Motor

DC Motor

 

  • DC motor converts electrical energy in the form of Direct Current into mechanical energy in the form of rotational motion of the motor shaft.
  • The DC motor speed can be controlled by applying varying DC voltage; whereas the direction of rotation of motor can be changed by reversing the direction of current through it.
  • For applying varying voltage, we can make use of PWM technique.
  • For reversing the current, we can make use of H-Bridge circuit or motor driver ICs that employ the H-Bridge technique.

For more information about DC motors and how to use them, H-Bridge circuit configurations, and PWM technique,  DC Motors refer the topic DC Motors in the sensors and modules section.

 

Connection Diagram of DC Motor with ARM MBED (LPC1768)

Interfacing DC Motor with ARM MBED

 

Control DC Motor using ARM MBED (LPC1768)


Here, we are going to control the speed and rotational direction of DC motor using ARM MBED.

Here, the potentiometer is used as a means for speed control and an input from the tactile switch is used to change the direction of motor.

The L293D motor driver IC is used to drive the DC motor.

You can refer functions required for PWM, External Interrupt, and ADC.

 

DC Motor Code for ARM MBED (LPC1768)

#include "mbed.h"
#include "Motor.h"

Motor Motors(p22, p6, p7);
AnalogIn pot(p15);
DigitalOut LED_1(LED1);
InterruptIn button(p9);
float potpin;
int pin;

void flip()
{
    pin = !pin;
    LED_1 = !LED_1;
}

int main() {
    button.rise(&flip);
    while(1) {
        if (pin == 1){
        potpin = pot.read();
        Motors.speed(-potpin);
        }
        
        else {
        potpin = pot.read();
        Motors.speed(potpin);
        }
    }
}

Components Used

ARM mbed 1768 LPC1768 Board
ARM mbed 1768 Board
1
L293D Driver
L293D Driver
1

Downloads

DC_Motor_mbed_uvision5_lpc1768 Download
Ad