AquaticTechTank.net

A forum dedicated to design and program aquatic tanks
It is currently Sat Nov 18, 2017 11:54 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Thermometer with display
PostPosted: Wed Aug 24, 2016 2:29 pm 
Offline
Site Admin

Joined: Fri Nov 30, 2012 1:54 pm
Posts: 275
So Paronaram made the DIY par meter and he had the circuit board printed. You can only print out in batches so he had a few on his hands. I decided to find different uses for the printed boards.

Image
Image

The thermometer I used is a onewire DS18B20.

https://www.adafruit.com/products/381
https://www.adafruit.com/products/374

Theoretically you can hook up multiple sensors since it's oneWire but you'll have to play with that.
You can also leave out the 15K resistor and POT on the signal line. That's not needed but I had it soldered in already.


Here's the code

Code:
#include <OneWire.h>
#include <LiquidCrystal.h>

//Celsius=(Fahrenheit–32)×5÷9. Fahrenheit=Celsius×9÷5+32

int DS18S20_Pin = A0; //DS18S20 Signal pin

//Temperature chip i/o
OneWire ds(DS18S20_Pin); 

// create the LCD
LiquidCrystal lcd(8, 7, 5, 4, 16, 2);
// set up backlight
int bkl = 6; // backlight pin


void setup(void) {
   lcd.begin(16, 2);
   lcd.begin(16, 2);
    // Print a message to the LCD.
   lcd.print("Thermometer");
   pinMode(bkl, OUTPUT);
   digitalWrite(bkl, HIGH);
}

void loop(void) {
  float temperature = getTemp();
   lcd.setCursor(0, 1);
    // print the number of seconds since reset:
    lcd.print(temperature);
    lcd.print("C   ");
   
    lcd.setCursor(9, 1);
    lcd.print(temperature*1.8+32);
    lcd.print("F   ");
 
  delay(1000); //just here to slow down the output so it is easier to read
 
}


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;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -1000;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      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;
 
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Copyright 2noodles LLC 2012