Hi everyone,
I'm working on a project where I want to create an IR proximity sensor using the TSOP1738 IR receiver module and an IR LED connected to an Arduino Nano. I've successfully generated a 38 kHz PWM signal on pin 10 using Timer2 to drive the IR LED. However, I'm unsure how to implement the proximity detection function using the TSOP1738.
Tried to add burst function but that's disturbing my 38Khz Modulated IR LED Signal. what could be wrong ?
I need to enable output GPIO on proximity detection and vice versa.
Here's the code I'm currently using:
const byte LED = 10; // Timer 1 "B" output: OC1B
// 16 MHz clock divided by 38 KHz frequency desired
const long timer1_OCR1A_Setting = 16000000L / 38000L;
// Define burst parameters
#define BURST_DURATION 50 // Duration of each burst in milliseconds
#define BURST_GAP 1000 // Gap between bursts in milliseconds
void generateIRBurst() {
// Generate burst of 38 kHz signal
digitalWrite(LED, HIGH); // Turn on IR LED
delayMicroseconds(13); // ON period for 38 kHz
digitalWrite(LED, LOW); // Turn off IR LED
delayMicroseconds(13); // OFF period for 38 kHz
// Delay to control burst duration
delay(BURST_DURATION);
// Delay to control gap between bursts
delay(BURST_GAP);
}
void setup()
{
pinMode (LED, OUTPUT);
// set up Timer 1 - gives us 38.005 KHz
// Fast PWM top at OCR1A
TCCR1A = _BV (WGM10) | _BV (WGM11) | _BV (COM1B1); // fast PWM, clear OC1B on compare
TCCR1B = _BV (WGM12) | _BV (WGM13) | _BV (CS10); // fast PWM, no prescaler
OCR1A = timer1_OCR1A_Setting - 1; // zero relative
} // end of setup
void loop()
{
OCR1B = (((512) * timer1_OCR1A_Setting) / 1024L) - 1;
// Generate bursts of 38 kHz PWM signal
generateIRBurst();
}