// ATtiny85 Blink!
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
#define sensor 3
#define rele 1
#define THERMISTOR 992 // VALOR OHM DEL SENSOR 25 °C(992 spark)(2500 optra)
#define NUMSAMPLES 10 // NUMERO DE MUESTRAS TOMADAS NTC
#define BCOEFFICIENT 3680 // beta coefficient 3000-4000 (3680 spark)
#define SERIESRESISTOR 974 // resistor en serie 10k (1k para spark)
unsigned long timer;
void setup() {
pinMode(rele, OUTPUT);
pinMode(sensor, INPUT);
digitalWrite(rele, LOW);
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
oled.on();
}
void loop() {
float Rth, steinhart, average=0; char i; int samples[NUMSAMPLES];
for (i=0; i< NUMSAMPLES; i++) { samples[i] = analogRead(sensor); }
for (i=0; i< NUMSAMPLES; i++) { average += samples[i]; }
average /= NUMSAMPLES;
Rth = (1024 * float(THERMISTOR)/average)-float(THERMISTOR); //Valor de Rth en funcion del conexionado de nuestro termistor
steinhart = ((1/((1/298.15)+(1/float(BCOEFFICIENT))*log(SERIESRESISTOR/Rth)))-273.15); //Aplicamos directamente Steinhart-hart para NTC
//****************************************************************************************//
if (millis() > timer) { oled.clear(); timer = millis() + 3000UL; }
oled.setFont(FONT6X8);
oled.setCursor(32,0); oled.println(F("TEMPERATURA"));
oled.setFont(FONT8X16);
oled.setCursor(35,3); oled.print(steinhart,1); oled.println(F(" 'C"));
if (steinhart>=92) {digitalWrite(rele,HIGH);
oled.setCursor(40,5); oled.println(F("FAN On"));}
if (steinhart<90) {digitalWrite(rele,LOW);}
}