Advertisement
Guest User

TemperatureSwith.h

a guest
Jun 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. // Tempaerature switch is used to switch relay ON/OFF according to room's temperature
  2. // BOM:
  3. //      - Arduino Micro - RobotDyn - https://www.aliexpress.com/item/Micro-ATmega32U4-5V-16MHz-Pins-soldered-Compatible-with-Arduino-Micro-and-Leonardo/32676998690.html?spm=2114.13010608.0.0.dKi9ne
  4. //        $ 4.39
  5. //      - Button - RobotDyn - https://www.aliexpress.com/item/Button-Switch-module-WHITE/32628948023.html?spm=2114.13010608.0.0.aM9oQE
  6. //        -- Interrupt pin 9
  7. //        $ 0.75
  8. //      - 2 Channel 5V Relay - RobotDyn https://www.aliexpress.com/item/Relay-Module-2-relays-5V/32530849971.html?spm=2114.13010608.0.0.dKi9ne
  9. //        -- Pins 4, 5
  10. //        $ 1.09
  11. //      - Temperature and Humidity sensor SHT1x - RobotDyn - https://www.aliexpress.com/item/Temperature-and-Humidity-sensor-SHT1x/32569601511.html?spm=2114.13010608.0.0.FQUvCk
  12. //        -- Pins Data 6, SCK 7
  13. //        $ 5.8
  14. //      - RTC DS1307 - RobotDyn - https://www.aliexpress.com/item/RTC-Real-Time-Clock-DS1307-module-with-battery/32530897478.html?spm=2114.13010608.0.0.pEu9M6
  15. //        -- I2C
  16. //        $ 1.25
  17. //      - Krabice na omítku KLIK 130
  18. //        CZK 42,-
  19. //      - Dupont lines
  20.  
  21. //include guard
  22. #ifndef _TemperatureSwitch_h_
  23. #define _TemperatureSwitch_h_
  24.  
  25. // Include libraries
  26. #include "Arduino.h"
  27. #include "Board.h"
  28. #include "Wire.h"
  29. #include "p.h"
  30. #include "SHT1x.h"
  31. #include "RtcDS1307.h"
  32.  
  33. bool debug = false;
  34.  
  35. // Typing
  36. typedef struct strucTime {
  37.   uint8_t hour = 0;
  38.   uint8_t minute = 0;
  39.   uint8_t second = 0;
  40. } strucTime;
  41.  
  42. // Relay Pins
  43. //p relayPin1(4);
  44. //p relayPin2(5);
  45. p relayPin1(4);
  46. p relayPin2(5);
  47.  
  48. // Button pint
  49. int buttonPin = 20;
  50. int buttonInterruptPin = 2;
  51.  
  52. // Standard led PIN
  53. p ledPin(13);
  54.  
  55. // RTC
  56. RtcDS1307<TwoWire> Rtc(Wire);
  57.  
  58. // SHT sensor
  59. int dataPin = 6;
  60. int clockPin = 7;
  61. SHT1x temperatureSensor(dataPin, clockPin);
  62.  
  63. // Control variables
  64. float lowTemperature = 18; //TODO: Change
  65. float highTemperature = 21; //TODO: Change
  66. int minutesToRun = 10; //TODO: Change
  67. int stopMinute = -1;
  68. int startHour = 22;
  69. int endHour = 8;
  70. strucTime actualTime;
  71. strucTime buttonTime;
  72. strucTime temperatureTime;
  73. strucTime waitTime;
  74. bool buttonPressed = false;
  75. bool getTime = false;
  76. bool waitingTime = false;
  77.  
  78. //float actualTemperature = 20;
  79. //bool step=false;
  80. //unsigned long startMillis=-1;
  81.  
  82. void checkTemperature();
  83. void getDateTime();
  84.  
  85. bool highTempeartureReached(float temperature);
  86. bool lowTemperatureReached(float temperature);
  87.  
  88. void setupPins();
  89. void setupRTC();
  90. void handleButtonPressed();
  91.  
  92. void setup();
  93. void loop();
  94. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement