Ir beam break sensor

Discussion in 'The Projects Forum' started by geoffers, Apr 21, 2013.

  1. geoffers

    Thread Starter Active Member

    Oct 25, 2010
    239
    6
    Morning all,
    I've a project on the go at the moment that requires a pic to sense if there's milk in a pipe or not, the pipe is clear so I was hoping to use a ir pair as a beam break sensor. I've hunted about the net a bit and seen quite a few examples that modulate the output of the ir led and then use a band pass filter at the sensor end.

    From what I understand this is to aviod any stray ir triggering the sensor?
    Other examples seem much simpler and use the ir sensor as a switch.

    I'm going to have to make a plastic holder for the emitter and sensor so eliminating stray ir shouldn't be to tricky. Are there any other reasons to go for modulation? I have a spare pwm output on the pic but the simple option is attractive!
    Cheers Geoff
     
  2. DickCappels

    Moderator

    Aug 21, 2008
    2,653
    632
    There are two reasons for switching the LED on and off. One is that doing so makes it easy to separate the IR signal from any background noise or dark current in the IR detector. The other is that it then becomes easy to amplify the pulses without amplifying any DC offset from the IR detector.

    It really makes life a lot easier, especially since it is likely to make sensitivity adjustment unnecessary.
     
    geoffers likes this.
  3. wayneh

    Expert

    Sep 9, 2010
    12,123
    3,048
    Modulation is also used to get a higher peak output without a higher average output, which is hard on the life of the LED. Useful if you want to drive a signal through a finger, say, to look at a pulse.

    Your application could likely be made to work fine without modulation, but it's hard to speculate whether it would save you any time or trouble, for the reasons Dick has noted. More complicated upfront, but far easier when you put it into the field.
     
    geoffers likes this.
  4. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I hope this is not considered hi-jacking, but I am wondering if I need to pulse a visible LED that is illuminating a photo transistor less than 1/4" away and will be blocked by a coin passing between them. I intend to measure the time it takes the coin to pass by.
     
  5. geoffers

    Thread Starter Active Member

    Oct 25, 2010
    239
    6
    Thanks for the quick reply,
    That makes good sense, what do folks think of this circuit, I found it on pcbheaven.com

    irshorddistancebeamcut_1276410085.png

    Hope he doesn't mind me reproducing it!(its a interesting site).

    I can do away with the transmitter circuit shown on the site and use the pwm output I have spare to drive the ir led. If I hadn't already used the a/d on my pic I could have used the on board comparator.

    Cheers Geoff
     
  6. wayneh

    Expert

    Sep 9, 2010
    12,123
    3,048
    I don't think you'd gain much from modulation in this application, unless it's out in direct sunlight or some other "noisy" environment. It's all about signal to noise.
     
    tracecom likes this.
  7. Bernard

    AAC Fanatic!

    Aug 7, 2008
    4,172
    397
    I've tried unmodulated & modulated IR detection at 17 ft goal- modulated won, but at 1 ft no difference, red or IR, no difference; just reasonable match wavelengths of Rx & Tx. Might use slot aperatures to more define break.
     
    tracecom likes this.
  8. geoffers

    Thread Starter Active Member

    Oct 25, 2010
    239
    6
    Hi all,
    Thanks for the help I've had here and in the Embedded controllers section.
    Here's what I've come up with;

    irsensor.gif

    The 12f675 drives the ir led at about 1.5khz, I used the internal voltage ref set to maximum as the +ref for the comparator, the 50k pot adjusts the sensitivity.

    Its sensitive enough to be be triggered by the presence of milk in a clear pipe.:)

    Here's the code;

    Code ( (Unknown Language)):
    1. #INCLUDE P12F675.INC
    2.     LIST P=12F675
    3.     ORG  0X00
    4.     GOTO    START
    5.  
    6. __CONFIG_INTRC_ORC_NOCLKOUT
    7. __CONFIG_WDT_OFF_
    8. __CONFIG_PWRTE_ON
    9. __CONFIG_MCLRE_OFF
    10. __CONFIG_BOREN_OFF
    11. __CONFIG_CP_OFF
    12. __CONFIG_CPD_OFF
    13.    
    14.     COUNT   EQU 0X20
    15.     TIME    EQU 0X21
    16. ;#########################################################
    17. DELAYP5 MOVLW   .100
    18.         MOVWF   COUNT
    19. TIMED   CALL    DELAY
    20.         DECFSZ  COUNT
    21.         GOTO    TIMED
    22.         RETLW   0
    23.  
    24. DELAY   CLRF    TMR0
    25. LOOPA   MOVF    TMR0,W
    26.         SUBLW   .39
    27.         BTFSS   STATUS,Z
    28.         GOTO    LOOPA
    29.         RETLW   0
    30.  
    31. DELAY1.5    CLRF    TMR0
    32. LOOPB       MOVF    TMR0,W
    33.             SUBLW   .3
    34.             BTFSS   STATUS,Z
    35.             GOTO    LOOPB
    36.             RETLW   0
    37.  
    38.  
    39. START BSF   STATUS,5    ;BANK1
    40.  
    41.     CLRF    ANSEL
    42.  
    43. ;   CALL    3FFH
    44. ;   MOVWF   OSCCAL
    45.     MOVLW   B'00001011' ;GP0, GP1 COMPARATOR INPUT REST OUTPUT
    46.     MOVWF   TRISIO
    47.     MOVLW   B'10001111'
    48.     MOVWF   VRCON       ;TURNS ON COMPARATOR VREF, LOW RANGE, ABOUT 3V
    49.     CLRWDT
    50.     MOVLW   B'00000111'
    51.     MOVWF   OPTION_REG
    52.     BCF     STATUS,5    ;BANK0
    53.  
    54.     MOVLW   B'00010011'     ;   B'00000011' ;GP0=CIN+ GP1=CIN- GP0=OUTPUT
    55.     MOVWF   CMCON
    56.  
    57.     CLRF    GPIO
    58.  
    59. ;####################################################
    60.  
    61.  
    62. BEGIN   BSF     GPIO,5
    63.         CALL    DELAY1.5
    64.         BCF     GPIO,5
    65.         CALL    DELAY1.5
    66.         GOTO    BEGIN
    67.  
    68. END
    I have had a issue with the configuration bits so set them in mplab.

    Cheers Geoff
     
Loading...