Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWireTempSensor.h>
- #include <Wire.h>
- #include "RTClib.h"
- #include <OneWire.h>
- #include <LiquidCrystal.h>
- int DS18S20_Pin = 7; //temp
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- RTC_DS1307 RTC; //timer
- OneWire ds(DS18S20_Pin); //temp
- void setup(void) {
- Wire.begin();
- RTC.begin();
- lcd.begin(20, 4);
- lcd.print("Time :");
- pinMode(8, OUTPUT);
- }
- void loop(void) {
- float temperature = getTemp();
- float tempF = (temperature * 9.0)/ 5.0 + 32.0;
- DateTime now = RTC.now();
- lcd.setCursor(7, 0);
- if ( now.hour() < 10) {
- lcd.print("0");
- }
- lcd.print(now.hour(), DEC);
- lcd.print(':');
- if ( now.minute() < 10) {
- lcd.print("0");
- }
- lcd.print(now.minute(), DEC);
- lcd.print(':');
- if ( now.second() < 10) {
- lcd.print("0");
- }
- lcd.print(now.second(), DEC);
- lcd.setCursor(0, 1);
- lcd.print("Temp : ");
- lcd.print(tempF);
- lcd.print(" *F ");
- lcd.setCursor(0, 2);
- lcd.print("Temp : ");
- lcd.print(temperature);
- lcd.print(" *C ");
- if ( tempF < 78) { //This line should turn on pin 8 @78F
- digitalWrite(8, HIGH);
- }
- if ( tempF > 77) { //This line should turn off pin 8 @78F
- digitalWrite(8, LOW);
- }
- }
- float getTemp(){
- //returns the temperature from one DS18S20 in DEG Celsius
- byte data[12];
- byte addr[8];
- if ( !ds.search(addr)) {
- //no more sensors on chain, reset search
- ds.reset_search();
- return -1000;
- }
- ds.reset();
- ds.select(addr);
- ds.write(0x44,1); // start conversion, with parasite power on at the end
- byte present = ds.reset();
- ds.select(addr);
- ds.write(0xBE); // Read Scratchpad
- for (int i = 0; i < 9; i++) { // we need 9 bytes
- data[i] = ds.read();
- }
- ds.reset_search();
- byte MSB = data[1];
- byte LSB = data[0];
- float tempRead = ((MSB << 8) | LSB); //using two's compliment
- float TemperatureSum = tempRead / 16;
- return TemperatureSum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement