View previous topic :: View next topic |
Author |
Message |
indio_19gen
Joined: 05 Jan 2013 Posts: 2
|
How to interface IR proximity sensor as switch? |
Posted: Sat Jan 05, 2013 7:45 am |
|
|
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 the sensor is OFF, the motor is activated. I am using a 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 an object and if there's no object the motor is still active. I used PCW as compiler. THANKS in advance.
Here's the simulation:
http://obrazki.elektroda.pl/6434967200_1356351832.jpg
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);
}
}
} |
|
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sun Jan 06, 2013 9:40 am |
|
|
What kind of IR sensor are you using? If it has a simple 0 or 1 output then it should substitute for a microswitch with no code changes except maybe an inversion.
If the sensor has some sort of pulse width or pulse timing output then things get more complicated. The sensor datasheet will tell you what the output format is. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Jan 06, 2013 10:21 am |
|
|
...or it could be an analog IR sensor,typically used in 'PIR motion detectors'.
...so more info about the sensor is required !
mfr/make/model/etc.. |
|
|
indio_19gen
Joined: 05 Jan 2013 Posts: 2
|
|
Posted: Mon Jan 07, 2013 5:04 am |
|
|
SherpaDoug wrote: | What kind of IR sensor are you using? If it has a simple 0 or 1 output then it should substitute for a microswitch with no code changes except maybe an inversion.
If the sensor has some sort of pulse width or pulse timing output then things get more complicated. The sensor datasheet will tell you what the output format is. |
To SherpaDoug
The output is 0 and 1. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Jan 07, 2013 1:26 pm |
|
|
indio_19gen wrote: | SherpaDoug wrote: | What kind of IR sensor are you using? If it has a simple 0 or 1 output then it should substitute for a microswitch with no code changes except maybe an inversion.
If the sensor has some sort of pulse width or pulse timing output then things get more complicated. The sensor datasheet will tell you what the output format is. |
To SherpaDoug
The output is 0 and 1. |
So code that works for a microswitch should work for these IR sensors with no changes. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|