CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to interface IR proximity sensor as switch?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
indio_19gen



Joined: 05 Jan 2013
Posts: 2

View user's profile Send private message

How to interface IR proximity sensor as switch?
PostPosted: Sat Jan 05, 2013 7:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jan 05, 2013 8:24 am     Reply with quote

you can find your answer here:

http://www.ccsinfo.com/forum/viewtopic.php?t=47549
_________________
CCS PCM 5.078 & CCS PCH 5.093
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Jan 06, 2013 9:40 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 06, 2013 10:21 am     Reply with quote

...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

View user's profile Send private message

PostPosted: Mon Jan 07, 2013 5:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 07, 2013 1:26 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group