I have an Arduino Nano that is pulsing an IR LED at 38kHz in hardware and a TSOP4136 IR receiver. To stop the AGC from stopping the signal I am sending 20mS bursts followed by 20mS gaps. If I look at the signal on the LED I see 20mS bursts of 38kHz. If I look at the output of the TSOP I see 20mS square waves. If I vary the on/off times I see this reflected on the scope. The IR LED and TSOP are on a breadboard facing each other and appear to be working exactly as expected. However, if I put a barrier between them the (TSOP) signal persists. If I turn of the LED in software the signal disappears, if I disconnect the ground from the LED the signal disappears. It's as though powering the LED causes the TSOP signal - not the IR light.
This is the code I'm using,
The LCD I'm using uses an I²C backpack of my own design so just ignore that bit.
The LCD displays "Sense = 0" but if I remove the delayMicroseconds(500) it reads "Sense = 1" which also suggests the IR is being seen.
OK, while writing this I just stuck a 1/4" sticky note pad in the beam and noticed that for a very short time it register a high. This is the opposite of what I was expecting,
I was expecting that if I used a continuous 38kHz signal then it would initially go low but then return high when the AGC kicked in.
The 20mS doesn't seem to be too long as changing to 2mS gives the same result.
Can anyone explain this behaviour?
Thanks
Mike.
This is the code I'm using,
Code:
#include <mwI2C.h>
#define IR 11
#define sense 2
uint32_t tickLED;
uint8_t onOff;
LCD lcd;
void setup(){
Serial.begin(115200);
Serial.println("\n\nHello");
lcd.init(0x3f,20,4);
pinMode (IR, OUTPUT);
pinMode (sense, INPUT_PULLUP);
// set up Timer 2
TCCR2A = _BV (COM2A0) | _BV(WGM21); // CTC, toggle OC2A on Compare Match
TCCR2B = _BV (CS20); // No prescaler
OCR2A = 207; // compare A register value (210 * clock speed)
// = 13.125 nS , so frequency is 1 / (2 * 13.125) = 38095
//adjusted using scope to give 38kHz
}
void loop(){
if(millis()-tickLED>20){
tickLED=millis();
if(onOff++&1){ //alternate
pinMode(IR,OUTPUT); //turn on 38kHz
delayMicroseconds(500);
if(digitalRead(sense)){
lcd.setCursor(0,1);
lcd.print("Sense = 1");
}else{
lcd.setCursor(0,1);
lcd.print("Sense = 0");
}
}else{
pinMode(IR,INPUT); //turn off 38kHz
//tickLED-=10; //will change the on/off time ratio
}
}
}
The LCD displays "Sense = 0" but if I remove the delayMicroseconds(500) it reads "Sense = 1" which also suggests the IR is being seen.
OK, while writing this I just stuck a 1/4" sticky note pad in the beam and noticed that for a very short time it register a high. This is the opposite of what I was expecting,
I was expecting that if I used a continuous 38kHz signal then it would initially go low but then return high when the AGC kicked in.
The 20mS doesn't seem to be too long as changing to 2mS gives the same result.
Can anyone explain this behaviour?
Thanks
Mike.