Advertisement
seston

greenhouse windows 3 v.0.5

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