How to Interface Sensor with LPC2148 ARM

Temp Sensor Interfacing With ARM7 Slicker

Overall rating
ARM7 LPC2148 Slicker Board

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

Temperature Sensor

DS1820 is a temperature sensor which is small sensor. The output of sensor converted to digital that easy connecting with microcontroller.

Interfacing ds1820

Fig. 1 shows how to interface the ds1820 to microcontroller. As you can see the first pin is connected to GND, the third pin is connected to VCC & the second pin is connected to the Microcontroller. So when the temperature is sensing, it give the sensor reading to controller.


Fig. 1 Interfacing ds1820 to Microcontroller

Interfacing ds1820 with LPC2148

We now want to read the temperature in LPC2148 Slicker Board from temperature sensor ds1820. The ARM7 LPC2148 Slicker board uses the ADC pin for reading temperature from temperature sensor ds1820. The reading output is displayed into PC through UART1.

The 10 bit ADC used to read temperature. Basic clocking for the A/D converters is provided by the VPB clock. A programmable divider is included in each converter, to scale this clock to the 4.5 MHz (max) clock needed by the successive approximation process. A fully accurate conversion requires 11 of these clocks.

Pin Assignment with LPC2148



Temp Sensor

LPC2148 Lines

Temperature Sensor






Circuit Diagram to Interface ds1820 with LPC2148


Source Code

The Interfacing ds1820 with LPC2148 program is very simple and straight forward, that reading temperature from temperature sensor ds1820 and it display into PC through serial port. The C programs are written in Keil software.

C Program to read temperature using LPC2148


Title : Program to read temperature



#include <LPC214X.H>

#include "OneWire.h"

#include "LCD8.h"

#include "Utility.h"



const unsigned char LCD_Message[16] = {"ARM Digital Temp"};

unsigned char DSMAG;

char DSSIGN;

unsigned char TEMPnum[16];

int Temperature;

unsigned char Xpos, temp1;

int main (void)


   PINSEL0 = 0;

   PINSEL1 = 0;

   PINSEL2 &= 0x0000000C;


   LCD8_init (&IOPIN0, &IOPIN0, 12, 13, 14, 16);

   ow_init (&IOPIN0, 29/*DQ*/); //DS18s20 Sensor output

   LCD8_sendstr (0,0, LCD_Message);


   while (1)


      Xpos = 0;

      if (DS1820_read (&DSMAG, &DSSIGN) == 0x00)



         Temperature = DSMAG / 2;

         if (DSSIGN == 0xFF)

            Temperature = -Temperature;


         Xpos += int2str (TEMPnum, Temperature);

         TEMPnum[Xpos++] = '.';

         if ((DSMAG % 2) == 0)

            TEMPnum[Xpos++] = '0';


            TEMPnum[Xpos++] = '5';

         TEMPnum[Xpos++] = 0xDF;

         TEMPnum[Xpos++] = 'C';

         TEMPnum[Xpos] = 0;


         LCD8_sendstr (0,1, TEMPnum);




         LCD8_sendstr (0,1, "Error   ");



      // Delay 1s

      delay_Nx10cyc (5999999);



/* Read temperature from DS1820 */

unsigned char DS1820_read (unsigned char *DSM, char *DSS)


   // Get current temperature reading

   if (ow_reset() == 0x01)


      return (0x01); // Return ERROR, part not present


   ow_write (0xCC);  // DS1820 ROM Command, SKIP PROM

   ow_write (0xBE);  // READ SCRATCH PAD


   *DSM = ow_read(); // Get MAGNITUDE

   *DSS = ow_read(); // Get SIGN (FF = -ve, 00 = +ve)


   // Start NEW Conversion

   if (ow_reset() == 0x01)


      return (0x01);  // Return ERROR, part not present


   ow_write (0xCC);   // DS1820 ROM Command, SKIP PROM

   ow_write (0x44);   // START CONVERSION


   // If DSSIGN not 0 or 255 then return ERROR

   if ((*DSS != 0x00) && (*DSS != 0xFF))

      return (0x01);

   return (0x00);





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

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

Testing the ds1820 with LPC2148

Give +3.3V power supply to LPC2148 Slicker Board; the serial cable is connected between the controller and PC. Open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show the current temperature readings.

Bring a Hot soldering iron tip near the ds1820's pins, don't touch it keep it 1 or 2mm away. The screen should update with the rising temperature. Now finally touch the pins of ds1820 with the tip of iron, the temperature should rise quickly. Keep it there until temperature rise to 80 degrees, and then remove the iron.

  • If you not reading any text from UART0, then you just check the jumper connections & just check the serial cable is working. Otherwise you just check the code with debugging mode in KEIL.

General Information

Join the World's Largest Technical Community

we respect your privacy.