marov
Newbie level 6
Hi guys,
I am working on a simple smart house project using pic16f877a.I used two ultrasonic sensors one on the outer and other inner. If outer give signal first so somebody enters and if the inner give signal first then somebody left. Also I am using a thermistor for calculating temperature. I wrote the code. It should be working, i simulated it using real Pic simulator and it worked, however using"Proteus" i had some errors. When I programmed the code on the pic i didn't get any response.
Here is the complete code:
unsigned int en,ex,t,k;
int i=0;
void main() {
ADCON1=0;
TRISA=0xFF;
TRISD=0;
PORTD=0;
TRISB=0;
PORTB=0;
ADC_Init();
while (1){
en=ADC_Read(0); //reading from external ultrasonic sensor
ex=ADC_Read(1);// reaing from internal ultrasonic sensor
t=ADC_Read(2);// reading form thermistor
k=ADC_Read(3);// pressure sensor
if( en> 300 && ex<50 ){// if the external sensor give signal, lamp is on, and counter for one person in incremented
PORTB.F2=1;
i=i+1;
Delay_ms(3000);}
if( ex> 300 && en<50 ) {/ if the internal sensor give signal, counter for one person in deccremented
if(i>0){
i=i-1;}
Delay_ms(3000);}
if(i==0){
PORTB.F2=0;}
if(i>=1 & k>128){ // if somebody is in the room, and pressure sensor is above a referance value
if (t>128){ // if t above reference value, switch on a cooler
PORTB.F4=0;
delay_ms(2000);
PORTB.F3=1;}
if( t>110 & t<128){
PORTB.F4=0;
PORTB.F3=0; }
if (t<110 ){ // if temp below reference temp turn on heater
PORTB.F3=0;delay_ms(2000);
PORTB.F4=1;} }
}}
I dont know if there is a problem in ADC
Guys i really appreciate your help
I am working on a simple smart house project using pic16f877a.I used two ultrasonic sensors one on the outer and other inner. If outer give signal first so somebody enters and if the inner give signal first then somebody left. Also I am using a thermistor for calculating temperature. I wrote the code. It should be working, i simulated it using real Pic simulator and it worked, however using"Proteus" i had some errors. When I programmed the code on the pic i didn't get any response.
Here is the complete code:
unsigned int en,ex,t,k;
int i=0;
void main() {
ADCON1=0;
TRISA=0xFF;
TRISD=0;
PORTD=0;
TRISB=0;
PORTB=0;
ADC_Init();
while (1){
en=ADC_Read(0); //reading from external ultrasonic sensor
ex=ADC_Read(1);// reaing from internal ultrasonic sensor
t=ADC_Read(2);// reading form thermistor
k=ADC_Read(3);// pressure sensor
if( en> 300 && ex<50 ){// if the external sensor give signal, lamp is on, and counter for one person in incremented
PORTB.F2=1;
i=i+1;
Delay_ms(3000);}
if( ex> 300 && en<50 ) {/ if the internal sensor give signal, counter for one person in deccremented
if(i>0){
i=i-1;}
Delay_ms(3000);}
if(i==0){
PORTB.F2=0;}
if(i>=1 & k>128){ // if somebody is in the room, and pressure sensor is above a referance value
if (t>128){ // if t above reference value, switch on a cooler
PORTB.F4=0;
delay_ms(2000);
PORTB.F3=1;}
if( t>110 & t<128){
PORTB.F4=0;
PORTB.F3=0; }
if (t<110 ){ // if temp below reference temp turn on heater
PORTB.F3=0;delay_ms(2000);
PORTB.F4=1;} }
}}
I dont know if there is a problem in ADC
Guys i really appreciate your help