DS18B20 turn off/on Fan

I'm doing a project which I need to use a DS18B20 to turn off/on a fan. The objective is to turn on the fan for 30 mins when the sensor reads 25 degrees and turns off after those 30 mins, wether the temp got up or down, and so on. I have an LCD 16x2 and I want it so show "Amb. Temp. XX". I'm new to arduino, and I tried a few coodes, but never worked. Thanks.

So what do you want from us? We know next to nothing about your setup cause you haven’t provided a schematic. We don’t know which “few codes” that you tried, either. Post the code that you tried, describe what the code actually does and how that is different from what you want. A photo of your actual wiring can help, too.

Read the “how to use this forum-please read” stickies to see how to format and post code and error messages and a few hints on what we need to know to help you (see #7 and 10).

Are you using Arduino UNO or MEGA or NANO or DUE?

Are you using PLCD (normal parallel interface) or I2CLCD?

Have you installed Dallas Temperature-3.8.0 (or what library?) for DS18B20 sensor?

If you are using I2CLCD, you have to install hd44780.h or LiquidCrystal_I2C.h Library. Have you done it?

I am using Arduino Leonardo with PLCD, I tried the temp sensor and it is working, my main problem is how to use the values from the threshold. Per exemple, I get the 25 degrees, but I don't know how to turn on/off the fan when that value is aquired. I have all the libraries installed.

The following program is tested on Arduino UNO under the following test parameters:
1. DPin-13 controls the Fan.
2. Temperature samples at 500 ms interval; it can changed to suit your need.
3. Temperature is shown on PLCD.
4. Test Temperature is 310C.
5. Fan ON period is 1-min (60000 ms).

#include <OneWire.h>
#include <DallasTemperature.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(11, 12, 5, 4, 3, 2);

#define ONE_WIRE_BUS 10  //10 is DPin-10 of UNO at which sensor's output is connected

OneWire oneWire(ONE_WIRE_BUS);         
DallasTemperature sensors(&oneWire);   //sensors is the object created from the class -- DallasTemp..
unsigned int dsTemp;                          //variable to hold Temperature value directly in Celsius
unsigned long presentmillis;

void setup(void)
{
  Serial.begin(9600);   //initialize Serial Monitor
  lcd.begin(16, 2);
  pinMode(13, OUTPUT);        //fac control
  digitalWrite(13, LOW);      //fan OFF
  sensors.begin();      //initialize One-Wire Sensor -- DS18B20 
}

void loop(void)
{ 
  showTempOnLCD();               //at 2-sec interval
  if (dsTemp > 32)
  {
    digitalWrite(13, HIGH);   //fan ON
    presentmillis = millis();
    
    do
    {
      showTempOnLCD();
    }
    while(millis() - presentmillis < 60000);
    digitalWrite(13, LOW);
     
  }
}

void showTempOnLCD()
{
  sensors.requestTemperatures();  // Temp conversion command; waiting here until comversion is done
  dsTemp = sensors.getTempCByIndex(0);  //read temp data from Sensor #0 and convert to celsius  
  lcd.print("Amb Temp:");
  lcd.print(dsTemp);
  lcd.write(0xDF);
  lcd.print('C');
  lcd.setCursor(0, 0);
  delay(500);    //sample temperature at 2-sec interval
}

Is pin 13 a good choice to control the fan? The built in LED flashes during reset which may cause the fan to start?

This is a demonstration, and I have used it to test the functionality of the program logic.