Guest User

MTI - Final-Project Remote Temperature e Humidity Sensor

a guest
Dec 11th, 2010
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. /*
  2. MTI - Final-Project
  3. Remote Temperature e Humidity Sensor
  4. Daniel Freitas - [email protected]
  5. */
  6.  
  7.  
  8. int humidSensorPin = 1; // variable to store the the analog pin for the temperator sensor
  9. int tempSensorPin = 3; // variable to store the the analog pin for the humidity detector
  10.  
  11. int tempSensorValue = 0; // variable to store the value coming from the temperature sensor
  12. int humidSensorValue = 0; // variable to store the value coming from the humidity detector
  13.  
  14. int temperature=0;
  15. int hum=0;
  16.  
  17.  
  18.  
  19. void setup() {
  20. Serial.begin(115200); //bluetooth only works at 115200
  21. }
  22.  
  23.  
  24. void loop()
  25. {
  26.  
  27. int tempSensorValue = analogRead(tempSensorPin); //read temperature
  28. int humidSensorValue = analogRead(humidSensorPin); //read humity value
  29.  
  30.  
  31. if (humidSensorValue >15) { //if the value is higher than 15 (and highest value possible is 1024) it means that the cloth was wet
  32. hum=1;
  33.  
  34. }
  35.  
  36.  
  37. int temperature = map(tempSensorValue, 0, 1023, 32, 212); // maps the values into Fahrenheit scale
  38.  
  39.  
  40.  
  41. //in order to use the Serial.read() function in Processing the numbers sent have to be between 0 and 255.
  42. //Example: if humidity is detected and the temperature is 73F it sends: 173.
  43. int sentdata= temperature + hum*100;
  44.  
  45. Serial.write(sentdata);
  46.  
  47. delay(1000); //writes into serial every 1 sec
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment