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-LPC214x






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

Step 3: Download Source Code

Kiel ARM  Code (main.c):


/* blog.circuits4you.com */

#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;

  for(j=0;j<count;j++)
  {
    /* At 60Mhz, the below loop introduces
    delay of 10 us */
    for(i=0;i<35;i++);
  }
}

/******************************************************************
 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};


  lcd_putstring(LINE1,"pH:");

  lcd_putchar(pH[0]);lcd_putchar(pH[1]);  
  lcd_putchar(pH[2]);lcd_putchar(pH[3]);lcd_putchar(pH[4]);

  adc_value = adc_read(ADC0, CHANNEL_3); 
  adc_value=adc_value/3.1;
  sprintf((char *)buf, " T:%02d ", adc_value);
  //lcd_putstring(LINE2, (char *)buf);  
  lcd_putchar(buf[0]);
  lcd_putchar(buf[1]);
  lcd_putchar(buf[2]);
  lcd_putchar(buf[3]);
  lcd_putchar(buf[4]);
  lcd_putchar(0xDF);
  lcd_putchar('C');
 sprintf((char *)buf, "Flow:%d ", Flow); 
 lcd_putstring(LINE2, (char *)buf);
 lcd_putchar('L');lcd_putchar('/');lcd_putchar('H');lcd_putchar('r');

//Send data to PC through uart0
  uart0_putc('(');
  uart0_putc(pH[0]);uart0_putc(pH[1]);  
  uart0_putc(pH[2]);uart0_putc(pH[3]);uart0_putc(pH[4]);
  uart0_putc(',');

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

/*******************************************************
 Function Name : main()
*********************************************************/
int main (void) 
{
  init_adc0();      // Initialize ADC
  init_lcd();      // Initialize LCD
  wait(100000);

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

 wait(100000);
 
 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
  while(1)
  {
    process_adc();     // Raed ADC value and display it on first line of LCD
    wait(50000);
 //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 
{    
 EINT2++;    
 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