Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define win1MotorA 4
- #define win1MotorB 5
- #define win1Speed 6
- #define win2MotorA 7
- #define win2MotorB 8
- #define win2Speed 9
- #define win3Speed 10
- #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, 0x2B, 0xE6, 0xDA, 0x02, 0x00, 0x00, 0x43 };
- int X = 0;
- int Y = 0;
- int Z = 0;
- int speed = 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 printlnTemperature(DeviceAddress deviceAddress)
- {
- float tempC = sensors.getTempC(deviceAddress);
- if (tempC == -127.00) {
- Serial.println("Error getting temperature");
- } else {
- Serial.println("C: ");
- Serial.println(tempC);
- }
- //Window 1
- if (tempC >= 16 && X == 0) { // if temp => +16 1. window opens
- Serial.println("Temp is +16C. Open window 1.");
- 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); // motor 1 pin A LOW, full stop
- Serial.println("Window 1 is open.");
- X = 1;
- }
- if (tempC <= 15 && X == 1) { // if temp <= 15 1. window closes
- Serial.println("Temp is +15C. Close window 1.");
- X = 0;
- digitalWrite(win1MotorA, LOW);
- digitalWrite(win1MotorB, HIGH);
- analogWrite(win1Speed, 255); // motor full speed
- delay(6000); // time for motor full speed
- analogWrite(win1Speed, 150); // slow speed for close
- delay(3000); // time for slow close
- analogWrite(win1Speed, 0); // motor stop
- digitalWrite(win1MotorB, LOW); // motor 1 pin B LOW, full stop
- Serial.println("Window 1 is closed.");
- }
- //window 2
- if (tempC >= 23 && Y == 0) { // if temp => +23 window 2 opens
- Serial.println("Temp is +23C. Open window 2.");
- 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); // motor 2 pin A LOW, full stop
- Serial.println("Window 2 is open.");
- Y = 1;
- }
- if (tempC <= 21 && Y == 1) { // if temp <= 21 2. window closes
- Serial.println("Temp is +21C. Close window 2.");
- 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, 150); // slow speed for close
- delay(3000); // time for soft close :-)
- analogWrite(win2Speed, 0); // motor stop
- digitalWrite(win1MotorB, LOW); // motor 2 pin B LOW, full stop
- Serial.println("Window 2 is closed.");
- }
- /*
- //window 3
- if (tempC >= 25 && Z == 0) { // if temp => +25 3. window opens
- Serial.println("Temp is +25C. Open window 3.");
- 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
- digitalWrite(win1MotorA, LOW); // motor 3 pin A LOW, full stop
- Serial.println("Window 3 is open.");
- Z = 1;
- }
- if (tempC <= 24 && Z == 1) { // if temp <= 24 3. window closes
- Serial.println("Temp is lower than +24C. Closing window 3");
- Z = 0;
- digitalWrite(win1MotorA, LOW);
- digitalWrite(win1MotorB, HIGH);
- analogWrite(win1Speed, 255); // motor full speed
- delay(6000); // time for motor full speed
- analogWrite(win1Speed, 150); // slow speed for close
- delay(3000); // time for slow close
- analogWrite(win1Speed, 0); // motor stop
- digitalWrite(win1MotorB, LOW); // motor 3 pin A LOW, full stop
- Serial.println("Window 3 is closed.");
- }
- */
- }
- void loop(void)
- {
- Serial.print("Getting temperatures...\n\r");
- sensors.requestTemperatures();
- Serial.print("Temperature is: ");
- printlnTemperature(thermometer);
- Serial.print("\n\r");
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement