LCD & Temp sensor DS18B20

The LCD and Keypad Shield gives you a handy 16-character by 2-line display, 5 buttons and a controllable backlight.
Post Reply
vero96
Posts: 25
Joined: Sat Jun 01, 2013 10:08 pm

LCD & Temp sensor DS18B20

Post by vero96 » Fri Jan 03, 2014 1:37 pm

//had this bunch of parts lying around and it had been forecast to be very hot over the following //few day's. Here is a bit of code, mostly borrowed that worked for me. LCD and DS18B20 //temp sensor.

Code: Select all

 #include <LiquidCrystal.h>

LiquidCrystal lcd(8,9,4,5,6,7);

#define REF_PIN 2
void getCurrentTemp( int *sign, int *whole, int *fract);
char temp_string[10];

void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.clear();
  pinMode(13 , INPUT);

  Serial.begin(38400);
  // initialize DS18B20 datapin
  digitalWrite(REF_PIN, LOW);
  pinMode(REF_PIN, INPUT);      // sets the digital pin as input (logic 1)
  pinMode(15, INPUT);
}

void loop(){
  getCurrentTemp(temp_string);
  Serial.println(temp_string);
  delay(1000);
    Serial.print("Degree C ");
  //Serial.print("Inches: ");
  Serial.println();
  //Serial.println(inches);
  
  lcd.setCursor(0,0);
  lcd.print(temp_string);
  lcd.print(" Degree C");
  
  
}

void OneWireReset (int Pin) // reset.  Should improve to act as a presence pulse
{
  digitalWrite (Pin, LOW);
  pinMode (Pin, OUTPUT);        // bring low for 500 us
  delayMicroseconds (500);
  pinMode (Pin, INPUT);
  delayMicroseconds (500);
}

void OneWireOutByte (int Pin, byte d) // output byte d (least sig bit first).
{
  byte n;

  for (n=8; n!=0; n--)
  {
    if ((d & 0x01) == 1)  // test least sig bit
    {
      digitalWrite (Pin, LOW);
      pinMode (Pin, OUTPUT);
      delayMicroseconds (5);
      pinMode (Pin, INPUT);
      delayMicroseconds (60);
    }
    else
    {
      digitalWrite (Pin, LOW);
      pinMode (Pin, OUTPUT);
      delayMicroseconds (60);
      pinMode (Pin, INPUT);
    }

    d = d>>1; // now the next bit is in the least sig bit position.
  }
}


byte OneWireInByte (int Pin) // read byte, least sig byte first
{
  byte d, n, b;

  for (n=0; n<8; n++)
  {
    digitalWrite (Pin, LOW);
    pinMode (Pin, OUTPUT);
    delayMicroseconds (5);
    pinMode (Pin, INPUT);
    delayMicroseconds (5);
    b = digitalRead (Pin);
    delayMicroseconds (50);
    d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position
  }
  return (d);
}


void getCurrentTemp (char *temp)
{
  int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;

  OneWireReset (REF_PIN);
  OneWireOutByte (REF_PIN, 0xcc);
  OneWireOutByte (REF_PIN, 0x44); // perform temperature conversion, strong pullup for one sec

  OneWireReset (REF_PIN);
  OneWireOutByte (REF_PIN, 0xcc);
  OneWireOutByte (REF_PIN, 0xbe);

  LowByte = OneWireInByte (REF_PIN);
  HighByte = OneWireInByte (REF_PIN);
  TReading = (HighByte << 8) + LowByte;
  sign = TReading & 0x8000;  // test most sig bit
  if (sign) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25

  whole = Tc_100 / 100;  // separate off the whole and fractional portions
  fract = Tc_100 % 100;

  if (sign) {
    temp[0] = '-';
  } else {
    temp[0] = '+';
  }

  if (whole/100 == 0) {
    temp[1] = ' ';
  } else {
    temp[1] = whole/100+'0';
  }

  temp[2] = (whole-(whole/100)*100)/10 +'0' ;
  temp[3] = whole-(whole/10)*10 +'0';
  temp[4] = '.';
  temp[5] = fract/10 +'0';
  temp[6] = fract-(fract/10)*10 +'0';
  temp[7] = '\0';
}  

//cheers, vero

Himanshu123
Posts: 5
Joined: Fri Dec 01, 2017 5:29 am

oiuytrewq

Post by Himanshu123 » Fri Dec 01, 2017 5:37 am

Hey guys if you are getting bored of your free time then visit here oiuytrewq our homepage it is really an awesome fun and game zone here you will play many free online trending games and video here on just single click it is really an awesome and fantastic video game.

xiaozheng6666
Posts: 150
Joined: Wed Jan 17, 2018 2:00 am

xiaozheng6666

Post by xiaozheng6666 » Wed Jan 17, 2018 7:43 am

2018-1-17 xiaozheng6666
ray ban pas cher
michael kors outlet
ray ban
canada goose outlet store
canada goose outlet store
adidas superstar
coach outlet
pandora bracelet
michael kors outlet
giuseppe zanotti shoes
nfl jerseys wholesale
valentino shoes
nike shoes for men
cheap jordans for sale
oakley sunglasses
michael kors outlet
pandora charms
michael kors outlet online
nike air max 90
coach outlet
christian louboutin shoes
canada goose
pandora outlet
nike outlet store
michael kors outlet
polo ralph lauren
canada goose outlet
mcm backpack
ray ban sunglasses outlet
nike air max
uggs outlet
cheap jordans
pandora outlet
coach outlet online
canada goose outlet online
fred perry shirts
ray ban sunglasses
ralph lauren polo
michael kors outlet clearance
michael kors outlet online
ugg boots
cheap oakley sunglasses
cheap oakley sunglasses
ugg outlet
longchamp outlet
adidas outlet
ugg outlet
ugg outlet
moncler coats
pandora charms
cheap ugg boots
canada goose outlet
michael kors outlet
michael kors outlet
canada goose jackets canada
canada goose jackets
canada goose
ugg outlet
coach outlet
coach outlet online
pandora outlet
kate spade purses
coach factory outlet
coach outlet
christian louboutin sale
oakley sunglasses
fitflop sandals
ralph lauren
mulberry handbags
polo outlet
coach factory outlet
michael kors outlet stores
canada goose uk
cheap oakley sunglasses
uggs outlet
coach factory outlet
polo outlet
michael kors outlet
michael kors outlet online
oakley sunglasses wholesale
michael kors outlet store
michael kors outlet
ugg outlet store
coach outlet online
adidas nmd
nike outlet store
oakley sunglasses outlet
ugg outlet
nike air max
canada goose uk
polo ralph lauren
canada goose
coach outlet store
ultra boosts
ralph lauren outlet
canada goose outlet online
moncler jackets
polo ralph lauren
puma shoes
polo shirts

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests