Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hesam Moshiri
Published

3-Wires/4-Wires FAN Control and Over Temperature Protection

3-Wires/4-Wires FAN Control and Over Temperature Protection using LM35 and ATTiny13

IntermediateFull instructions provided2 hours101
3-Wires/4-Wires FAN Control and Over Temperature Protection

Things used in this project

Hardware components

2N7002
×1
78L05
×1
ATTiny13
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Sch

Code

Code

C/C++
#include <util/delay.h>    


// Clock at 9.6MHz
#define F_CPU 9600000


const int PWMPin = 1;  
analog_pin_t PotPin = A3;
const unsigned char relayPin = 0, buzzerPin = 4;
unsigned int rawTemp = 0, out = 0;
unsigned char counter = 0;


void setup()
{
  analogReference(INTERNAL1V1);
  pinMode(PWMPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  digitalWrite(relayPin, 0);
  digitalWrite(buzzerPin, 0);
  // Phase Correct PWM Mode, no Prescaler
  // PWM on Pin 1(PB1), Pin 0(PB0) disabled
  // 9.6MHz / 192 / 2 = 25Khz
  TCCR0A = _BV(COM0B1) | _BV(WGM00);
  TCCR0B = _BV(WGM02) | _BV(CS00);
  // Set TOP and initialize duty cycle to zero(0)
  OCR0A = 192;  // TOP - DO NOT CHANGE, SETS PWM PULSE RATE
  OCR0B = 192;    // duty cycle for Pin 1(PB1)
}


void loop()
{
  rawTemp = analogRead(PotPin) + rawTemp;
  counter ++;
  if (counter == 15) {
    rawTemp = rawTemp / 15;
    if (rawTemp < 232) {
      OCR0B = 192;
    } else {
      out = map(rawTemp, 232, 558, 192, 0);
      OCR0B = out;
    }
    if (rawTemp > 560)
    {
      emergency_OFF();
    }
    counter = 0;
    rawTemp = 0;
  }
  _delay_ms(25);
}


void emergency_OFF() {
  while (1) {
    digitalWrite(relayPin, 1);
    digitalWrite(buzzerPin, 1);
    _delay_ms(250);
    digitalWrite(buzzerPin, 0);
    _delay_ms(250);
  }
}

Credits

Hesam Moshiri
51 projects • 35 followers
https://www.youtube.com/c/MyVanitar/videos
Contact

Comments

Please log in or sign up to comment.