how to add the code for sensor?

Discussion in 'The Projects Forum' started by indio_19gen, Dec 26, 2012.

  1. indio_19gen

    Thread Starter New Member

    Dec 26, 2012
    1
    0
    Can anyone help me to solve this problems. I have already the code in c language and I would like to use sensor but i don't know how to code it. When sensor is activated means is ON the motor will stop then if sensor is OFF the motor is activated. I am using switch as i mentioned in my proteus simulation placed in PIN_d3, because my ir proximity sensor kit has three wires, input, output, and for ground. Can you please interface the code for the sensor as switch only just to stop the motor when its detected object and if there's no object the motor is still actives. THANKS in advance.
    Code ( (Unknown Language)):
    1. #include<16F877A.h>
    2. #fuses HS, NOPUT, NOLVP
    3. #use delay(clock=20Hz)
    4.  
    5.  
    6. void main()
    7. {
    8.     while(true)
    9.     {
    10.         //-------------------------------for motor operation
    11.         if(!input(PIN_D0))//---------microswitch
    12.         {
    13.             //-------------------------------switch for reversing
    14.             output_high(PIN_B2);//----clockwise mode
    15.  
    16.             if(!input(PIN_D1))
    17.             {
    18.                 output_high(PIN_B0);
    19.                 output_low(PIN_B1);
    20.  
    21.             }
    22.             else if(!input(PIN_D2))//-----counter clockwise mode
    23.             {
    24.                 output_high(PIN_B1);
    25.                 output_low(PIN_B0);
    26.  
    27.             }
    28.         }
    29.         else if(input(PIN_D0))
    30.         {
    31.             output_low(PIN_B2);
    32.         }
    33.     }
    34. }[IMG]http://obrazki.elektroda.pl/6434967200_1356351832.jpg[/IMG]
     
    Last edited: Dec 26, 2012
Loading...