Advertisement
seston

Kasvuhoone aknad 02.06.2017

Jun 2nd, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 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. int i = 0;
  41.  
  42. void setup(void)
  43. {
  44. digitalWrite (inverter, LOW);
  45. pinMode (win1MotorA, OUTPUT);
  46. pinMode (win1MotorB, OUTPUT);
  47. pinMode (win2MotorA, OUTPUT);
  48. pinMode (win2MotorB, OUTPUT);
  49. // pinMode (win3MotorA, OUTPUT);
  50. // pinMode (win3MotorB, OUTPUT);
  51. pinMode (win1Speed, OUTPUT);
  52. pinMode (win2Speed, OUTPUT);
  53. // pinMode (win3Speed, OUTPUT);
  54. pinMode (inverter, OUTPUT);
  55. digitalWrite (win1MotorA, LOW);
  56. digitalWrite (win1MotorB, LOW);
  57. digitalWrite (win2MotorA, LOW);
  58. digitalWrite (win2MotorB, LOW);
  59. // digitalWrite (win3MotorA, LOW);
  60. // digitalWrite (win3MotorB, LOW);
  61. digitalWrite (win1Speed, LOW);
  62. digitalWrite (win2Speed, LOW);
  63. // digitalWrite (win3Speed, LOW);
  64. //digitalWrite (inverter, LOW);
  65.  
  66.  
  67. // start serial port
  68. Serial.begin(9600);
  69. // Start up the library
  70. sensors.begin();
  71. // set the resolution to 10 bit (good enough?)
  72. sensors.setResolution(thermometer, 10);
  73.  
  74. }
  75.  
  76. void printTemperature(DeviceAddress deviceAddress)
  77. {
  78. float tempC = sensors.getTempC(deviceAddress);
  79. if (tempC == -40.00) {
  80. Serial.print("Error getting temperature");
  81. } else {
  82. Serial.print("C: ");
  83. Serial.print(tempC);
  84. delay(1000);
  85. }
  86.  
  87.  
  88.  
  89. //Window 1
  90.  
  91. if (tempC >= 15 && X == 0) { // if temp => +15 1. window opens
  92. Serial.println("Temp on +15. Avan akna 1.");
  93. for(i = 0; i < 256; i++)
  94. digitalWrite(inverter, HIGH);
  95. digitalWrite(win1MotorA, HIGH); // motor direction if need other direction change
  96. digitalWrite(win1MotorB, LOW); // motor direction if need other direction change
  97. analogWrite(win1Speed, i); // motor full speed
  98. Serial.print(i);
  99. delay(66000); // time for motor full speed
  100. // analogWrite(win1Speed, 200); // slower speed for opens window
  101. //delay(3000); // time for slow open
  102. analogWrite(win1Speed, 0); // motor stop
  103. digitalWrite(win1MotorA, LOW);
  104. digitalWrite(inverter, LOW);
  105. Serial.println("Aken 1 avatud. ");
  106. delay(1000);
  107. X = 1;
  108. }
  109.  
  110. if (tempC <= 14 && X == 1) { // if temp <= 14 1. window closes
  111.  
  112. X = 0;
  113. Serial.println("Temp on +14. Sulen akna 1.");
  114. digitalWrite(inverter, HIGH);
  115. digitalWrite(win1MotorA, LOW);
  116. digitalWrite(win1MotorB, HIGH);
  117. analogWrite(win1Speed, 255); // motor full speed
  118. delay(66000); // time for motor full speed
  119. //0analogWrite(win1Speed, 200); // slow speed for close
  120. //delay(3000); // time for slow close
  121. analogWrite(win1Speed, 0); // motor stop
  122. digitalWrite(win1MotorB, LOW);
  123. digitalWrite(inverter, LOW);
  124. Serial.println("Aken 1 suletud.");
  125. delay(1000);
  126. }
  127.  
  128. //window 2
  129.  
  130. if (tempC >= 20 && Y == 0) { // if temp => +20 2. window opens
  131. Serial.println("Temp on +20. Avan akna 2.");
  132. digitalWrite(inverter, HIGH);
  133. digitalWrite(win2MotorA, HIGH); // motor direction if need other direction change
  134. digitalWrite(win2MotorB, LOW); // motor direction if need other direction change
  135. analogWrite(win2Speed, 255); // motor full speed
  136. delay(66000); // time for motor full speed
  137. //analogWrite(win2Speed, 200); // slower speed for opens window
  138. //delay(3000); // time for slow open
  139. analogWrite(win2Speed, 0); // motor stop
  140. digitalWrite(win2MotorA, LOW);
  141. digitalWrite(inverter, LOW);
  142. Serial.println("Aken 2 avatud.");
  143. delay(1000);
  144.  
  145. Y = 1;
  146. }
  147.  
  148. if (tempC <= 19 && Y == 1) { // if temp <= 21 2. window closes
  149.  
  150. Y = 0;
  151. Serial.print("Temp on +19. Sulen akna 2.");
  152. digitalWrite(inverter, HIGH);
  153. digitalWrite(win2MotorA, LOW); // motor direction if need other direction change
  154. digitalWrite(win2MotorB, HIGH); // motor direction if need other direction change
  155. analogWrite(win2Speed, 255); // motor full speed
  156. delay(66000); // time for motor full speed
  157. //analogWrite(win2Speed, 200); // slow speed for close
  158. //delay(3000); // time for soft close :-)
  159. analogWrite(win2Speed, 0); // motor stop
  160. digitalWrite(win2MotorB, LOW);
  161. digitalWrite(inverter, LOW);
  162. Serial.println("Aken 2 suletud. ");
  163. delay(1000);
  164. }
  165.  
  166. /* //window 3
  167.  
  168.  
  169. if (tempC >= 25 && Z == 0) { // if temp => +25 3. window opens
  170. digitalWrite(inverter, HIGH);
  171. digitalWrite(win3MotorA, HIGH); // motor direction if need other direction change
  172. digitalWrite(win3MotorB, LOW); // motor direction if need other direction change
  173. analogWrite(win3Speed, 255); // motor full speed
  174. delay(6000); // time for motor full speed
  175. analogWrite(win3Speed, 200); // slower speed for opens window
  176. delay(3000); // time for slow open
  177. analogWrite(win3Speed, 0); // motor stop
  178. digitalWrite(inverter, LOW);
  179. Z = 1;
  180. }
  181.  
  182. if (tempC <= 24 && Z == 1) { // if temp <= 24 3. window closes
  183.  
  184. Z = 0;
  185. digitalWrite(inverter, HIGH);
  186. digitalWrite(win1MotorA, LOW);
  187. digitalWrite(win1MotorB, HIGH);
  188. analogWrite(win1Speed, 255); // motor full speed
  189. delay(6000); // time for motor full speed
  190. analogWrite(win1Speed, 50); // slow speed for close
  191. delay(3000); // time for slow close
  192. analogWrite(win1Speed, 0); // motor stop
  193. digitalWrite(win1MotorB, LOW);
  194. digitalWrite(inverter, LOW);
  195.  
  196. }
  197.  
  198. */
  199.  
  200.  
  201.  
  202.  
  203.  
  204. }
  205.  
  206. void loop(void)
  207.  
  208.  
  209. {
  210. Serial.print("Getting temperatures...\n\r");
  211. sensors.requestTemperatures();
  212. delay(1000);
  213.  
  214. Serial.print("Temperature is: ");
  215. printTemperature(thermometer);
  216. Serial.println("\n\r");
  217. delay(500);
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement