Using 2 temperature sensors

I would like to display the temp of two DS18B20 temp sensors on an i2c LCD
I know that each sensor has its own address and can have more that 1 sensor on one arduino pin
I found this sketch but I cant figure out how the sketch uses the sensors without there address

//I2C bus support
#include <Wire.h>
//I2C 
#include <LiquidCrystal_I2C.h>
//OneWire bus suport
#include <OneWire.h>
//DS18B20 temperature sensor support
#include <DallasTemperature.h>
//DS18B20 sensor pin
#define ONE_WIRE_BUS 8

// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  lcd.init();
  lcd.backlight(); //Turns backlight on
  sensors.begin();
}

void loop()
{  
  sensors.requestTemperatures();
  
  //Read first sensor
  float temp = sensors.getTempCByIndex(0);
  
  //Print first sensor results
  lcd.setCursor (0, 0 );
  lcd.print("T1: ");
  lcd.print(temp);
  lcd.print("      ");

  //Read second sensor  
  temp = sensors.getTempCByIndex(1);
  
  //Print second sensor result
  lcd.setCursor (0, 1 );
  lcd.print("T2: ");  
  lcd.print(temp);
  lcd.print("      ");
  
  //Wait 0.1 sec
  delay(100);  
}

Hi,

Example and code for multiple DS18B20 to LCD here:

http://arduino-info.wikispaces.com/MultipleTemperatureSensorsToLCD

Thanks
If Im going to have 2 temp sensors one about 100ft and the other about 50ft is it better to have them on different pins
Also the temp is a little off is there any way in the sketch to for example -.5c

You have a one wire bus, I don't know why you would need separate pins (buses).

  float temp50 = sensors.getTempCByIndex(0);  // give temp a better and unique name
  temp50 = temp50 - 0.5;   // or temp50 -= 0.5
  //Print first sensor results
  lcd.setCursor (0, 0 );
  lcd.print("T1: ");
  lcd.print(temp50);
  lcd.print("      ");
 
  //Read second sensor 
  float temp100 = sensors.getTempCByIndex(1);  // give temp a better and unique name
  temp100 = temp100 - 0.5; 
  //Print second sensor result
  lcd.setCursor (0, 1 );
  lcd.print("T2: "); 
  lcd.print(temp100);
  lcd.print("      ");

Better would be to have a constant (OFFSET, maybe) defined to replace the magic number "0.5".

1. Each and every DS18B20 sensor has its own unique 64-bit (8-byte) ROM Code which is composed of: 8-bit CRC, 48-bit Serial Number, and 8-bit Family Code.

2. When we include OneWire.h library file in the sketch, the following commands are availabe:
(1) OneWire ds(DPin); //Dpin is the digital pin of UNO that connects sensors’ signal

(2) ds.reset(); //to reset the internal logic circuitry of the sensor

(3) ds.search(dsAddrs1); //Searches all the sensors one-by-one for ROM Code and saves in an 8-byte wide array named byte dsAddrs1[8];.

(4) ds.select(dsAddrs1); //selects DS18B20-1 with address – dsAddrs1 for data acquisition.

(5) ds.write(0x44); //temp conversion command and wait for max 1-sec conversion time
delay(1000);

(6) ds.write(0xBE); //command to transfer data from EEPROM into scratchpad memory

(7) ds.read(); //repeated read() commands to bring data from scratchpad memory into array-buffer

for(int i=0; i<9; i++)
{
   ds1Data[i] = ds.read();
}

3. Upper two byte (byte-0 and Byte-1) of the scratchpad memory contains the temperature data. Lower 4-bit of Byte-0 contains the fractional part; Bit-7 to Bit-3 of Byte-1 are the copies of the sign bit; the remaining bits of Byte-1 and Byte-0 are for the integer part of the temperature.

4. Compute decimal value of Temperature and show on Serial Monitor/ LCD

unsigned int rawTemp = (ds1Data[1]<<8)|ds1Data[0];
float tempC =(float)rawTemp/16.0;
Serial.print(tempC, 2);

OR

int rawTemp = (ds1Data[1]<<8) | ds1Data[0];
rawTemp = rawTemp>>4;
float upTemp =(float)rawTemp;

byte x = ds1Data[0];
x = x & 0x0F;
float dnTemp = (float)bitRead(x, 3)*0.5+bitRead(x, 2)*0.25+bitRead(x, 1)*0.125+bitRead(x, 0)*0.0625;
float tempC = upTemp + dnTemp;
Serial.print(tempC, 2);

BTW: When DallasTemperature.h is included in the sketch, many things go into hiding like sensor address; but, the address comes indirectly under the disguise of Index(x).

