Advertisement
Guest User

Henmulator 1.2

a guest
Apr 2nd, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "HTU21D.h"
  3.  
  4.  
  5. // initiate HTU21D //
  6. HTU21D myHumidity;
  7.  
  8. // define pins for the two relays//
  9. int lRelay = 11;
  10. int hRelay = 13;
  11.  
  12. //define the threshold values for humidity and temperature//
  13.  
  14. int tempThresh = 38;
  15. int humdThresh = 60;
  16.  
  17. //define floats for temperature and humidity//
  18.  
  19. float humd;
  20. float temp;
  21.  
  22. void setup() {
  23.  
  24. Serial.begin(9600);
  25. myHumidity.begin();
  26.  
  27. pinMode(lRelay, OUTPUT);
  28. pinMode(hRelay, OUTPUT);
  29.  
  30. //start with relays off//
  31. digitalWrite(lRelay, LOW);
  32. digitalWrite(hRelay, LOW);
  33.  
  34. }
  35.  
  36. void loop() {
  37.  
  38. readSensor();
  39.  
  40. if (humd < humdThresh){
  41. digitalWrite(hRelay, HIGH);
  42. }else{
  43. digitalWrite(hRelay, LOW);
  44. }
  45.  
  46. if (temp < tempThresh){
  47. digitalWrite(lRelay, HIGH);
  48. }else{
  49. digitalWrite(lRelay, LOW);
  50. }
  51.  
  52. delay(10000);
  53. }
  54. //function to turn on relay for humidifier when humidity is below threshold//
  55. void runHumd(){
  56. do{
  57. readSensor();
  58. digitalWrite(hRelay, HIGH);
  59. delay(10000);
  60. }
  61. while(humd <=humdThresh);
  62. }
  63. //function to turn on relay for lights when temperature is below threshold//
  64. void runTemp(){
  65. do{
  66. readSensor();
  67. digitalWrite(lRelay, HIGH);
  68. delay(10000);
  69. }
  70. while(temp <=tempThresh);
  71. }
  72.  
  73. //function for checking the sensor every 10 seconds//
  74. void readSensor(){
  75. humd = myHumidity.readHumidity();
  76. temp = myHumidity.readTemperature();
  77. Serial.print("Time:");
  78. Serial.print(millis());
  79. Serial.print(" Temperature:");
  80. Serial.print(temp, 1);
  81. Serial.print("C");
  82. Serial.print(" Humidity:");
  83. Serial.print(humd, 1);
  84. Serial.print("%");
  85.  
  86. Serial.println();
  87. delay(10000);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement