As suggested in the thread Create 38kHz square wave with Teensy LC?, to generate a 38kHz signal, I am using:
How do I quickly modulate the signal, i.e. turn it on an off?
What comes to my mind:
The project is a light barrier with crossing beams to detect motion of a hand. For two reasons I am considering quickly cycling through the beams instead of having them on all the time:
Code:
analogWriteFrequency(myPin, 38000);
analogWrite(myPin, 128); // for a 50:50 square wave
How do I quickly modulate the signal, i.e. turn it on an off?
What comes to my mind:
- Alternate digitalWrite(myPin, LOW) and analogWriteFrequency(myPin, 38000).
- Alternate analogWrite(myPin, 0) and analogWrite(myPin, 128).
- Modulate the signal using an external component, e.g. a transistor.
The project is a light barrier with crossing beams to detect motion of a hand. For two reasons I am considering quickly cycling through the beams instead of having them on all the time:
- To avoid the wrong sensor from being triggered (by reflective objects, or by neighboring beams).
- To generate bursts. In a message on Electrical Engineering Stack Exchange I was told that the sensor which I am using, the Vishay TSSP4038 only reacts to bursts of 38kHz. That being said, I cannot reproduce the issue. In my current setup, the sensor constantly outputs high when a beam is interrupted, and it constantly outputs low when it sees 38kHz.