// This is for arduino pro mini. if you use other arduino, check pwm pin numbers //Temperature sensor DS18B20. I put it inside greenhouse shady place #include #include #define win1MotorA 4 #define win1MotorB 5 #define win1Speed 6 //has to be PWM pin #define win2MotorA 7 #define win2MotorB 8 #define win2Speed 9 //has to be PWM pin #define win3Speed 10 //has to be PWM pin #define win3MotorA 11 #define win3MotorB 12 // Data wire is plugged into pin 3 on the Arduino #define ONE_WIRE_BUS 3 // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // Assign the addresses of your 1-Wire temp sensors. // See the tutorial on how to obtain these addresses: // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html DeviceAddress thermometer = { 0x28, 0xC8, 0xDC, 0x51, 0x07, 0x00, 0x00, 0x72 }; int X = 0; int Y = 0; int Z = 0; void setup(void) { pinMode (win1MotorA, OUTPUT); pinMode (win1MotorB, OUTPUT); pinMode (win2MotorA, OUTPUT); pinMode (win2MotorB, OUTPUT); pinMode (win3MotorA, OUTPUT); pinMode (win3MotorB, OUTPUT); pinMode (win1Speed, OUTPUT); pinMode (win2Speed, OUTPUT); pinMode (win3Speed, OUTPUT); digitalWrite (win1MotorA, LOW); digitalWrite (win1MotorB, LOW); digitalWrite (win2MotorA, LOW); digitalWrite (win2MotorB, LOW); digitalWrite (win3MotorA, LOW); digitalWrite (win3MotorB, LOW); digitalWrite (win1Speed, LOW); digitalWrite (win2Speed, LOW); digitalWrite (win3Speed, LOW); // start serial port Serial.begin(9600); // Start up the library sensors.begin(); // set the resolution to 10 bit (good enough?) sensors.setResolution(thermometer, 10); } void printTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); if (tempC == -40.00) { Serial.print("Error getting temperature"); } else { Serial.print("C: "); Serial.print(tempC); } //Window 1 if (tempC >= 15 && X == 0) { // if temp => +15 1. window opens digitalWrite(win1MotorA, HIGH); // motor direction if need other direction change digitalWrite(win1MotorB, LOW); // motor direction if need other direction change analogWrite(win1Speed, 255); // motor full speed delay(6000); // time for motor full speed analogWrite(win1Speed, 200); // slower speed for opens window delay(3000); // time for slow open analogWrite(win1Speed, 0); // motor stop digitalWrite(win1MotorA, LOW); X = 1; } if (tempC <= 14 && X == 1) { // if temp <= 14 1. window closes X = 0; digitalWrite(win1MotorA, LOW); digitalWrite(win1MotorB, HIGH); analogWrite(win1Speed, 255); // motor full speed delay(6000); // time for motor full speed analogWrite(win1Speed, 200); // slow speed for close delay(3000); // time for slow close analogWrite(win1Speed, 0); // motor stop digitalWrite(win1MotorB, LOW); } //window 2 if (tempC >= 20 && Y == 0) { // if temp => +20 2. window opens digitalWrite(win2MotorA, HIGH); // motor direction if need other direction change digitalWrite(win2MotorB, LOW); // motor direction if need other direction change analogWrite(win2Speed, 255); // motor full speed delay(6000); // time for motor full speed analogWrite(win2Speed, 200); // slower speed for opens window delay(3000); // time for slow open analogWrite(win2Speed, 0); // motor stop digitalWrite(win2MotorA, LOW); Y = 1; } if (tempC <= 19 && Y == 1) { // if temp <= 21 2. window closes Y = 0; digitalWrite(win2MotorA, LOW); // motor direction if need other direction change digitalWrite(win2MotorB, HIGH); // motor direction if need other direction change analogWrite(win2Speed, 255); // motor full speed delay(6000); // time for motor full speed analogWrite(win2Speed, 50); // slow speed for close delay(3000); // time for soft close :-) analogWrite(win2Speed, 0); // motor stop digitalWrite(win2MotorB, LOW); } //window 3 if (tempC >= 25 && Z == 0) { // if temp => +25 3. window opens digitalWrite(win3MotorA, HIGH); // motor direction if need other direction change digitalWrite(win3MotorB, LOW); // motor direction if need other direction change analogWrite(win3Speed, 255); // motor full speed delay(6000); // time for motor full speed analogWrite(win3Speed, 200); // slower speed for opens window delay(3000); // time for slow open analogWrite(win3Speed, 0); // motor stop Z = 1; } if (tempC <= 24 && Z == 1) { // if temp <= 24 3. window closes Z = 0; digitalWrite(win1MotorA, LOW); digitalWrite(win1MotorB, HIGH); analogWrite(win1Speed, 255); // motor full speed delay(6000); // time for motor full speed analogWrite(win1Speed, 50); // slow speed for close delay(3000); // time for slow close analogWrite(win1Speed, 0); // motor stop digitalWrite(win1MotorB, LOW); } } void loop(void) { Serial.print("Getting temperatures...\n\r"); sensors.requestTemperatures(); Serial.print("Temperature is: "); printTemperature(thermometer); Serial.print("\n\r"); }