DS18B20 - temperature sensor code Help Request


greetings,

i purchased few temperature sensors - ds18b20.  using uno r3
i found code , modified display alarm , display on lcd.

1. i  have code sensing 2 ds18b20 temp sensors (the temp readings good) , displaying temperature on lcd 16/2.
2. i  have managed  figure out how display on lcd when over-temp occurs , turn on led not working way want to.

problem:

1. code below results in word "alarm" on lcd when on temp occurs on temp led blinks, instead of being on steady during alarm. (it wired relay which  turns on fan, must not blink during alarm period, fan must on continuous cool down over-temp device , preferably stay on @ least minute after temp returns normal)

2. have 2 temp sensors , able to  display sensor has alarm , display on lcd (during alarm period.)

help figuring out code appreciated
thanks
joe
---------------------------------

code: [select]
#include <onewire.h>
#include <dallastemperature.h>
#include <liquidcrystal_i2c.h>
#include <wire.h>

liquidcrystal_i2c lcd(0x27,16,2); // set lcd address 0x27  16/2
// liquidcrystal_i2c lcd(0x27,20,4); // set lcd address 0x27  20/4

// data wire plugged pin 2 on arduino
#define one_wire_bus 2

// setup onewire instance communicate onewire devices
onewire onewire(one_wire_bus);

// pass our onewire reference dallas temperature.
dallastemperature sensors(&onewire);

deviceaddress insidethermometer = {
  0x28, 0x25, 0x33, 0xdc, 0x03, 0x00, 0x00, 0x7e };
deviceaddress outsidethermometer = {
  0x28, 0x67, 0x3d, 0xdc, 0x03, 0x00, 0x00, 0xc7 };


void setup(void)
{
  pinmode(7, output); //pin selected control on temp led / fan

  // start library
  sensors.begin();
  // set resolution 10 bit (good enough?)
  sensors.setresolution(insidethermometer, 10);
  sensors.setresolution(outsidethermometer, 10);

  // alarm when temp higher 28c
  sensors.sethighalarmtemp(insidethermometer, 28);

  // alarm when temp lower -10c
  sensors.setlowalarmtemp(insidethermometer, -10);

  // alarm when temp higher 26c
  sensors.sethighalarmtemp(outsidethermometer, 26);

  // alarm when temp lower 15c
  sensors.setlowalarmtemp(outsidethermometer, 15);

  lcd.init(); // initialize lcd
  lcd.backlight();
  lcd.clear(); // start blank screen
}

void printtemperature(deviceaddress deviceaddress) // display error if device not found
{
  float tempc = sensors.gettempc(deviceaddress);
  if (tempc == -127.00) {
    lcd.print("error");
  }
  else
  {
    lcd.print(tempc);
    lcd.print("/");
    lcd.print(dallastemperature::tofahrenheit(tempc));
  }
}

void loop()
{
  delay(200);
  sensors.requesttemperatures();
  if (sensors.hasalarm()) // check see if there alarm
  {
    lcd.setcursor(0,0);
    lcd.print(" hightemp alarm");
    digitalwrite(7, high); // turn on over-temp light
  }
  // call alarm handler function defined sensors.setalarmhandler
  // each device reporting alarm
  sensors.processalarms();

  if (!sensors.hasalarm())
  {
    // if no alarm print out current temperature
    //  printtemperature(insidethermometer);
    //  printtemperature(outsidethermometer);

    lcd.setcursor(0,0);
    lcd.print("in: ");
    printtemperature(insidethermometer);
    lcd.setcursor(0,1);
    lcd.print("out: ");
    printtemperature(outsidethermometer);
    digitalwrite(7, low);// overtemp light off
  }


}



code: [select]
 float tempc = sensors.gettempc(deviceaddress);
 if (tempc == -127.00) {
   lcd.print("error");
 }

so, -126.999 , -127.001 ok, -127.000 problem. got it.

you unconditionally calling sensors.processalarms(). why that? you've checked whether there have alarm condition, so, shouldn't called if test true?

personally, don't think i'd using sethighalarmtemp(), setlowalarmtemp(), hasalarms(), or processalarms() methods. temperature. test yourself. doing allows control on when pin turned on, , when turned off. perhaps want fan come on @ 28, not go off until gets 26.

frankly, don't see define sensors instance when alarm condition present.


Arduino Forum > Using Arduino > Programming Questions > DS18B20 - temperature sensor code Help Request


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial