Is it ok to Inhibit proximity sensor like this

Hey All. I have a homeade proximity sensor ( tsop and emitter) Arduino Pin 3 sourcing the 38khz. I need to occasionally prevent my proximity sensor from "detecting" if you will. Powering down the tsop is undesirable because it's active low goes to arduino input. I've tried digitalwriting the emitter's source pin low but it doesn't change state, I think because of the code used to generate the square wave. (See square wave code below). My currently working plan B is to sink the emitter's ground terminal to an arduino pin and writing that pin high when I want the emitter off. Any downsides to doing it like this? It does cost me an extra io pin. Being able to write that pwm pin 3 low would be ideal.

volatile byte pulse = 0;

ISR(TIMER2_COMPB_vect){  
    pulse++;
  if(pulse >= 8) { 
    pulse =0;
    TCCR2A ^= _BV(COM2B1); 
  }
}

void setIrModOutput(){  
  pinMode(3, OUTPUT);
  TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); 
  TCCR2B = _BV(WGM22) | _BV(CS22);
  OCR2A = 51; // defines the frequency 51 = 38.4 KHz, 54 = 36.2 KHz, 58 = 34 KHz, 62 = 32 KHz
  OCR2B = 26;  
  TCCR2B = TCCR2B & 0b00111000 | 0x2; 
}

void setup(){
  setIrModOutput();
  TIMSK2 = _BV(OCIE2B); 
}

void loop(){
}

type or paste code here

`type or paste code here`

Why not just ignore the sensor readings when you want to inhibit it ?

1 Like

pinMode(3, INPUT); to disable the transmitter

Low side switch the detector to turn it off and keep its output HIGH.

Switching pin 3 to input worked. it didn't automatically return to output
after my switch was released so I added an "else" like below. Let me know if there is an easier way, Thanks.

 if(digitalRead(halt)==LOW)
  {
    pinMode(3, INPUT);
    display.clearDisplay();
    display.setTextSize(3);
    display.setCursor(10, 7); 
    delay(300);
    display.print("Halted")
  }
    else if(digitalRead(halt)==HIGH)
   {
    pinMode(3, OUTPUT); 
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.