Advertisement
seston

Kasvuhoone tuulutus ilma ukseta 29.05.2017

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