Advertisement
seston

greenhouse windows 3 v.0.4

May 17th, 2016
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. // This is for arduino pro mini. if you use other arduino, check pwm pin numbers
  2. //Temperature sensor DS18B20. I put it inside greenhouse shady place
  3.  
  4.  
  5. #include <OneWire.h>
  6. #include <DallasTemperature.h>
  7.  
  8. #define win1MotorA 4
  9. #define win1MotorB 5
  10. #define win1Speed 6 //has to be PWM pin
  11. #define win2MotorA 7
  12. #define win2MotorB 8
  13. #define win2Speed 9 //has to be PWM pin
  14. #define win3Speed 10 //has to be PWM pin
  15. #define win3MotorA 11
  16. #define win3MotorB 12
  17.  
  18.  
  19. // Data wire is plugged into pin 3 on the Arduino
  20. #define ONE_WIRE_BUS 3
  21.  
  22. // Setup a oneWire instance to communicate with any OneWire devices
  23. OneWire oneWire(ONE_WIRE_BUS);
  24.  
  25. // Pass our oneWire reference to Dallas Temperature.
  26. DallasTemperature sensors(&oneWire);
  27.  
  28. // Assign the addresses of your 1-Wire temp sensors.
  29. // See the tutorial on how to obtain these addresses:
  30. // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
  31.  
  32. DeviceAddress thermometer = { 0x28, 0xC8, 0xDC, 0x51, 0x07, 0x00, 0x00, 0x72 };
  33.  
  34.  
  35.  
  36. int X = 0;
  37.  
  38. void setup(void)
  39. {
  40.  
  41. pinMode (win1MotorA, OUTPUT);
  42. pinMode (win1MotorB, OUTPUT);
  43. pinMode (win2MotorA, OUTPUT);
  44. pinMode (win2MotorB, OUTPUT);
  45. pinMode (win3MotorA, OUTPUT);
  46. pinMode (win3MotorB, OUTPUT);
  47. pinMode (win1Speed, OUTPUT);
  48. pinMode (win2Speed, OUTPUT);
  49. pinMode (win3Speed, OUTPUT);
  50. digitalWrite (win1MotorA, LOW);
  51. digitalWrite (win1MotorB, LOW);
  52. digitalWrite (win2MotorA, LOW);
  53. digitalWrite (win2MotorB, LOW);
  54. digitalWrite (win3MotorA, LOW);
  55. digitalWrite (win3MotorB, LOW);
  56. digitalWrite (win1Speed, LOW);
  57. digitalWrite (win2Speed, LOW);
  58. digitalWrite (win3Speed, LOW);
  59.  
  60. // start serial port
  61. Serial.begin(9600);
  62. // Start up the library
  63. sensors.begin();
  64. // set the resolution to 10 bit (good enough?)
  65. sensors.setResolution(thermometer, 10);
  66.  
  67. }
  68.  
  69. void printTemperature(DeviceAddress deviceAddress)
  70. {
  71. float tempC = sensors.getTempC(deviceAddress);
  72. if (tempC == -40.00) {
  73. Serial.print("Error getting temperature");
  74. } else {
  75. Serial.print("C: ");
  76. Serial.print(tempC);
  77. }
  78.  
  79.  
  80. //Window 1
  81.  
  82. if (tempC >= 16 && X == 0) { // if temp => +16 1. window opens
  83. digitalWrite(win1MotorA, HIGH); // motor direction if need other direction change
  84. digitalWrite(win1MotorB, LOW); // motor direction if need other direction change
  85. analogWrite(win1Speed, 255); // motor full speed
  86. delay(6000); // time for motor full speed
  87. analogWrite(win1Speed, 200); // slower speed for opens window
  88. delay(3000); // time for slow open
  89. analogWrite(win1Speed, 0); // motor stop
  90. X = 1;
  91. }
  92.  
  93. if (tempC <= 15 && X == 1) { // if temp <= 15 1. window closes
  94.  
  95. X = 0;
  96.  
  97. digitalWrite(win1MotorA, LOW);
  98. digitalWrite(win1MotorB, HIGH);
  99. analogWrite(win1Speed, 255); // motor full speed
  100. delay(6000); // time for motor full speed
  101. analogWrite(win1Speed, 50); // slow speed for close
  102. delay(3000); // time for slow close
  103. analogWrite(win1Speed, 0); // motor stop
  104. }
  105.  
  106. //window 2
  107.  
  108. if (tempC >= 23 && X == 0) { // if temp => +23 2. window opens
  109. digitalWrite(win2MotorA, HIGH); // motor direction if need other direction change
  110. digitalWrite(win2MotorB, LOW); // motor direction if need other direction change
  111. analogWrite(win2Speed, 255); // motor full speed
  112. delay(6000); // time for motor full speed
  113. analogWrite(win2Speed, 200); // slower speed for opens window
  114. delay(3000); // time for slow open
  115. analogWrite(win2Speed, 0); // motor stop
  116. X = 1;
  117. }
  118.  
  119. if (tempC <= 21 && X == 1) { // if temp <= 21 2. window closes
  120.  
  121. X = 0;
  122.  
  123. digitalWrite(win2MotorA, LOW); // motor direction if need other direction change
  124. digitalWrite(win2MotorB, HIGH); // motor direction if need other direction change
  125. analogWrite(win2Speed, 255); // motor full speed
  126. delay(6000); // time for motor full speed
  127. analogWrite(win2Speed, 50); // slow speed for close
  128. delay(3000); // time for soft close :-)
  129. analogWrite(win2Speed, 0); // motor stop
  130. }
  131.  
  132. //window 3
  133.  
  134.  
  135. if (tempC >= 25 && X == 0) { // if temp => +25 3. window opens
  136. digitalWrite(win3MotorA, HIGH); // motor direction if need other direction change
  137. digitalWrite(win3MotorB, LOW); // motor direction if need other direction change
  138. analogWrite(win3Speed, 255); // motor full speed
  139. delay(6000); // time for motor full speed
  140. analogWrite(win3Speed, 200); // slower speed for opens window
  141. delay(3000); // time for slow open
  142. analogWrite(win3Speed, 0); // motor stop
  143. X = 1;
  144. }
  145.  
  146. if (tempC <= 24 && X == 1) { // if temp <= 24 3. window closes
  147.  
  148. X = 0;
  149.  
  150. digitalWrite(win1MotorA, LOW);
  151. digitalWrite(win1MotorB, HIGH);
  152. analogWrite(win1Speed, 255); // motor full speed
  153. delay(6000); // time for motor full speed
  154. analogWrite(win1Speed, 50); // slow speed for close
  155. delay(3000); // time for slow close
  156. analogWrite(win1Speed, 0); // motor stop
  157. }
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165. }
  166.  
  167. void loop(void)
  168.  
  169.  
  170. {
  171. Serial.print("Getting temperatures...\n\r");
  172. sensors.requestTemperatures();
  173.  
  174. Serial.print("Temperature is: ");
  175. printTemperature(thermometer);
  176. Serial.print("\n\r");
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement