Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pir sensor with microcontroller

Status
Not open for further replies.

aadebola5

Newbie level 4
Newbie level 4
Joined
Aug 12, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
87
please can anyone assist me by going through this code, the LED is to come on when the switch is on and the pir sensor detects motion.. this is the code


//all these # below set up the PIC
//#include <16F877A.h>
//#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Highspeed Osc > 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=20000000) // Sets crystal oscillator at 20 megahertz
#use rs232(baud=9600, xmit=PIN_C6, invert) //Sets up serial port output pin & baud rate
#define PIR_SENSOR PIN_A0
#define RED_LED PIN_B7
#define sw PIN_A1



void main()
{
set_tris_a(0xff);
set_tris_b(0x00);


setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

while(true)
{ set_adc_channel(0);
delay_us(20);


if(PIR_SENSOR==0 && sw==0){
output_high(PIN_B7);
}
else{
output_low(PIN_B7);
}


}
}
 

Hi there,


What kind of assistance do you want??

I can explain above code ...

Code:
//all these # below set up the PIC
//#include <16F877A.h>
//#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Highspeed Osc > 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection

These are configuration setup for MCU

Code:
#use delay(clock=20000000) // Sets crystal oscillator at 20 megahertz
#use rs232(baud=9600, xmit=PIN_C6, invert) //Sets up serial port output pin & baud rate
Here you are defining the Clock for the delay, speed or baud rate for uart and other peripherals setups

Code:
#define PIR_SENSOR PIN_A0
#define RED_LED PIN_B7
#define sw PIN_A1

Here you are assigning GPIO pins for sensor , led and switch
like,
PORT A pin 0->> sensor input(input).
PORT B pin 7 ->> led indication(output).
PORT A pin 1->>switch(input) .

Code:
void main()
{
set_tris_a(0xff); //TRIS function for GPIO settings, if its zero means gpio assigned for output.1-> input.here portA pins are assigning as a input
set_tris_b(0x00); //TRIS function for GPIO settings, if its zero means gpio assigned for output.1-> input.here portB pins are assigning as a output


setup_adc_ports(AN0);// selecting ADC channel channel0 
setup_adc(ADC_CLOCK_INTERNAL);// selecting adc using internal clock 
setup_psp(PSP_DISABLED); // alternte function on same pins is disabling
setup_spi(FALSE);//spi disabled
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);// Timer0 clock setup and timer 0 enabled
setup_timer_1(T1_DISABLED);//timer 1 disabled
setup_timer_2(T2_DISABLED,0,1);//timer2 diabled
setup_comparator(NC_NC_NC_NC);// comparator module disabled
setup_vref(FALSE);// setting internal Vref for ADC

while(true)// infinte loop
{ 
set_adc_channel(0);// scanning adc channel0 or reading adc channel 0
delay_us(20);// delay routine


if(PIR_SENSOR==0 && sw==0)// checking switch is off and sensor data is null
{
output_high(PIN_B7);// led on or High
}
else
{     //else any data from sensor or switch is on
output_low(PIN_B7); // led is off or low
}//end main


update me.

Best regards,
 
please can anyone assist me by going through this code, the LED is to come on when the switch is on and the pir sensor detects motion.. this is the code


//all these # below set up the PIC
//#include <16F877A.h>
//#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Highspeed Osc > 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=20000000) // Sets crystal oscillator at 20 megahertz
#use rs232(baud=9600, xmit=PIN_C6, invert) //Sets up serial port output pin & baud rate
#define PIR_SENSOR PIN_A0
#define RED_LED PIN_B7
#define sw PIN_A1



void main()
{
set_tris_a(0xff);
set_tris_b(0x00);


setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

while(true)
{ set_adc_channel(0);
delay_us(20);


if(PIR_SENSOR==0 && sw==0){
output_high(PIN_B7);
}
else{
output_low(PIN_B7);
}


}
}

What's the exact need of you? Is there any roblems you r facing?
 

wanted to be sure if it is ok, before i start the hardware implementation..

- - - Updated - - -

the problem now after trying this is that the LED came on when the switch(sw) was switched on when motion was detected and that ws all, it wont detect again..please can anyone help me mdify then code .to make the LED come on when motion is detected and off when motion is not detected.. thanks
 

Hi again,

wanted to be sure if it is ok, before i start the hardware implementation..

Yes it will work ..

the problem now after trying this is that the LED came on when the switch(sw) was switched on when motion was detected and that ws all, it wont detect again..please can anyone help me mdify then code .to make the LED come on when motion is detected and off when motion is not detected.. thanks
..

I didn't get your words... what do you want to do?

Code:
if(PIR_SENSOR==0 && sw==0){
output_high(PIN_B7);
}
else{
output_low(PIN_B7);
}

here led become high whether sensor input and switch input also zero.what modification do you need?

update me,

Best regards.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top