Embedded VJ
Published © MIT

Greenhouse Monitoring using PIC MICROCONTROLLER

How to make a greenhouse monitoring using pic microcontroller

IntermediateFull instructions provided191
Greenhouse Monitoring using PIC MICROCONTROLLER

Things used in this project

Hardware components

PIC16F
Microchip Technology PIC16F
×1
PICkit 3 In-circuit Debugger
Digilent PICkit 3 In-circuit Debugger
×1
Gravity: Analog LM35 Temperature Sensor For Arduino
DFRobot Gravity: Analog LM35 Temperature Sensor For Arduino
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Gravity: Analog Soil Moisture Sensor For Arduino
DFRobot Gravity: Analog Soil Moisture Sensor For Arduino
×1
LED (generic)
LED (generic)
×1
Axial Fan, 12 VDC
Axial Fan, 12 VDC
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

MPLAB Code Configurator
Microchip Technology MPLAB Code Configurator

Hand tools and fabrication machines

Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)

Story

Read more

Schematics

Schematics and circuit diagrams

PROTEUS SIMULASION IMAGE

Code

PIC16F877A PROGRAM FOR MPLAB IDE

C/C++
#include<pic.h>
#include<htc.h>
#include<stdio.h>
#define fan1 RD2
#define fan2 RD3
#define lamp RD4
int v1=0,v2=0,v3=0;
#define waterpump1 RD0
#define waterpump2 RD1
#define _XATL_FREQ 20000000
__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_OFF & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_OFF & DEBUG_OFF);
void delay (unsigned int s)
{
while(s--);
}
int multichannel(unsigned char);
int multichannel1(unsigned char);
int multichannel2(unsigned char);
void cmd (unsigned char d)
{
PORTB=d;
PORTC=0X04;
delay(10);
PORTC=0X00;
}
void dat(unsigned char d)
{
PORTB=d;
PORTC=0X05;
delay(10);
PORTC=0X01;
}
void lcd_init()
{
cmd(0X38);
delay(100);
cmd(0X01);
delay(100);
cmd(0X0e);
delay(100);
cmd(0X0C);
delay(100);
}
void main()
{
unsigned int t,p;
unsigned char zz[30],i;
int x,y,z,ldr,soil;
float v,temp;
TRISB=0X00;
TRISD=0X00;
TRISC=0X00;
lcd_init();
       while(1)
       {
        x=multichannel(0X00);
        y=multichannel1(0x01);
        z=multichannel2(0x02);
        delay(100);
        v=(x*4.88281);
        temp=v/10.00;
        ldr=y;
        soil=z;
        delay(100);
if(v1==1)
{
sprintf(zz,"TMP=%.1f"" FAN=OFF",temp);
}
if(v1==2)
{
sprintf(zz,"TMP=%.1f"" FAN=ON ",temp);
}
        i=0;
        cmd(0X80);

        if(temp>40)
        {
v1=2;
        fan1=0xff;
        fan2=0x00; 
        } 
        if(temp<40) 
        {
v1=1;
        fan1=fan2=0x00; 
        }

        if(ldr>150) {
v2=2;
        lamp = 0xff;
        } 
        else 
        {
v2=1;
        lamp = 0x00;
        }

        if(soil<100) {
v3=2;
        waterpump1=0xff;
        waterpump2=0x00; 
        } 
        if(soil>100) 
        {
v3=1;
        waterpump1=waterpump2=0x00; 
        }
  while(zz[i]!='\0')
  {
  dat(zz[i]);
  i++;
  }
if(v2==2)
{
        sprintf(zz,"LED=ON ");
}
if(v2==1)
{
        sprintf(zz,"LED=OFF");
}
        i=0;
        cmd(0xC0);  

  while(zz[i]!='\0')
  {
  dat(zz[i]);
  i++;
  }
if(v3==2)
{
        sprintf(zz,"MTR=ON ");
}
if(v3==1)
{
        sprintf(zz,"MTR=OFF");
}
        i=0;
        cmd(0xC8); 
 
  while(zz[i]!='\0')
  {
  dat(zz[i]);
  i++;
  }
  }
  }

int multichannel(unsigned char a)
{
int x;
ADIE=0;
ADCON0=(0XC1|a); 
ADCON1=0Xc9;
delay(100);
GO=1;
while(GO==1);
ADIF=0;
x=((ADRESH*256)+ADRESL);
return x;
}

int multichannel1(unsigned char a)
{
int x;
ADIE=0;
ADCON0=(0XC9|a);
ADCON1=0Xc9;
delay(100);
GO=1;
while(GO==1);
ADIF=0;
x=((ADRESH*256)+ADRESL);
return x;
}

int multichannel2(unsigned char a)
{
int x;
ADIE=0;
ADCON0=(0XD1|a);
ADCON1=0Xc9;
delay(100);
GO=1;
while(GO==1);
ADIF=0;
x=((ADRESH*256)+ADRESL);
return x;
}

Credits

Embedded VJ

Embedded VJ

1 project • 4 followers
Iam creating industrial projects. Iam learning embedded system.

Comments

Add projectSign up / Login