Netra Agadi
Newbie level 4
- Joined
- Dec 18, 2013
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 53
hi guys..
Im doing the project which automatically turn on and off the water pump depending on the moisture content in soil. Im using Microcontroller 8051, programming done in c.
I have designed a circuit for soil moisture detection which I have attached below. the sensor output is given to adc. the sensor works such a way that voltage across sensor is proportional to moisture content in soil. The problem im facing is adc output value is increasing with decrease in voltage at sensor.
help me with this asap plz...
I have attached my code(it just display the adc o/p) too...check it.
Im doing the project which automatically turn on and off the water pump depending on the moisture content in soil. Im using Microcontroller 8051, programming done in c.
I have designed a circuit for soil moisture detection which I have attached below. the sensor output is given to adc. the sensor works such a way that voltage across sensor is proportional to moisture content in soil. The problem im facing is adc output value is increasing with decrease in voltage at sensor.
help me with this asap plz...
I have attached my code(it just display the adc o/p) too...check it.
Code:
#include<reg51.h>
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
sbit cs=P2^4;
sbit rd=P2^5;
sbit wr=P2^6;
sbit intr=P2^7;
void delay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcddata(unsigned char val)
{
rs=1;
rw=0;
P0=val;
en=1;
delay(5);
en=0;
}
void lcdcmd(unsigned char val)
{
rs=0;
rw=0;
P0=val;
en=1;
delay(5);
en=0;
}
void lcd_init()
{
lcdcmd(0x38);
lcdcmd(0x0e);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x80);
}
unsigned char adc()
{
unsigned char adc;
cs=0;
//intr=1;
wr=0;
wr=1;
while(intr==1);
rd=0;
adc=P1;
rd=1;
return adc;
}
void main()
{
unsigned char a;
lcd_init();
P0=0x00;
P1=0xff;
cs=0;
rd=1;
wr=1;
intr=1;
while(1)
{
lcdcmd(0x83);
a=adc();
lcddata((a/100)+48);
lcddata(((a/10)%10)+48);
lcddata((a%10)+48);
delay(30);
}
}
Attachments
Last edited by a moderator: