I am aware of the ir Libraries, but it is overkill for my purpose and there seems to be some processing delay with the libraries that I need to avoid.
What I want is a simple and fast "ir break beam detection circuit" using the ESP32 and the Arduino IDE. I want to use VS1838B sensors, so require a 38KHz ir LED sender. I am using two ESP32's (one sender, one receiver) as they will eventually be physically separated (~5feet), but for now they are only about 12" apart.
I thought this would be relatively simple, but I am getting a constant HIGH from the Sensor Pin regardless of if the 38K modulated LED is on or off. I have tested the LED and Sensor using the TinySender/TinyReceiver sketches and they work (aside from missing some data because I am polling so rapidly), so hardware appears to be valid.
I PWM an LED at 38,000Hz freq. Tested the LED will a RED LED and it appears to be working correctly, although I have not tested the modulation with an oscilloscope.
I am looking for a LOW from the VS1838B when the LED is turned on, but I never get the LOW I am expecting. I would love to know what I am doing wrong...
//ESP32 SENDER, the number of the LED pin
const int ledPin = 23;
// setting PWM properties
const int freq = 38000;
const int ledChannel = 0;
const int resolution = 8;
int dutyCycle = 255;
void setup(){
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
dutyCycle = 255;
ledcWrite(ledChannel, dutyCycle);
}
void loop(){
}
//ESP32 RECEIVER, the number of the Sensor pin
const int sensorPin = 23;
void setup(){
pinMode(sensorPin, INPUT);
}
void loop(){
printf("sensorPin(%d): %d\n", sensorPin, digitalRead(sensorPin)); //only get a 1 as output
delay(100);
}