1. /*
Programa control_on_off_temperatura_01.ino
- Control todo o nada.
- Control de temperatura con resistencia y LM35.
31/10/2017
*/
const int tempPin= 3;
const int controlPin = 5;
const float resolucion = 1023.0;
const int v_ref_mv = 1100;
float now , lasttime = 0 , timechange;
float Setpoint = 28.0; //NUNCA LLEGA A 35 GRADOS
float error;
int settime = 1000;
void setup()
{
Serial.begin(9600);
analogReference(INTERNAL); //1.1 VOLTIOS PARA MAYOR RESOLUCION
pinMode(controlPin, OUTPUT);
digitalWrite(controlPin, LOW);
}
void loop()
{
2. int val_adc;
float millivolts, temp;
now = millis() ; //EN VEZ DE DELAY, PREGUNTA SI PASO UN SEGUNDO, DESDE QUE INICIO EL uP, si
paso 1000 millis entonces ejecuta sino no puede ser para otras funciones
timechange = (now - lasttime);
if (timechange >= settime)
{
lasttime = now;
val_adc = analogRead(tempPin);
millivolts = (val_adc / resolucion) * v_ref_mv;
temp = millivolts / 10; //
error = Setpoint - temp;
Serial.print (Setpoint);
Serial.print (" ");
Serial.print (temp);
Serial.print (" ");
if (error > 0)
{
digitalWrite(controlPin, HIGH);
Serial.println(20);
}
else
{
digitalWrite(controlPin, LOW);