1. // transmitter.pde
  2. //
  3. // Simple example of how to use VirtualWire to transmit messages
  4. // Implements a simplex (one-way) transmitter with an TX-C1 module
  5. //
  6. // See VirtualWire.h for detailed API docs
  7. // Author: Mike McCauley (mikem@airspayce.com)
  8. // Copyright (C) 2008 Mike McCauley
  9. // $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
  10. #include <VirtualWire.h>
  11. void setup() {
  12. Serial.begin(9600); // Debugging only
  13. Serial.println("setup");
  14. // Initialise the IO and ISR
  15. vw_set_tx_pin(8);
  16. //vw_set_ptt_inverted(true); // Required for DR3100
  17. vw_setup(2000); // Bits per sec
  18. }
  19. void loop() {
  20. const char *msg = "hello";
  21. digitalWrite(13, true); // Flash a light to show transmitting
  22. vw_send((uint8_t *)msg, strlen(msg));
  23. vw_wait_tx(); // Wait until the whole message is gone
  24. digitalWrite(13, false);
  25. delay(200);
  26. }
  27.  
  28. ##############FILE SEPARATOR##############
  29.  
  30. // receiver.pde
  31. //
  32. // Simple example of how to use VirtualWire to receive messages
  33. // Implements a simplex (one-way) receiver with an Rx-B1 module
  34. //
  35. // See VirtualWire.h for detailed API docs
  36. // Author: Mike McCauley (mikem@airspayce.com)
  37. // Copyright (C) 2008 Mike McCauley
  38. // $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
  39. #include <VirtualWire.h>
  40. void setup() {
  41. Serial.begin(9600); // Debugging only
  42. Serial.println("setup");
  43. // Initialise the IO and ISR
  44. vw_set_rx_pin(8);
  45. //vw_set_ptt_inverted(true); // Required for DR3100
  46. vw_setup(2000); // Bits per sec
  47. vw_rx_start(); // Start the receiver PLL running
  48. }
  49. void loop() {
  50. uint8_t buf[VW_MAX_MESSAGE_LEN];
  51. uint8_t buflen = VW_MAX_MESSAGE_LEN;
  52. if (vw_get_message(buf, &buflen)) {
  53. int i;
  54. digitalWrite(13, true); // Flash a light to show received good message
  55. // Message with a good checksum received, dump it.
  56. Serial.print("Got: ");
  57. for (i = 0; i < buflen; i++) {
  58. Serial.print(buf[i], HEX);
  59. Serial.print(" ");
  60. }
  61. Serial.println("");
  62. digitalWrite(13, false);
  63. }
  64. }
  65.  
  66. PIN setup: http://imgur.com/XFakPpC