Advertisement
seston

kavuhoone aknad ja uks 31.05.2017

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