Temperature Sensor

Hi everyone
i have a question about temperature sensor
I want to test if the temperature is higher than 30 degrees(C).The led will light.
this is my code

#include <OneWire.h>
#include <DallasTemperature.h>
#include <NewSoftSerial.h>
NewSoftSerial xbee(2,3);
int ledPin = 13;
#define ONE_WIRE_BUS 9

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup()
{
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
xbee.begin(9600);
Serial.println(“Temperature Sensor”);
sensors.begin();
}

void loop()
{
sensors.requestTemperatures();
Serial.println(sensors.getTempCByIndex(0));
if(Serial.println(sensors.getTempCByIndex(0))>30){
digitalWrite(ledPin,HIGH);
delay(1000);
return;
}
}

i had a trouble at
if(Serial.println(sensors.getTempCByIndex(0))>30){

Has someone know is my code error or has other method to display
please help me :cold_sweat:

other method

The code below compiles. All I have added to a standard test is the

int ledPin = 13;

and the “if” section. You don’t define the resolution. It may default.

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };
int ledPin = 13;
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 10);
}

void loop(void)
{ 
  delay(2000);
  sensors.requestTemperatures();
  
  Serial.print("Inside temperature is: ");
  printTemperature(insideThermometer);
  }

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
     Serial.println(tempC);
     if (tempC>30.00)
     {
       digitalWrite(ledPin,HIGH);
       delay(1000);
     }
  }

Thanks for your help.But the result has an error.
in the monitor
it will continue to display "Inside temperature is:-127"
how to solve the question :~

I think 127 suggests improper or non-existent connection