Thanks for that explanation that was good
Can I assume that no matter how many times the arduino is rebooted it will always display the temp of the sensors in the same order

I have a motion sensor connected to pin A1. How do I go about turning the backlight on for 30 seconds when pin A1 goes high (from the motion sensor)
I know the commands are noBacklight() and backlight()

OK I initialized pin A0 then read the value. When I add 3v the value jumps to 702
Im not sure how to use that to turn on and off the backlight

//I2C bus support
#include <Wire.h>
//I2C
#include <LiquidCrystal_I2C.h>
//OneWire bus suport
#include <OneWire.h>
//DS18B20 temperature sensor support
#include <DallasTemperature.h>
//DS18B20 sensor pin
#define ONE_WIRE_BUS 8

// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

LiquidCrystal_I2C lcd(0x3f, 16, 2); // set the LCD address for the LCD display
int analogPin = A0;  
int val = 0;  
void setup()
{
  lcd.init();
  lcd.backlight(); //Turns backlight on
  sensors.begin();
  Serial.begin(9600);              //  setup serial
}

void loop()
{  
   val = analogRead(analogPin);     
  Serial.println(val);             
  sensors.requestTemperatures();

  //Temperature Sensor #1
  float temp = sensors.getTempCByIndex(0);

  //Print first sensor results
  float temp50 = sensors.getTempCByIndex(0);  // give temp a better and unique name
  temp50 = temp50 + .4;   // If Temp is out you can add or subtract here
  //Print first sensor results
  lcd.setCursor (0, 0 );
  lcd.print("OutsideTemp ");
  lcd.print(temp50);


  //Read second sensor
  temp = sensors.getTempCByIndex(1);

  //Temperature Sensor #2
  float temp100 = sensors.getTempCByIndex(1);  // give temp a better and unique name
  temp100 = temp100 + .4;   // If Temp is out you can add or subtract here
  //Print second sensor result
  lcd.setCursor (0, 1 );

  lcd.print("Pool Temp   ");
  lcd.print(temp100);

  //Wait 0.1 sec
  delay(100);
}

Patty0465:
I have a motion sensor connected to pin A1.

What motion sensor.
A PIR sensor has a digital output, so read it with a digital pin.

'ON' time can be set with the 'time' pot on the PIR, or in code.
Leo..

OK I have declared pin 24 as digital input, int val = 0, int pirState = LOW
Now under void loop if val = HIGH
Im not sure how to turn on the backlight (lcd.backlight()) then off after 30 sec

//DS18B20 sensor pin
#define ONE_WIRE_BUS 8

// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
int inputPin = 24;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
LiquidCrystal_I2C lcd(0x3f, 16, 2); // set the LCD address for the LCD display

void setup()
{
  pinMode(inputPin, INPUT);     // declare sensor as input
  lcd.init();
  lcd.backlight(); //Turns backlight on
  sensors.begin();
}

void loop()
{ 
   val = digitalRead(inputPin);  // read input value 
   if (val == HIGH)            // check if the input is HIGH
  sensors.requestTemperatures();

  //Temperature Sensor #1
  float temp = sensors.getTempCByIndex(0);

  //Print first sensor results
  float temp50 = sensors.getTempCByIndex(0);  // give temp a better and unique name
  temp50 = temp50 + .4;   // If Temp is out you can add or subtract here
  //Print first sensor results
  lcd.setCursor (0, 0 );
  lcd.print("OutsideTemp ");
  lcd.print(temp50);


  //Read second sensor
  temp = sensors.getTempCByIndex(1);

  //Temperature Sensor #2
  float temp100 = sensors.getTempCByIndex(1);  // give temp a better and unique name
  temp100 = temp100 + .4;   // If Temp is out you can add or subtract here
  //Print second sensor result
  lcd.setCursor (0, 1 );

  lcd.print("Pool Temp   ");
  lcd.print(temp100);

  //Wait 0.1 sec
  delay(100);
}

what is the trigger that would turn the back-light on ?

whatever that is, just start a timer so that 30 seconds later, the light goes off.

does your sketch compile ?

============
if I see 'val' as a digital input,
this is how it might be, (not written as working code.)
not sure how you are turning your back-light off and on, is ON a 1 or a 0 ?

if val == high
digitalWrite (backlight, ON); // change ON to a 1 or a 0 as needed.
if backlightFLAG == 0 // cannot repeat until the light goes off
if backlight == ON
backlightFLAG = 1
timeTHEN = milis() // loads the time once

since you have your timeTHEN set for some point in time.

elapsed = millis() - timeTHEN // this is the counter

if elapsed >= 30000 // 30 seconds,
digitalWrite (backlight, OFF) // change OFF to a 0 or 1 as needed
backlightFLAG= 0 // this resets so that it can turn on at some future time.