user57281: This is the code:
#define TMST A2 // Thermistor
#define BZR 10  // Buzzer
#define FanP 11 // Fan

void setup() {
  DDRD = B11000000;
  DDRB = B00001111;
  DDRC = B00000000;
  TCCR2B = TCCR2B & B11111000 | B00000101; // pin 3 & 11 -> 245Hz
  T0 = 25 + 273.15;
}

void loop() {
  if (hallState > magnetDistance) {
    PORTB &= ~(1 << 0); // port manipulation -> LOW
    strcpy(WPStatus, "OFF");
    if (Alarm == 1) { // this will be set in setting menu
      if ((millis() - BZRT) > 500) {
        tone(BZR, 2300);
        BZRT = millis();
      }
      if ((millis() - BZRT) > 250) {
        noTone(BZR);
      }
    }
    else {
      noTone(BZR);
    }
  }
  else {
    PORTB |= (1 << 0); // port manipulation -> HIGH
    noTone(BZR);
    strcpy(WPStatus, " ON");
  }

  if ((millis() - fanTimer) > 2000) { // checks every 2 seconds if temperature changed
    Thermistor();
    if (TX <= 32) {
      analogWrite(FanP, 60); // Fan spinning speed
    }
    if (TX > 32 && TX <= 36) {
      analogWrite(FanP, 120);
    }
    if (TX > 36) {
      analogWrite(FanP, 255);
    }
    fanTimer = millis();
  }
}
float Thermistor() { // reading and calculating from thermistor
  VRT = analogRead(TMST);
  VRT = (5.00 / 1023.00) * VRT;
  VR = 5 - VRT;
  RT = VRT / (VR / 10000);
  ln = log(RT / 10000);
  TX = (1 / ((ln / 3977) + (1 / T0)));
  TX = TX - 273.15;
  return TX; // returning the temperature
}

The 5V buzzer connected to a PWM pin with a 100 ohm resistor, thermistor and fan are connected to Arduino like this:

simulate this circuit – Schematic created using CircuitLab
Why When buzzer is alarming fan stops spinning?

user4143: The tone() command uses Timer2 to generate the square wave (it triggers an interrupt which toggles an IO pin).
However Timer2 is also used to generate the PWM signal on pins 3 and 11.
Thus you cannot use tone() and PWM on pins 3 or 11 simultaneously.
The simple fix: use PWM from pins 5, 6, 9 or 10 to control your fan.

57281: <p>This is the code:</p>

<pre><code>#define TMST A2 // Thermistor
#define BZR 10  // Buzzer
#define FanP 11 // Fan

void setup() {
  DDRD = B11000000;
  DDRB = B00001111;
  DDRC = B00000000;
  TCCR2B = TCCR2B &amp; B11111000 | B00000101; // pin 3 &amp; 11 -&gt; 245Hz
  T0 = 25 + 273.15;
}

void loop() {
  if (hallState &gt; magnetDistance) {
    PORTB &amp;= ~(1 &lt;&lt; 0); // port manipulation -&gt; LOW
    strcpy(WPStatus, "OFF");
    if (Alarm == 1) { // this will be set in setting menu
      if ((millis() - BZRT) &gt; 500) {
        tone(BZR, 2300);
        BZRT = millis();
      }
      if ((millis() - BZRT) &gt; 250) {
        noTone(BZR);
      }
    }
    else {
      noTone(BZR);
    }
  }
  else {
    PORTB |= (1 &lt;&lt; 0); // port manipulation -&gt; HIGH
    noTone(BZR);
    strcpy(WPStatus, " ON");
  }

  if ((millis() - fanTimer) &gt; 2000) { // checks every 2 seconds if temperature changed
    Thermistor();
    if (TX &lt;= 32) {
      analogWrite(FanP, 60); // Fan spinning speed
    }
    if (TX &gt; 32 &amp;&amp; TX &lt;= 36) {
      analogWrite(FanP, 120);
    }
    if (TX &gt; 36) {
      analogWrite(FanP, 255);
    }
    fanTimer = millis();
  }
}
float Thermistor() { // reading and calculating from thermistor
  VRT = analogRead(TMST);
  VRT = (5.00 / 1023.00) * VRT;
  VR = 5 - VRT;
  RT = VRT / (VR / 10000);
  ln = log(RT / 10000);
  TX = (1 / ((ln / 3977) + (1 / T0)));
  TX = TX - 273.15;
  return TX; // returning the temperature
}
</code></pre>

<p>The 5V buzzer connected to a PWM pin with a 100 ohm resistor, thermistor and fan are connected to Arduino like this:</p>



<p><img src="https://i.stack.imgur.com/QKArY.png" alt="schematic"></p>



<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fQKArY.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="nofollow">CircuitLab</a></sup></p>

<p>Why When buzzer is alarming fan stops spinning?</p>
 4143: <p>The <code>tone()</code> command uses Timer2 to generate the square wave (it triggers an interrupt which toggles an IO pin).</p>

<p>However Timer2 is also used to generate the PWM signal on pins 3 and 11.</p>

<p>Thus you cannot use <code>tone()</code> and PWM on pins 3 or 11 simultaneously.</p>

<p>The simple fix: use PWM from pins 5, 6, 9 or 10 to control your fan.</p>
