Advertisement
microrobotics

IR333C-A

Apr 15th, 2023
1,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. 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:
  3.  
  4. 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).
  5.  
  6. 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.
  7.  
  8. 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.
  9. */
  10.  
  11. const int irPin = 9; // IR emitter connected to digital pin 9
  12.  
  13. // Modulation frequency (in Hz)
  14. const int modulationFrequency = 38000;
  15.  
  16. // Signal duration (in milliseconds)
  17. const int signalDuration = 100;
  18.  
  19. void setup() {
  20.   pinMode(irPin, OUTPUT);
  21. }
  22.  
  23. void loop() {
  24.   // Send IR signal
  25.   sendIRSignal();
  26.  
  27.   // Wait for 1 second before sending the next signal
  28.   delay(1000);
  29. }
  30.  
  31. void sendIRSignal() {
  32.   // Calculate the modulation period (in microseconds)
  33.   int modulationPeriod = 1000000 / modulationFrequency;
  34.  
  35.   // Calculate the number of modulation cycles
  36.   int modulationCycles = (signalDuration * 1000) / modulationPeriod;
  37.  
  38.   for (int i = 0; i < modulationCycles; i++) {
  39.     digitalWrite(irPin, HIGH); // Turn the IR emitter on
  40.     delayMicroseconds(modulationPeriod / 2);
  41.  
  42.     digitalWrite(irPin, LOW); // Turn the IR emitter off
  43.     delayMicroseconds(modulationPeriod / 2);
  44.   }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement