EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / 3 INPUT sensor PIC Programming

3 INPUT sensor PIC Programming

|

Microcontroller › PIC › 3 INPUT sensor PIC Programming

  • This topic has 9 replies, 4 voices, and was last updated 13 years, 1 month ago by amit jha.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • April 30, 2012 at 12:15 pm #4773
    chelah
    Participant

    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 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
    }
     
    if(PORTA.F3==1)            //Water sensor
    {
    PORTB.F2=1;                //Vibrator ON
    delay_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 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.F2=0;                //Buzzer OFF
     PORTB.F3=0;                //Vibrator OFF
     PORTB.F4=0;                //Blue LED OFF
     PORTB.F5=0;                //RED LED OFF
     PORTB.F6=0;                //WHITE LED OFF
    }
    }
    }

     

     

    circuit

    May 3, 2012 at 5:52 pm #7582
    AJISH ALFRED
    Participant

    Could 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 #7591
    chelah
    Participant

    When 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 #7593
    AJISH ALFRED
    Participant

    The 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 #7603
    chelah
    Participant

    yes, i’ve already try your modified code, but it still won’t function as well.

     

    May 9, 2012 at 1:33 pm #7686
    Amrith
    Participant

    Hello Chelah,

     

    I think i have a solution to your problem. Will post you soon.

     

    Thank you !!!

    May 9, 2012 at 1:33 pm #7705
    Amrith
    Participant

    Hello Chelah,

     

    I think i have a solution to your problem. Will post you soon.

     

    Thank you !!!

    May 10, 2012 at 5:19 am #7696
    Amrith
    Participant

    Try 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 OFF

                 delay_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 OFF

                PORTB &= 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 #7715
    Amrith
    Participant

    Try 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 OFF

                 delay_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 OFF

                PORTB &= 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 #7845
    amit jha
    Participant

    hi 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

     

  • Author
    Posts
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Curved lines in PCB design June 18, 2025
  • What is correct names for GOOD user friendly circuit drawing program? June 18, 2025
  • using a RTC in SF basic June 18, 2025
  • Is AI making embedded software developers more productive? June 18, 2025
  • Why can't I breadboard this oscillator? June 18, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise