document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.  
  3. Sensor Transmitter
  4. By Markus Ulfberg 2012-07-06
  5.  
  6. Takes a sensor reading 0-1023
  7. converts it to a char array and sends
  8. to RF receiver unit via VirtualWire
  9.  
  10. */
  11.  
  12. #include <VirtualWire.h>
  13.  
  14. // LED's
  15. const int ledPin = 13;
  16.  
  17. // Sensors
  18. const int Sensor1Pin = A1;
  19. // const int Sensor2Pin = 3;
  20.  
  21. int Sensor1Data;
  22. //int Sensor2Data;
  23. char Sensor1CharMsg[4];
  24.  
  25. void setup() {
  26.  
  27. // PinModes
  28. // LED
  29. pinMode(ledPin,OUTPUT);
  30. // Sensor(s)
  31. pinMode(Sensor1Pin,INPUT);
  32.  
  33. // for debugging
  34. Serial.begin(9600);
  35.  
  36. // VirtualWire setup
  37. vw_setup(2000); // Bits per sec
  38.  
  39.  
  40. }
  41.  
  42. void loop() {
  43.  
  44. // Read and store Sensor 1 data
  45. Sensor1Data = analogRead(Sensor1Pin);
  46.  
  47. // Convert integer data to Char array directly
  48. itoa(Sensor1Data,Sensor1CharMsg,10);
  49.  
  50. // DEBUG
  51. Serial.print("Sensor1 Integer: ");
  52. Serial.print(Sensor1Data);
  53. Serial.print(" Sensor1 CharMsg: ");
  54. Serial.print(Sensor1CharMsg);
  55. Serial.println(" ");
  56. delay(10);
  57.  
  58. // END DEBUG
  59.  
  60. digitalWrite(13, true); // Turn on a light to show transmitting
  61. vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
  62. vw_wait_tx(); // Wait until the whole message is gone
  63. digitalWrite(13, false); // Turn off a light after transmission
  64. delay(200);
  65.  
  66. } // END void loop...
');