Spread the love

Interfacing of Rain Detector and Zigbee Module in LPC2148.

 

In this project, a controller is fitted on the roof of room or building and information of rain is transmitted inside house or building using zigbee module.

zigbee

ZigBee is an IEEE 802.15.4-based specification for a suite of high-level communication protocols used to create personal area networks with small, low-power digital radios.The technology defined by the ZigBee specification is intended to be simpler and less expensive than other wireless personal area networks (WPANs), such as Bluetooth or Wi-Fi.Its low power consumption limits transmission distances to 10–100 meters line-of-sight, depending on power output and environmental characteristics. ZigBee devices can transmit data over long distances by passing data through a mesh network of intermediate devices to reach more distant ones.

CIRCUIT DIAGRAM :

raindetector

CODE FOR PROJECT :

Transmitter Code –

#include "header.h"
#include "lcd.h"
#include "pll.h"
#include "uart.h"

int main()
{
	PINSEL1=0;
	PINSEL2=0;
	IO0DIR|=0xff<<16 | 0xf<<25;
	IO1DIR&=(~(1<<16)) & (~(1<<17)) & (~(1<<18));
	lcd_init();
	uart_init();
	lcdstring("Rain Detector");
	lcdcmd(0xc0);
	lcdstring("Using Zigbee");
	delay(50);
	lcdcmd(0x01);
	lcdstring("Project By:");
	lcdcmd(0xc0);
	lcdstring("FIRMCODES");
	delay(50);
	lcdcmd(0x01);
	while(1)
	{
		if(!(IO1PIN & (1<<16)))				//Rain Detector Sensor
		{
			txdata('r');
			delay(100);
			IO0SET=1<<25;				//Rain Indicator
		}
		
		if(!(IO1PIN & (1<<17)))				//Rain Detector Sensor
		{
			txdata('g');
			delay(100);
			IO0SET=1<<26;				//Gas Indicator
		}
		
		else
		{
			txdata('n');
			delay(100);
			IO0CLR=1<<25;				// Rain Indicator
		}
	}
}

Receiver –

#include "header.h"
#include "lcd.h"
#include "uart.h"
#include "pll.h"
int main()
{
	PINSEL1=0;
	PINSEL2=0;
	IO0DIR|=0xff<<16 | 0xf<<25;
	IO1DIR|=(~(1<<16));
	lcd_init();
	uart_init();
	lcdstring("Rain Detector");
	lcdcmd(0xc0);
	lcdstring("Using Zigbee");
	delay(50);
	lcdcmd(0x01);
	while(1)
	{
		rxdata();
	}
}

header.h –

#include<lpc214x.h>
#include<string.h>
#define PLOCK 10
#define THRE 5
#define RDR 0
#define lcdport IO0SET
#define lcdportclr IO0CLR
#define rs 16
#define rw 17
#define en 18
#define row1 18
#define row2 19
#define row3 20
#define row4 21
#define col1 22
#define col2 23
#define col3 24
#define col4 25
#define STA 5
#define STO 4
#define SI 3
#define I2EN 6

int i,j,z;

void delay(int);
void cmd(void);
void lcdcmd(char);
void disp(void);
void lcddata(char);
void lcd_init(void);
void lcdstring(char *);

lcd.h –

#include "header.h"
void delay(int time)
{
	int i,j;
	for(i=0;i<time;i++)
	for(j=0;j<7500;j++);
}

void cmnd()
{
		lcdportclr=(1<<rs);
		lcdportclr = (1<<rw);
		lcdport = (1<<en);
		delay(5);
		lcdportclr=(1<<en);
}
void lcdcmd(char ch)
{
	lcdport = ((ch&0xf0)<<15);
	cmnd();
	lcdportclr = ((ch&0xf0)<<15);
	
	lcdport = (((ch<<4)&0xf0)<<15);
	cmnd();
	lcdportclr = (((ch<<4)&0xf0)<<15);
}

void daten()
{
	lcdport=(1<<rs);
	lcdportclr = (1<<rw);
	lcdport = (1<<en);
	delay(5);
	lcdportclr=(1<<en);
}

void lcddata(char ch)
{
	lcdport = ((ch&0xf0)<<15);
	daten();
	lcdportclr = ((ch&0xf0)<<15);
	
	lcdport = (((ch<<4)&0xf0)<<15);
	daten();
	lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcdstring(char *str)
{
	int j;
	for(j=0;str[j]!='\0';j++)
	{
		lcddata(str[j]);
	}
}
void lcd_init()
{
	lcdcmd(0x02);
	lcdcmd(0x28);
	lcdcmd(0x01);
	lcdcmd(0x0e);
}

pll.h –

void clk_init()
{
	PLL0CON=0x01;
	PLL0CFG=0x24;
	PLL0FEED=0xAA;
	PLL0FEED=0x55;
	while(!(PLL0STAT & (1<<PLOCK)));
	PLL0CON=0x03;
	PLL0FEED=0xAA;
	PLL0FEED=0x55;
	VPBDIV=0x00;
}

uart.h –

/* uart.h for reciever */

#include "header.h"
void uart_init()
{
	PINSEL0=0x05;
	U0LCR=0x83;
	U0DLL=0x61;
	U0DLM=0x00;
	U0LCR=0x03;
}
void txdata(char ch)
{
		U0THR=ch;
		while(!(U0LSR & (1<<THRE)));	
}
void txstring(char *str)
{
	while(*str)
	{
		txdata(*str);
		str++;
	}
}

void rxdata()
{
	char str[10],i;
	for(i=0;i<1;i++)
	{
		while(!(U0LSR & (1<<RDR)));
		str[i]=U0RBR;
		U0FCR=0x07;
	}
	str[i]='\0';
	lcdcmd(0x01);
	//lcdstring(str);
	delay(10);
	if(strcmp("r",str)==0)
	{
		lcdstring("Its Raining......");
		IO0SET=1<<25;
		IO0SET=1<<26;
	}
	else if(strcmp("n",str)==0)
	{
		lcdstring("Normal Status");
		IO0CLR=1<<25;
		IO0CLR=1<<26;
	}
	
	else if(strcmp("g",str)==0)
	{
		lcdstring("Gas Leakage");
		IO0SET=1<<27;
		IO0CLR=1<<26;		//buzzer
	}
	
}


	
/*uart.h for transmitter  */

#include "header.h"
void uart_init()
{
	PINSEL0=0x05;
	U0LCR=0x83;
	U0DLL=0x61;
	U0DLM=0x00;
	U0LCR=0x03;
}
void txdata(char ch)
{
		U0THR=ch;
		while(!(U0LSR & (1<<THRE)));	
}
void txstring(char *str)
{
	while(*str)
	{
		txdata(*str);
		str++;
	}
}

void rxdata()
{
	char str[10],i;
	for(i=0;i<1;i++)
	{
		while(!(U0LSR & (1<<RDR)));
		str[i]=U0RBR;
		U0FCR=0x07;
	}
	str[i]='\0';
	lcdcmd(0x01);
	lcdstring(str);
	delay(10);
	if(strcmp("R",str)==0)
	{
		lcdstring("Its Raining......");
	}
}


	

COMING SOON ………………….

video