DS18B20 - temperature sensor code Help Request

Hmm, MarkT,

Maybe, A simpler approach like the code below would help the progress

  1. This displays TEMP0 = ACTUAL TEMP on lcd line 0 and TEMP1 = ACTUAL TEMP on lcd line 1 -- however i see the 2 fields to the right of the temperature filled with weird characters, but the temps are good

  2. When tempsensor1 goes above 25 , i get Alarm1 on the lcd display - good

  3. Led goes on when an alarm on temp1 occurs but it blinks - it needs to be on only....

Any code suggestions , example to clear these issues would be appreciated

Joe

#include <OneWire.h>

#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27  16/2
// LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27  20/


// pin connected to sensor
int tempPin = 2;
// define the onewire obj needed for connecting to onewire components
OneWire oneWire(tempPin);
// define dallas obj, makes it easier to read temp
DallasTemperature tempSens(&oneWire);

DeviceAddress insideThermometer = { 
  0x28, 0x25, 0x33, 0xDC, 0x03, 0x00, 0x00, 0x7E };
DeviceAddress outsideThermometer = { 
  0x28, 0x67, 0x3D, 0xDC, 0x03, 0x00, 0x00, 0xC7 };


void setup() {
  // set up the serial console
  Serial.begin(9600);
  pinMode(7, OUTPUT); //pin selected to control OVER TEMP LED /fan off
  digitalWrite(7, LOW);


  lcd.init(); // initialize the lcd
  lcd.backlight();
  lcd.clear(); // start with a blank screen



  // init the temp sensor
  tempSens.begin();

  // set the resolution to 10 bit 
  tempSens.setResolution(insideThermometer, 10);
  tempSens.setResolution(outsideThermometer, 10);

}

void loop() {
  // get the current temperature
  tempSens.requestTemperatures();

  // get the temperature in centigrade
  // index 0 as multiple temp sensors can be connected on same bus

  float t = tempSens.getTempCByIndex(0); / first sensor 0
  Serial.print("TEMP0 = ");
  Serial.println(t);
  lcd.setCursor(0,0);
  lcd.print("TEMP0 = "); 
  lcd.println(t);  //print sensor0 temperature
  delay(100);

  float t1 = tempSens.getTempCByIndex(1);
  lcd.setCursor(0,1);
  lcd.print("TEMP1 = ");
  lcd.println(t1); // print sensor 1 temperature to lcd
  Serial.print("TEMP1= ");
  Serial.println(t1);
  {
//------------------------------------conditions-----------------------
   
    if  (t1 > 25) // IF TEMP ON SENSOR1 IS GREATER THAN 25  set alarm and turn on led / fan
{
    lcd.setCursor(0,1);
    lcd.print("Alarm1= ");
    lcd.setCursor(0,2);
    lcd.println(t1);
    digitalWrite(7,HIGH);
  }
else 
{
digitalWrite(7,LOW); // KEEP LED / FAN OFF
}

}


}