You are currently viewing How to Interface Stepper Motor with LPC2148 ARM7 Development Board

How to Interface Stepper Motor with LPC2148 ARM7 Development Board

Spread the love

The ARM7 LPC2148 Development board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port.

NXPโ€™s ARM7 (LPC2148), ARM Development Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 32-bit Microcontrollers.

Stepper Motor

A stepper motor is a brushless, synchronous electric motor that converts digital pulses into mechanical shaft rotation. Every revolution of the stepper motor is divided into a discrete number of steps, and the motor must be sent a separate pulse for each step.

Interfacing Stepper Motor

Fig. 1 shows how to interface the Stepper Motor to microcontroller. As you can see the stepper motor is connected with Microcontroller output port pins through a ULN2803A array. So when the microcontroller is giving pulses with particular frequency to ULN2803A, the motor is rotated in clockwise or anticlockwise.

interfacing stpper motor to microcontroller
Fig. 1 Interfacing Stepper Motor to Microcontroller

Interfacing Stepper Motor with LPC2148

Controlling a stepper motor using LPC2148 Development Board. It works by turning ON & OFF a four I/O port lines generating at a particular frequency.

The ARM7 LPC2148 Development Board has four numbers of I/O port lines, connected with I/O Port lines (P1.16 โ€“ P1.19) to rotate the stepper motor. ULN2803 is used as a driver for port I/O lines, drivers output connected to stepper motor, connector provided for external power supply if needed.

Pin Assignment with LPC2148

Circuit Diagram to Interface Stepper Motor with LPC2148

Circuit Diagram to Interface Stepper Motor with LPC2148

Source Code

The Interfacing stepper motor control with LPC2148 program is very simple and straight forward, that control the stepper motor in clockwise, counter clockwise and also a particular angular based clockwise by using switches. The I/O port lines are used to generate pulses for stepper motor rotations. C programs are written in Keil software.

C Program to control stepper motor using LPC2148


Title : Program to control stepper motor rotations


#include  // Define LPC2148 Header File

#define SW1 24 //SW1 (P1.24)
#define SW2 25 //SW2 (P1.25)
#define SW3 26 //SW3 (P1.26)
#define COIL_A 16 //change the Stepper Motor Port! 
void motor_cw(void);
void motor_ccw(void);
void delay(int);
unsigned char STEP[] = {0x09, 0x08, 0x0C, 0x04, 0x06, 0x02, 0x03, 0x01};
void main(void)
unsigned char i = 0;
PINSEL2 &= 0xFFFFFFF3; // P1.16 - P1.31 as GPIO 
IODIR1 = 0x000F0000; // P1.16 - P1.19 as Output 
while(1) // Loop forever 
if (!(IOPIN1 & (1<<SW1))) // Switch SW1 ON/OFF 
motor_cw(); // Stepper Motor clockwise 
else if (!(IOPIN1 & (1<<SW2))) // Switch SW2 ON/OFF 
motor_ccw();  // Stepper Motor anticlockwise
else if (!(IOPIN1 & (1<<SW3)))// Switch SW3 ON/OFF
while (i < 12)
motor_cw ();  // clockwise for req. angle 
else i = 0;
void delay(int n)
int i,j;
void motor_ccw(void)
unsigned int i=0;
while (STEP[i] != '\0')
delay(1); i++;
void motor_cw(void)
int i = 7; while (i >= 0)

To compile the above C code you need the KEIL software. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Keil, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without LPC2148 Development Board.

The Flash Magic software is used to download the hex file into your microcontroller IC LPC2148 through UART0.

Testing the Stepper Motor with LPC2148

Give +3.3V power supply to LPC2148 Development Board; the Stepper Motor is connected with LPC2148 Development Board. When the program is downloading into LPC2148 in Primer Board, the LED output is working that the LED is ON some time period and the LED is OFF some other time period for a particular frequency. Now, the stepper motor is rotating.

โ˜žIf you are pressed switch sw1, then the stepper motor is rotating in clockwise direction.

โ˜žIf you are pressed switch sw2, then the stepper motor rotating in anti-clockwise direction.

โ˜žIf you are pressed switch sw3, then the motor is rotating the required angle which angle is set in code.

If you are not reading any output from LED, then you just check the jumper connections & check the LED is working.

If the stepper motor is not rotating then check the motor connections. Otherwise you just check the code with debugging mode in Keil. If you want to see more details about debugging just see the videos in below link.

โ˜žHow to Create & Debug a Project in Keil.

General Information

โ˜žFor proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.

โ˜žSolder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.

โ˜žUse the exact value crystal shown in schematic.

โ˜žMore instructions are available in following articles,

User Manual ARM7-LPC2148 Development Kit

Creating & Debugging a Project in KEIL

How to Interface LEDs with LPC2148 ARM7 Development Board

How to Interface Switch with LPC2148 ARM7 Development Board

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.