DS18B20 commands thermostat

Hi

I am new to Arduino and I am trying to make a thermostat but I can`t seem to get the right command to the temperature, cahelp me/tell me what iam doing wrong?
Iam using:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#define DS18B20 8

and the part i am having problems whit are:

void loop()
{

sensor.requestTemperatures();
Serial.print(sensor.getTempCByIndex(0));
Serial.println("°C");
lcd.setCursor(7,0);
lcd.print(sensor.getTempCByIndex(0));
lcd.write(1);
lcd.print("C");
delay(1000);

; if( ("float") <= 29 ){
Serial.println(", Yellow LED is Activated");
digitalWrite(yellowLedPin, HIGH); }
else if(("Temperature") >= 30, degree_symbol ){
Serial.println(", Green LED is Activated");
digitalWrite(yellowLedPin, LOW);
}
}

Were it says float, what is the right comand fore the temperature ??

Regards
Kim

First read ow to use this forum - please read, specifically point 7.

Not familiar with the DS18B20, but looking at the code getTempCByIndex seems to return a value.

 Serial.print(sensor.getTempCByIndex(0));

No idea if that is a float or an int or ..., but you can store that value in a variable of the correct type. And you can use that variable in your if statement.

Please post the complete program using </> code tags as shown in "How to use this forum - please read" at the top of every forum.

From what I see so far those if statements make no sense. Why are you comparing strings to numbers? And what is the ", degree_symbol" supposed to do?

Steve

If you went through the dictionary and put a number next to every word, I'm certain that "float" would not be number 29.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#define DS18B20 8


int yellowLedPin = 13;


OneWire ourWire(DS18B20);
DallasTemperature sensor(&ourWire);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
byte degree_symbol[8] = 
              {
                0b00111,
                0b00101,
                0b00111,
                0b00000,
                0b00000,
                0b00000,
                0b00000,
                0b00000
              };
void setup()
{
   Serial.begin(9600); 

    //Setup the LEDs to act as outputs
  

  pinMode(yellowLedPin,OUTPUT);

  
   delay(1000);
   sensor.begin();
   lcd.begin(16, 2);
   lcd.createChar(1, degree_symbol);
   lcd.setCursor(0,0);
   lcd.print("    Espens    ");
   lcd.setCursor(0,1);
   lcd.print("  Destilering   ");
   delay(4000);
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("Temp ");
}

void loop()
{

  
   sensor.requestTemperatures();
   Serial.print(sensor.getTempCByIndex(0));
   Serial.println("°C");
   lcd.setCursor(7,0);
   lcd.print(sensor.getTempCByIndex(0));
    lcd.write(1);
    lcd.print("C");
   delay(1000);

 
;   if( ("float")   <= 29  ){ 
    Serial.println(", Yellow LED is Activated"); 
    digitalWrite(yellowLedPin, HIGH); } 
else if(("Temperature") >= 30, degree_symbol  ){  
    digitalWrite(yellowLedPin, LOW);
}
}

Sorry about that guys, I am new to this forum.
The point about this code is to trigger the yellow led (pin13) when the thermostat is lower than 29 celsius, and to shut it of when it is over 30 celsius.

thank you guys fore taking the time :slight_smile:

  • Kim Kjellemyr

But you're still checking the word "float" to see if it is less than 29.

Is the temperature that is printed to the lcd and in the Serial monitor correct? If it is then you want to use the same value in your if statements. Something like "if (sensor.getTempCByIndex(0) <= 29)".

Or even better save the value in a variable like currentTemp = sensor.getTempCByIndex(0) and then use currentTemp in all your prints and ifs.

Steve

Thanks Steve

It worked with:

;   if( (sensor.getTempCByIndex(0) )  <= 29  ){ 
    Serial.println(", Yellow LED is Activated"); 
    digitalWrite(yellowLedPin, HIGH); } 
else if( (sensor.getTempCByIndex(0) )  >= 30, degree_symbol  ){  
    digitalWrite(yellowLedPin, LOW);
}

Thanks so much fore all the help guys :slight_smile:

if( (sensor.getTempCByIndex(0) )  >= 30, degree_symbol  ){

What is that?

if( (sensor.getTempCByIndex(0) )  >= 30, degree_symbol  ){

If the thermostat sensor value is below or 30 degree celsius

I can just about guarantee that you don’t want to use the Comma Operator there.