How to Interface Relay with LPC2148 ARM

Relay Interfacing With ARM Primer

Tags: ARM7 LPC2148 Primer Board, Interfacing Relays, how to interface Relay to microcontroller, Interfacing Relay with LPC2148, Circuit Diagram to Interface Relay with LPC2148, C Program to control Relay in LPC2148, Source Code to control Relay in LPC2148,
Overall rating
ARM7 LPC2148 Primer Board

The ARM7 LPC2148 Primer 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 Primer Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 32-bit Microcontrollers.


Relays are devices which allow low power circuits to switch a relatively high Current/Voltage ON/OFF. A relay circuit is typically a smaller switch or device which drives (opens/closes) an electric switch that is capable of carrying much larger current amounts.

Interfacing Relays

Fig. 1 shows how to interface the Relay to microcontroller. There are 2 input channels. Each input is connected to the triggering coil of the respective relay. There are 2 output channels that each correspond to an input. When the input is energized, the relay turns on and the '+' output is connected to +12v. When the relay is off, the '+' output is connected to Ground. The '-' output is permanently wired to Ground.


Fig. 1 Interfacing Relay to Microcontroller

Interfacing Relay with LPC2148

Control the relay operations by using LPC2148 Primer Board. Here we are using two Relays. The relay consists of a coil and a switch. When the coil is energized, the switch closes, connecting the two contacts together. ULN2803 is used as a driver for port I/O lines, drivers output connected to relay modules. Connector provided for external power supply if needed.

Relay Module : Port P1 pins (Realy1 – P1.20) and Relay2-P1.21) for relay module, make port pins to high, relay will activated.

Pin Assignment with LPC2148




LPC2148 Lines

RELAY Power Select

RELAY Modules






Note      : Relay selection make switch SW28 to SM/RL label marking position


Circuit Diagram to Interface Relay with LPC2148


Source Code

The Interfacing Relay with LPC2148 program is very simple and straight forward, which control the relays in LPC2148 Primer Board. The relay is working that uses a delay procedure loop based software delay. The C programs are developed in Keil software.

C Program to control Relay in LPC2148


Title : Program to control Relay




#include <LPC214x.h>

#include <stdio.h>


#define RLY1   20   //RLY1 (P1.20)

#define RLY2   21   //RLY2 (P1.21)


void main(void)


   PINSEL2   =   0x00;

   IODIR1 = 1 << RLY1;    //Configure P1.20 Output

   IODIR1 |= 1 << RLY2;   //Configure P1.21 Output


   while(1)               //loop forever


         IOSET1   =   1 << RLY1;


         IOCLR1   =   1 << RLY1;


         IOSET1   =   1 << RLY2;


         IOCLR1   =   1 << RLY2;





void Delay()


   unsigned int i,j;

   for(i=0;i<2000;i++) for(j=0;j<900;j++);




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 Primer Board.

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

Testing the Relay with LPC2148

Give +3.3V power supply to LPC2148 Primer Board; the Relay module is connected with LPC2148 Primer Board. When the program is downloading into LPC2148 in Primer Board, the Relay output is working that the Relay is ON some time period and the Relay is OFF some other time of period.

If you are not getting any output from Relay, then you just check the jumper connections & check the Relay is connected properly. Otherwise you just check it with debugging mode in Keil. If you want to see more details about debugging just see the videos in below link.

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 of LPC2148 Primer Board.
       - Tutorial of how to create & Debug a project in Keil.

Join the World's Largest Technical Community

we respect your privacy.