This article is a continuation of the series of tutorials on the LPC2148 Microcontroller (ARM7). The aim of this series is to provide easy and practical examples that anyone can understand. In the previous tutorial, we have interfaced the DC motor with LPC2148 (ARM7). In this tutorial, we will learn Relay interfacing with LPC2148. Relay is a very important component to interface the heavy appliances with the help of a microcontroller.
Relay
Relays are devices that 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.
Principle
Current flowing through the coil of the relay creates a magnetic field that attracts a lever and changes the switch contacts. The coil current can be on or off so relays have two switch positions and most have double throw (changeover) switch contacts.
Construction and working
Relays are made up of an electromagnet and a set of contacts generally based on Single Pole Double Throw (SPDT) or Double Pole Double Throw (DPDT) switching method. It has 3 pins to perform a function –
- COM = Common, always connect to NC; it is the moving part of the switch.
- NC = Normally Closed, COM is connected to this when the relay coil is off.
- NO = Normally Open, COM is connected to this when the relay coil is on.
You can easily understand the concept of Relay by looking the below image.
Suggestion to read
Before getting into Interfacing, You should know about the Relay Driver (ULN2803) and its need and working.
Relay Interfacing with LPC2148
Circuit Diagram
In this tutorial, I’m connecting One Relay in Port 0.0.
Code
If you want to make Relay ON, Just give the High Signal (1) to that pin that is connected to ULN2803. The concept of this code is just to turn On the Relay for Some time and Turn Off the relay for some time.
#include<lpc214x.h> #define bit(x) (1<<x) #define delay for(i=0;i<60000;i++) unsigned int i; int main() { IO0DIR=0xff; IO0PIN=0; while(1) { IO0SET=bit(0); //Relay ON delay; IO0CLR=bit(0); //Relay OFF delay; } }
Output
[ Please find the output image Here ]
That’s all guys… So Programming wise it’s very simple. It is like a LED program. But Hardware wise we should be careful. Because we might connect AC power supply devices here. So Be careful guys. You may connect Fan, AC Motor, Lamp, etc to relay.
In our next tutorial, we will see how to interface the keypad with LPC2148 (ARM7). If you want to use FreeRTOS on LPC2148, then please refer FreeRTOS series.
You can also read the below tutorials.

Embedded Software | Firmware | Linux Devic Deriver | RTOS
Hi, I’m SLR. I am a tech blogger and an Embedded Engineer. I am always eager to learn and explore tech-related concepts. And also, I wanted to share my knowledge with everyone in a more straightforward way with easy practical examples. I strongly believe that learning by doing is more powerful than just learning by reading. I love to do experiments. If you want to help or support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning!