Advertisement
Guest User

clock and temp w relay control

a guest
Jul 9th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <OneWireTempSensor.h>
  2. #include <Wire.h>
  3. #include "RTClib.h"
  4. #include <OneWire.h>
  5. #include <LiquidCrystal.h>
  6. int DS18S20_Pin = 7; //temp
  7. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  8.  
  9. RTC_DS1307 RTC; //timer
  10.  
  11.  
  12. OneWire ds(DS18S20_Pin); //temp
  13.  
  14. void setup(void) {
  15. Wire.begin();
  16. RTC.begin();
  17. lcd.begin(20, 4);
  18. lcd.print("Time :");
  19. pinMode(8, OUTPUT);
  20. }
  21.  
  22. void loop(void) {
  23. float temperature = getTemp();
  24. float tempF = (temperature * 9.0)/ 5.0 + 32.0;
  25.  
  26. DateTime now = RTC.now();
  27.  
  28. lcd.setCursor(7, 0);
  29. if ( now.hour() < 10) {
  30. lcd.print("0");
  31. }
  32. lcd.print(now.hour(), DEC);
  33. lcd.print(':');
  34. if ( now.minute() < 10) {
  35. lcd.print("0");
  36. }
  37. lcd.print(now.minute(), DEC);
  38. lcd.print(':');
  39. if ( now.second() < 10) {
  40. lcd.print("0");
  41. }
  42. lcd.print(now.second(), DEC);
  43.  
  44. lcd.setCursor(0, 1);
  45. lcd.print("Temp : ");
  46. lcd.print(tempF);
  47. lcd.print(" *F ");
  48. lcd.setCursor(0, 2);
  49. lcd.print("Temp : ");
  50. lcd.print(temperature);
  51. lcd.print(" *C ");
  52.  
  53. if ( tempF < 78) { //This line should turn on pin 8 @78F
  54. digitalWrite(8, HIGH);
  55. }
  56. if ( tempF > 77) { //This line should turn off pin 8 @78F
  57. digitalWrite(8, LOW);
  58. }
  59. }
  60.  
  61.  
  62. float getTemp(){
  63. //returns the temperature from one DS18S20 in DEG Celsius
  64.  
  65. byte data[12];
  66. byte addr[8];
  67.  
  68. if ( !ds.search(addr)) {
  69. //no more sensors on chain, reset search
  70. ds.reset_search();
  71. return -1000;
  72. }
  73.  
  74.  
  75.  
  76. ds.reset();
  77. ds.select(addr);
  78. ds.write(0x44,1); // start conversion, with parasite power on at the end
  79.  
  80. byte present = ds.reset();
  81. ds.select(addr);
  82. ds.write(0xBE); // Read Scratchpad
  83.  
  84.  
  85. for (int i = 0; i < 9; i++) { // we need 9 bytes
  86. data[i] = ds.read();
  87. }
  88.  
  89. ds.reset_search();
  90.  
  91. byte MSB = data[1];
  92. byte LSB = data[0];
  93.  
  94. float tempRead = ((MSB << 8) | LSB); //using two's compliment
  95. float TemperatureSum = tempRead / 16;
  96.  
  97. return TemperatureSum;
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement