how to add the code for sensor?

Thread Starter

indio_19gen

Joined Dec 26, 2012
1
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.
Rich (BB code):
#include<16F877A.h>
#fuses HS, NOPUT, NOLVP
#use delay(clock=20Hz)


void main()
{
	while(true)
	{
		//-------------------------------for motor operation
		if(!input(PIN_D0))//---------microswitch 
		{
			//-------------------------------switch for reversing 
			output_high(PIN_B2);//----clockwise mode

			if(!input(PIN_D1))
			{
				output_high(PIN_B0);
				output_low(PIN_B1);

			}
			else if(!input(PIN_D2))//-----counter clockwise mode
			{
				output_high(PIN_B1);
				output_low(PIN_B0);

			}
		}
		else if(input(PIN_D0))
		{
			output_low(PIN_B2);
		}
	}
}

	
	
		
		
	


	
 
Last edited:
Top