Microcontroller › PIC › 3 INPUT sensor PIC Programming
- This topic has 9 replies, 4 voices, and was last updated 12 years, 7 months ago by amit jha.
-
AuthorPosts
-
April 30, 2012 at 12:15 pm #4773chelahParticipant
Hello everyone, I need some help for my final year project.
My problem is, when 3 sensor detect at the same time, the 3output is not function properly, i think, there is conflict in programming.
here are my program…
MicroC Compiler
c language.
void main(){TRISA=0b01101; // Configure RA0,RA2,and RA3 as input sensor.PORTA=0b00000;TRISB=0b00000000; //Configure ALL PORTB as outputPORTB=0b00000000;while(1) //Loop forever{if(PORTA.F2==1) //Analogue Distance Sensor{PORTB.F3=1; //Buzzer ONdelay_ms(400); //time delay wait for 0.4s}if(PORTA.F3==1) //Water sensor{PORTB.F2=1; //Vibrator ONdelay_ms(400); //time delay wait for 0.4s}// 3 LED WILL RUNNING AND BLINK AT DARK CONDITION.if(PORTA.F0==0) //Dark sensor{PORTB.F4=1; //Blue LED ONPORTB.F5=0; //RED LED OFFPORTB.F6=0; //WHITE LED OFFdelay_ms(200); // time delay wait for 0.2sPORTB.F4=0; //Blue LED OFFPORTB.F5=1; //RED LED ONPORTB.F6=0; //WHITE LED OFFdelay_ms(200);PORTB.F4=0; //Blue LED OFPORTB.F5=0; //RED LED OFFPORTB.F6=1; //WHITE LED ONdelay_ms(200);}else{PORTB.F2=0; //Buzzer OFFPORTB.F3=0; //Vibrator OFFPORTB.F4=0; //Blue LED OFFPORTB.F5=0; //RED LED OFFPORTB.F6=0; //WHITE LED OFF}}}May 3, 2012 at 5:52 pm #7582AJISH ALFREDParticipantCould you please share exactly what kind of abnormality you have in the output?
I’ve tried to modify your code. Please try this also and update the result.
void main()
{
TRISA=0b01101; // Configure RA0,RA2,and RA3 as input sensor.
PORTA=0b00000;
TRISB=0b00000000; //Configure ALL PORTB as output
PORTB=0b00000000;
while(1) //Loop forever
{
if(PORTA.F2==1) //Analogue Distance Sensor
{
PORTB.F3=1; //Buzzer ON
delay_ms(400); //time delay wait for 0.4s
}
else
{
PORTB.F2=0; //Buzzer OFF
delay_ms(50); //time delay wait for 0.05s
}if(PORTA.F3==1) //Water sensor
{
PORTB.F2=1; //Vibrator ON
delay_ms(400); //time delay wait for 0.4s
}
else
{
PORTB.F3=0; //Vibrator OFF
delay_ms(50); //time delay wait for 0.05s
}
if(PORTA.F0==0) //Dark sensor
{
PORTB.F4=1; //Blue LED ON
PORTB.F5=0; //RED LED OFF
PORTB.F6=0; //WHITE LED OFF
delay_ms(200); // time delay wait for 0.2s
PORTB.F4=0; //Blue LED OFF
PORTB.F5=1; //RED LED ON
PORTB.F6=0; //WHITE LED OFF
delay_ms(200);
PORTB.F4=0; //Blue LED OF
PORTB.F5=0; //RED LED OFF
PORTB.F6=1; //WHITE LED ON
delay_ms(200);
}
else
{
PORTB.F4=0; //Blue LED OFF
PORTB.F5=0; //RED LED OFF
PORTB.F6=0; //WHITE LED OFF
delay_ms(50); //time delay wait for 0.05s
}
}
}May 5, 2012 at 4:53 pm #7591chelahParticipantWhen the sensor detect obstacle, the buzzer will ON, and when the LDR detect dark condition, The 3 LED will running, when both of this sensor function at the same time. The Buzzer always ON, and LED running and then stop. the buzzer still ON.
May 5, 2012 at 6:28 pm #7593AJISH ALFREDParticipantThe buffer remains ON because the code for turning the buffer OFF is included in the ‘else’ of dark sense check. So when the dark sensing is TRUE, the statements inside the else won’t get executed.
Have you tried the code modified by me?
May 7, 2012 at 12:11 am #7603chelahParticipantyes, i’ve already try your modified code, but it still won’t function as well.
May 9, 2012 at 1:33 pm #7686AmrithParticipantHello Chelah,
I think i have a solution to your problem. Will post you soon.
Thank you !!!
May 9, 2012 at 1:33 pm #7705AmrithParticipantHello Chelah,
I think i have a solution to your problem. Will post you soon.
Thank you !!!
May 10, 2012 at 5:19 am #7696AmrithParticipantTry This & let me know the result
void main()
{
TRISA=0b01101; // Configure RA0,RA2,and RA3 as input sensor.
PORTA=0b00000;
TRISB=0b00000000; //Configure ALL PORTB as output
PORTB=0b00000000;
while(1) //Loop forever
{
if(PORTA.F2==1) //Analogue Distance Sensor
{
PORTB |= 0b00001000; //Buzzer ON
delay_ms(400); //time delay wait for 0.4s
}
else
{
PORTB &= 0b11110111; //Buzzer OFFdelay_ms(50); //time delay wait for 0.05s
}
if(PORTA.F3==1) //Water sensor
{
PORTB |=0b00000100; //Vibrator ON
delay_ms(400); //time delay wait for 0.4s
}
else
{
PORTB &= 0b11111011; //Vibrator OFF
delay_ms(50); //time delay wait for 0.05s
}
if(PORTA.F0==0) //Dark sensor
{
PORTB |= 0b00010000; //Blue LED ON
PORTB &= 0b11011111; //RED LED OFFPORTB &= 0b10111111; //WHITE LED OFF
delay_ms(200); // time delay wait for 0.2s
PORTB &= 0b11101111; //Blue LED OFF
PORTB |= 0b00100000; //RED LED ON
PORTB &= 0b10111111; //WHITE LED OFF
delay_ms(200);
PORTB &= 0b11101111; //Blue LED OF
PORTB &= 0b11011111; //RED LED OFF
PORTB |= 0b01000000; //WHITE LED ON
delay_ms(200);
}
else
{
PORTB &= 0b00000000;
delay_ms(50); //time delay wait for 0.05s
}
}
}May 10, 2012 at 5:19 am #7715AmrithParticipantTry This & let me know the result
void main()
{
TRISA=0b01101; // Configure RA0,RA2,and RA3 as input sensor.
PORTA=0b00000;
TRISB=0b00000000; //Configure ALL PORTB as output
PORTB=0b00000000;
while(1) //Loop forever
{
if(PORTA.F2==1) //Analogue Distance Sensor
{
PORTB |= 0b00001000; //Buzzer ON
delay_ms(400); //time delay wait for 0.4s
}
else
{
PORTB &= 0b11110111; //Buzzer OFFdelay_ms(50); //time delay wait for 0.05s
}
if(PORTA.F3==1) //Water sensor
{
PORTB |=0b00000100; //Vibrator ON
delay_ms(400); //time delay wait for 0.4s
}
else
{
PORTB &= 0b11111011; //Vibrator OFF
delay_ms(50); //time delay wait for 0.05s
}
if(PORTA.F0==0) //Dark sensor
{
PORTB |= 0b00010000; //Blue LED ON
PORTB &= 0b11011111; //RED LED OFFPORTB &= 0b10111111; //WHITE LED OFF
delay_ms(200); // time delay wait for 0.2s
PORTB &= 0b11101111; //Blue LED OFF
PORTB |= 0b00100000; //RED LED ON
PORTB &= 0b10111111; //WHITE LED OFF
delay_ms(200);
PORTB &= 0b11101111; //Blue LED OF
PORTB &= 0b11011111; //RED LED OFF
PORTB |= 0b01000000; //WHITE LED ON
delay_ms(200);
}
else
{
PORTB &= 0b00000000;
delay_ms(50); //time delay wait for 0.05s
}
}
}May 17, 2012 at 11:08 am #7845amit jhaParticipanthi chelah,
You need some changes in you coding. use connection carefully . your obstacle sensor is connected with RA3, water sensor with RA2, dark sensor with RA0, buzzer with RB2 & vibrator with RB3 as per your circuit diagram. use this connection all where. you have used RB3 for your buzzer while switching on & RB2 for buzzer while switching of. again use code if and else for all the condition. try the and tell me what happen.
amit jha
-
AuthorPosts
- You must be logged in to reply to this topic.