metalx1000

Very basic IR Remote Receiver to Serial

Jun 25th, 2016
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. //Install library
  2. //http://pastebin.com/kNMMxkkk
  3. //For computer side of things http://pastebin.com/PXCbLKNj
  4. //------------------------------------------------------------------------------
  5. // Include the IRremote library header
  6. //
  7. #include <IRremote.h>
  8.  
  9. //------------------------------------------------------------------------------
  10. // Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838)
  11. //
  12. int recvPin = 11;
  13. IRrecv irrecv(recvPin);
  14.  
  15. //+=============================================================================
  16. // Configure the Arduino
  17. //
  18. void  setup ( )
  19. {
  20.   Serial.begin(9600);   // Status message will be sent to PC at 9600 baud
  21.   irrecv.enableIRIn();  // Start the receiver
  22. }
  23.  
  24.  
  25. void  dumpCode (decode_results *results)
  26. {
  27.  
  28.     // All protocols have data
  29.     Serial.print(results->value, HEX);
  30.     Serial.print("\n");
  31.  
  32. }
  33.  
  34. //+=============================================================================
  35. // The repeating section of the code
  36. //
  37. void  loop ( )
  38. {
  39.   decode_results  results;        // Somewhere to store the results
  40.  
  41.   if (irrecv.decode(&results)) {  // Grab an IR code
  42.    
  43.     dumpCode(&results);           // Output the results as source code
  44.     irrecv.resume();              // Prepare for the next value
  45.   }
  46. }
Add Comment
Please, Sign In to add comment