Last active
April 21, 2023 23:52
-
-
Save trytone/e97edae798e2aa7f6cdfbf4baa256b59 to your computer and use it in GitHub Desktop.
IR Transceiver for Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <IRremote.h> | |
const int ir_recv_pin = 8; | |
const int ir_send_pin = 3; | |
IRrecv irrecv(ir_recv_pin); | |
IRsend irsend(ir_send_pin); | |
decode_results results; | |
uint8_t rawCodes[RAW_BUFFER_LENGTH]; | |
int frequency = 38; // frequency in kHz | |
/* | |
+-----+ | |
+----[PWR]-------------------| USB |--+ | |
| +-----+ | | |
| GND/RST2 [ ][ ] | | |
| MOSI2/SCK2 [ ][ ] A5/SCL[ ] | | |
| 5V/MISO2 [ ][ ] A4/SDA[ ] | | |
| AREF[ ] | | |
| GND[ ] | | |
| [ ]N/C SCK/13[ ] | | |
| [ ]IOREF MISO/12[ ] | | |
| [ ]RST MOSI/11[ ]~| IR Receiver | |
| [ ]3V3 +---+ 10[ ]~| | |
| [ ]5v -| A |- 9[ ]~| +5V --|\ | |
| [ ]GND -| R |- 8[*]=|=======--| ) | |
| [ ]GND -| D |- | GND --|/ | |
| [ ]Vin -| U |- 7[ ] | | |
| -| I |- 6[ ]~| | |
| [ ]A0 -| N |- 5[ ]~| IR Diode | |
| [ ]A1 -| O |- 4[ ] | | |
| [ ]A2 +---+ INT1/3[*]=|=======--|\ | |
| [ ]A3 INT0/2[ ] | GND --|/ | |
| [ ]A4/SDA RST SCK MISO TX>1[ ] | | |
| [ ]A5/SCL [ ] [ ] [ ] RX<0[ ] | | |
| [ ] [ ] [ ] | | |
| UNO_R3 GND MOSI 5V ____________/ | |
\_______________________/ | |
*/ | |
void setup() | |
{ | |
Serial.begin(9600); | |
irrecv.enableIRIn(); // Start the receiver | |
irrecv.blink13(true); // Enable feedback LED | |
} | |
void loop() | |
{ | |
if (Serial.available() > 0) { | |
Serial.read(); | |
ir_send(); | |
} | |
ir_recv(); | |
delay(10); | |
} | |
void ir_send() | |
{ | |
irrecv.stop(); | |
Serial.flush(); | |
irsend.sendRaw(rawCodes, RAW_BUFFER_LENGTH, frequency); | |
irrecv.resume(); | |
} | |
void ir_recv() | |
{ | |
if (irrecv.decode(&results)) { | |
if (results.rawlen > 4) { | |
irrecv.printIRResultRawFormatted(&Serial, true); | |
irrecv.compensateAndStoreIRResultInArray(rawCodes); | |
} | |
irrecv.resume(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment