Wireless Telemetry Using a very Few Sensors, Xbee, LCD.

Transmitter Side Code:

Arduino Code:
  1.  
  2.  
  3. int tempC;
  4. int tempPin = 0;
  5. int ldrPin = 1;
  6. int brightness = 0;
  7. void setup()
  8. {
  9. Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
  10. }
  11.  
  12. void loop()
  13. {
  14. tempC = analogRead(tempPin); //read the value from the sensor
  15. tempC = (5.0 * tempC * 100.0) / 1024.0; //convert the analog data to temperature
  16. delay(20);
  17. brightness = analogRead(ldrPin);
  18.  
  19. Serial.write('<');
  20. Serial.print(tempC);
  21. Serial.write('>');
  22. Serial.print(brightness);
  23. Serial.write(']');
  24.  
  25.  
  26. delay(1000); //wait one second before sending new data
  27. }
  28.  

Receiver Side Code:

Arduino Code:
  1.  
  2. #include "LiquidCrystal.h"
  3. LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
  4.  
  5. #define IDLE 0
  6. #define RECEIVING1 1
  7. #define RECEIVING2 2
  8.  
  9. int remotetemp = 0;
  10. int remotebrightness = 0;
  11. byte status = IDLE;
  12.  
  13. void setup()
  14. {
  15. // initialize serial communication:
  16. Serial.begin(9600);
  17. lcd.begin(16, 2);
  18. lcd.clear();
  19. }
  20.  
  21. void loop() {
  22. if (Serial.available()) {
  23. int c = Serial.read();
  24. if (status == RECEIVING1 && c >= '0' && c <= '9') {
  25. remotetemp = remotetemp * 10 + (c - '0');
  26.  
  27. } else if (status == RECEIVING2 && c >= '0' && c <= '9') {
  28. remotebrightness = remotebrightness * 10 + (c - '0');
  29.  
  30. } else if (status == RECEIVING1 && c == '>') {
  31. status = RECEIVING2;
  32.  
  33.  
  34. } else if (c == ']') {
  35. status = IDLE;
  36.  
  37. // remote value received completely, do something with it
  38. lcd.setCursor(0, 0);
  39. lcd.print("Temp is: ");
  40. lcd.setCursor(10, 0);
  41. lcd.print(remotetemp);
  42. lcd.setCursor(13, 0);
  43. lcd.print(".C");
  44. lcd.setCursor(0, 1);
  45. lcd.print("Brightness: ");
  46. lcd.setCursor(13, 1);
  47. lcd.print(remotebrightness);
  48. } else if (c == '<') {
  49. status = RECEIVING1;
  50. remotetemp = 0;
  51. remotebrightness = 0;
  52. }
  53. }
  54. }
  55.