-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtermostato.ino
52 lines (43 loc) · 1.72 KB
/
termostato.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Por Roberto A.Zavala
// Breve : https://es.overleaf.com/read/xmzzgmygvbqx
// Libro : https://www.amazon.com.mx/dp/B074TTGLL2
// 🙏🏼 : DNv7acPAeVBhTXbKv26itJecPG1SPy2o4F
int Tr = 2; // puerto del transistor
int PT; // PWM aplicado al transistor
int Tm = A0; // puerto del termistor
float To = 50; // temperatura objetivo
float A = 0.001482484340; // Coefientes de Steinhart-Hart
float B = 0.000167799949;
float C = 0.000000406675;
int R = 9950; // resistencia de divisor de voltaje
float RT; // resistencia del termistor
float t; // temperatura
float Vs; // voltaje de salida
int Ve = 5; // voltaje de entrada
int dl = 10000; // periodo de la rutina
void setup()
{
Serial.begin(9600);
pinMode( Tr,OUTPUT );
Serial.println("Termostato :)");
}
void loop()
{
t = 0;
for (int i=0; i <= 9; i++) // se mide 10 veces la temperatura
{
Vs = (analogRead(Tra)/204.6);
RT = (Ra*Vsa)/(Ve-Vsa);
dT = Aa + Ba * log( RT ) + Ca * pow( log(RT) , 3 );
T = 1/dT;
T = T - 273.15;
t = t + T;
delay(200);
}
t = t/10; // obtiene la temperatura
if ( t < To ) { analogWrite ( Tr , PT ); PT = PT + 1; } // si t < To aumenta la potencia
else if ( t == To ) { analogWrite ( Tr , PT ); } // si t = To se mantiene la potencia
else { analogWrite ( Tr, 0 ); PT = PT - 1; } // si t > To se apaga y reduce en 1 la potencia
Serial.print(to); Serial.print("\t"); Serial.print(t); Serial.print("\t"); Serial.println(PT);
delay(dl);
}