Interfacing Relay With LPC2148 ARM: Arm How-To Guide

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

ARM HOW-TO GUIDE

Interfacing Relay with


LPC2148 ARM
Contents at a Glance
ARM7 LPC2148 Primer Board ...........................................3
Relay ...............................................................................3
Interfacing Relays ............................................................4
Interfacing Relay with LPC2148 ........................................5
Pin Assignment with LPC2148 ..........................................5
Circuit Diagram to Interface Relay with LPC2148 ..............6
Source Code ....................................................................6
C Program to control Relay in LPC2148 .............................7
Testing the LED with LPC2148 ..........................................8
General Information ........................................................9

Join the Technical Community Today!


http://www.pantechsolutions.net
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.

Relay

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.

Join the Technical Community Today!


http://www.pantechsolutions.net
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 Buzzer to Microcontroller

Join the Technical Community Today!


http://www.pantechsolutions.net
Interfacing Relay with LPC2148

We now want to 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


RELAY SPDT LPC2148 Lines RELAY Power Select

+5V
SW28
Relay-1 P1.20
RELAY Modules

OFF 1 8 ON 7SEG
2 7 LCD
3 6 SM/RL
4 5 GLCD
PWR ON/OFF

Relay-2 P1.21 JP8


1 2- 3 Internal +5V (Stepper Motor)

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

Join the Technical Community Today!


http://www.pantechsolutions.net
Circuit Diagram to Interface Relay with LPC2148
3.3V
63
51
43
23
7

U16
VDD1
VDD2
VDD3
VDDA
VREF

U4
6 16 1 18 STM_A
18 VSS1 P1.16 12 2 I1 O1 17 STM_B
25 VSS2 P1.17 8 3 I2 O2 16 STM_C
42 VSS3 P1.18 4 4 I3 O3 15 STM_D
50 VSS4 P1.19 48 5 I4 O4 14 RL1
59 VSS5 P1.20 44 6 I5 O5 13 RL2
VSSA P1.21 7 I6 O6 12
LPC2148 8 I7 O7 11
9 I8 O8 10 ULN_PWR
GND COMM
ULN2803A

ULN_PWR 2 7 LS3
XTAL2

XTAL1

ULN_PWR 2 7 LS2 RL2 1 6

1
RL1 1 6 4 R2_NC
1

4 D5 3
R1_NC R2_C
D4 3 5
R1_C R2_NO
61

62

5 R1_NO 8
12MHz LED
8 RELAY SPDT
JP9 LED RELAY SPDT

2
3 R1_NO
2

C32 3 2 R1_C JP10


X11 C33
2 1 R1_NC JP11 3 R2_NO
1 R26 3
22pf 22pf 3 R1_NO 2 R2_C
R25 3 330E 2
2 R1_C 1 R2_NC
RELAY O/P1 330E 2 1 R1_NC 1
1

RL2
RELAY O/P2
RL1

RELAY O/P1

RELAY SPDT

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.

Join the Technical Community Today!


http://www.pantechsolutions.net
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;


Delay();
IOCLR1 = 1 << RLY1;
Delay();
IOSET1 = 1 << RLY2;
Delay();
IOCLR1 = 1 << RLY2;
Delay();
}

void Delay()
{
unsigned int i,j;
for(i=0;i<2000;i++) for(j=0;j<900;j++);
}

Join the Technical Community Today!


http://www.pantechsolutions.net
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 LED 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

Join the Technical Community Today!


http://www.pantechsolutions.net
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.

 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,

Join the Technical Community Today!


http://www.pantechsolutions.net
 User Manual of LPC2148 Primer Board.
 Tutorial of how to create & Debug a project in Keil.

Join the Technical Community Today!


http://www.pantechsolutions.net
Did you enjoy the read?
Pantech solutions creates information packed technical
documents like this one every month. And our website is a rich
and trusted resource used by a vibrant online community of
more than 1,00,000 members from organization of all shapes
and sizes.

Join the Technical Community Today!


http://www.pantechsolutions.net
What do we sell?
Our products range from Various Microcontroller
development boards, DSP Boards, FPGA/CPLD boards,
Communication Kits, Power electronics, Basic electronics,
Robotics, Sensors, Electronic components and much more . Our
goal is to make finding the parts and information you need
easier and affordable so you can create awesome projects and
training from Basic to Cutting edge technology.

Join the Technical Community Today!


http://www.pantechsolutions.net

You might also like