Saturday, June 13, 2015

LPC2148 based water quality monitoring system

This project is based on LPC2148 ARM 7 Microcontroller, It measures pH, Flow, and temperature of water. It logs data on computer and shows real time readings on 16x2 LCD, It uses BlueBoard-LPC2148

BlueBoard is a cost effective prototyping and solutions using the versatile LPC214x series of microcontrollers. It is a ready-to-run development platform with code snippets to demonstrate applications for every feature supported on the board. The BlueBoard offers ubiquitous interfaces making it the best board available for the offered price.
The LPC2148 microcontroller has 512KB of internal flash and 32+8K RAM, can be clocked up to 60Mhz. LPC2148 features include USB 2.0 device, 2xUARTs, RTC, 2x10bit ADCs each ADC has multiple channels, 1xDAC, 6XPWM, 2xI2C, 1xSPI, 1XSSP, 2x32-bit TIMERS, FAST I/0 support and WDT. LPC2148 also supports In System Programming (ISP)VB6 Software for Data logging

Step 1: Circuit Diagram and Connections
1. Flow sensor connections goes to EINT1 (Pin 45 of LPC2148).
2. Temperature Sensor to ADC Channel (AD0.3 Pin 15 of LPC2148).
3. pH sensor RX, TX lines are connected to USART1 (TTL Rx Tx).
4. UART0 is used for sending data to PC for data logging.

Step 2: Download Required Files
In this project we are directly connecting these sensor to blueboard so no need of separate PCB or Circuit Diagram
1. Circuit Diagram of Blueboard
2. pH Sensor Protocol and Details

Step 3: Download Source Code
1. Download VB6 Software for DataLogging
2. Download LPC2148 Project Code File

Kiel ARM  Code (main.c):

/* */

#include <stdio.h>
#include <LPC214x.H>                       /* LPC214x definitions */
#include "lcd.h"
#include "adc.h"
#include "uart.h"
#include "irq.h"

extern char pH[5];
int volatile EINT2   =   0;
void ExtInt_Serve2(void)__irq;
void ExtInt_Init2(void);
int Flow;

  Function Name : wait()
  Description :This function suspends the tasks for specified ticks. 
  Input :  ticks:no of ticks in multiple of 1 usec
            task: task to be suspended

void wait(int count)
  int j=0,i=0;

    /* At 60Mhz, the below loop introduces
    delay of 10 us */

 Function Name : process_adc()
 Description :
Reads ADC data LM35, then displays it on LCD
void process_adc(void)
 unsigned short adc_value = 0;
   unsigned char buf[16] = {0};



  adc_value = adc_read(ADC0, CHANNEL_3); 
  sprintf((char *)buf, " T:%02d ", adc_value);
  //lcd_putstring(LINE2, (char *)buf);  
 sprintf((char *)buf, "Flow:%d ", Flow); 
 lcd_putstring(LINE2, (char *)buf);

//Send data to PC through uart0

  sprintf((char *)buf, "%04d", Flow);  
  uart0_puts((char *)buf);
  sprintf((char *)buf, "%02d",adc_value);
  uart0_puts((char *)buf);

 Function Name : main()
int main (void) 
  init_adc0();      // Initialize ADC
  init_lcd();      // Initialize LCD

 init_VIC();      //Interrupt enable
 ExtInt_Init2();     //Enable Flow Sensor Intterupt 
    UARTInit1(38400);    //UART1 init
 UARTInit(38400);    //UART0 init

 uart1_puts("C");    //pH Sensor Command "C+CR" to continuously send pH data 
 uart1_putc(13);     //at baud rate of 38400

  lcd_clear();      // clear display
    process_adc();     // Raed ADC value and display it on first line of LCD
 //Measure Flow
 EINT2 = 0;                      //Set NbTops to 0 ready for calculations
  VICIntEnable |= 1<<16;           //Enables interrupts
  wait(100000);                    //Wait 1 second
  VICIntEnable &= ~(1<<16);           //Disable interrupts
  Flow = ((EINT2 * 60) / 7.5);       //(Pulse frequency x 60) / 7.5Q = flow rate in L/hour 

void ExtInt_Serve2(void)__irq 
 EXTINT |= 4;    
 VICVectAddr = 0; 

void ExtInt_Init2(void) 
 EXTMODE |= 4;         //Edge sensitive mode on EINT2    
 EXTPOLAR = 0;           //Falling Edge Sensitive    
 PINSEL0 |= 0x80000000; //Enable EINT2 on P0.15    
 VICVectCntl1 = 0x20 | 16; // 16 is index of EINT2    
 VICVectAddr1 = (unsigned int) ExtInt_Serve2;    
// VICIntEnable |= 1<<16;   //Enable EINT2   

Step 4: Testing and Debuging
1. Give power supply to respective sensors from BlueBoard, LPC2148 is +5V Compatible.
2. Flow Sensor is common hall effect type sensor, gives pulses as output
3. Temperature Sensor is LM35
4. Follow us on Google+, Facebook
5. Comment if you find any difficulty.

No comments:

Post a Comment