Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The IR333C-A is an infrared (IR) emitter diode, which emits IR light when a current is applied. You can use it with an Arduino to send IR signals. In this example, we'll use a simple modulation scheme to send a basic IR signal:
- In this example, we connect the IR333C-A IR emitter to digital pin 9 on the Arduino. The modulation frequency is set to 38 kHz, which is commonly used for IR communication. The sendIRSignal function turns the IR emitter on and off at the modulation frequency for a specified signal duration (100 ms in this case).
- The loop function sends the IR signal every 1 second. You can modify this code to send specific IR codes or implement a protocol like NEC or RC-5, depending on your application.
- Note: This example assumes you have already connected the IR333C-A IR emitter to your Arduino with a current-limiting resistor according to the manufacturer's recommendations. Be sure to consult the IR333C-A datasheet for proper wiring and usage instructions.
- */
- const int irPin = 9; // IR emitter connected to digital pin 9
- // Modulation frequency (in Hz)
- const int modulationFrequency = 38000;
- // Signal duration (in milliseconds)
- const int signalDuration = 100;
- void setup() {
- pinMode(irPin, OUTPUT);
- }
- void loop() {
- // Send IR signal
- sendIRSignal();
- // Wait for 1 second before sending the next signal
- delay(1000);
- }
- void sendIRSignal() {
- // Calculate the modulation period (in microseconds)
- int modulationPeriod = 1000000 / modulationFrequency;
- // Calculate the number of modulation cycles
- int modulationCycles = (signalDuration * 1000) / modulationPeriod;
- for (int i = 0; i < modulationCycles; i++) {
- digitalWrite(irPin, HIGH); // Turn the IR emitter on
- delayMicroseconds(modulationPeriod / 2);
- digitalWrite(irPin, LOW); // Turn the IR emitter off
- delayMicroseconds(modulationPeriod / 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement