DC Motor Interfacing with MSP-EXP430G2 TI Launchpad

Overview of DC Motor

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 the motor can be changed by reversing the direction of current through it.

For applying varying voltage, we can make use of the 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, refer to the topic DC Motors in the sensors and modules section.


Connection Diagram of DC Motor with MSP-EXP430G2 TI Launchpad

Interfacing DC Motor with MSP-EXP430G2 TI Launchpad
Interfacing DC Motor with MSP-EXP430G2 TI Launchpad


Control the speed and rotational direction of the DC motor using the MSP-EXP430G2 TI Launchpad

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

L293D motor driver IC is used for controlling the direction of the motor.

PWM wave generated on the MSP-EXP430G2 TI Launchpad is used to provide a variable voltage to the motor through L293D. In Energia, the analogWrite function is used to generate the PWM wave.


Tread Carefully: MSP-EXP430G2 TI Launchpad board has a RAM of 512 bytes which is easily filled, especially while using different libraries. There are times when you need the Serial buffer to be large enough to contain the data you want and you will have to modify the buffer size for the Serial library. While doing such things, we must ensure that the code does not utilize more than 70% RAM. This could lead to the code working in an erratic manner, working well at times, and failing miserably at others. 

There are times when the RAM usage may exceed 70% and the codes will work absolutely fine, and times when the code will not work even when the RAM usage is 65%. 

In such cases, a bit of trial and error with the buffer size and/or variables may be necessary.


Direction and Speed Control of DC Motor Code for MSP-EXP430G2 TI Launchpad

const int pot_input = A4;
bool d1 = HIGH;
bool d2 = LOW;

void setup() {
  pinMode(12, OUTPUT);  /* Motor control pin 1 */
  pinMode(13, OUTPUT);  /* Motor control pin 2 */
  pinMode(14, OUTPUT);  /* PWM pin for Speed Control */
  pinMode(5, INPUT_PULLUP);  /* Interrupt pin for direction control */
  attachInterrupt(5, motor, FALLING);	/* Interrupt on falling edge on pin 5 */

void loop() {
  int pwm_adc;
  pwm_adc = analogRead(pot_input); /* Input from Potentiometer for speed control */
  analogWrite(14, pwm_adc / 4);    

void motor(){
  d1 = !d1;
  d2 = !d2;
  for(int i = 0; i<10000; i++)
  for(int j = 0; j<10; j++);


Video of DC Motor Speed Control using MSP-EXP430G2 TI Launchpad


DC Motor Function Used

attachInterrupt(pin, ISR, mode)
  • This function is used to configure the mode of interrupt event and declare the ISR for that interrupt. The interrupt event and ISR are for the interrupt pin declared in the function.
  • ISR in this function is the name of the ISR that will be used for this interrupt.
  • the mode defines when the interrupt will be triggered. There are four modes available to choose from :
    - LOW: trigger the interrupt whenever the pin is low.
    - CHANGE: trigger the interrupt whenever the pin changes value.
    - RISING: trigger when the pin goes from low to high.
    - FALLING: trigger when the pin goes from high to low.
  • For example, attachInterrupt(2, motor, FALLING) configures digital pin 2 as an interrupt pin with ISR named motor and which generates an interrupt for every falling edge event on pin 2.

Components Used

TI Launchpad MSP-EXP430G2
TI Launchpad MSP-EXP430G2
L293D Driver
L293D Driver


DC_Motor_Interfacing_With_TI_Launchpad_INO Download