Paso 4: Programar el termostato!
Ahora tenemos nuestro termostato. Abre la App Arduino (si no lo tienes, es gratis! Descargar aquí: https://www.arduino.cc/en/Main/Software)
Voy a publicar el código y usar las fotos para explicar lo que está sucediendo en todas las etapas.
#include
refV doble;
doble tL = 25;
doble tH = tL + 1;
const int button6 = 6; Este botón muestra la temperatura
const int button7 = 7; Este botón lleva a temp
const int button8 = 8;
int speakerPin = 10;
int numTones = 5;
tonos de int [] = {261, 294, 330, 370, 415};
int button6state = 0;
int button7state = 0;
int button8state = 0;
LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
{
pinMode (button6, entrada);
pinMode (button7, entrada);
pinMode (button8, entrada);
pinMode (10, salida);
pinMode(13,OUTPUT);
LCD.Begin(16,2);
lcd.setCursor(0,0);
LCD.Print(tL);
LCD.Print ("a");
LCD.Print(TH);
analogReference(DEFAULT);
refV = 5;
pinMode(13,OUTPUT);
Serial.Begin(9600);
Serial.Print ("tL es:");
Serial.Print("\t");
Serial.println(tL);
Serial.Print ("es:");
Serial.Print("\t");
Serial.println(TH);
Serial.Print("Temp(C)");
Serial.Print("\t");
Serial.println("status");
Serial.println("___");
Serial.println ("a partir de los datos:");
}
void loop()
{
acc de int = 0;
int N = 10;
para (int i = 0; i < N; i ++) {}
ACC += analogRead(0); Delay(10);
}
doble voltaje = refV*acc/1023./(double(N));
doble tempC = (voltaje) * 100.;
lcd.setCursor(0,1);
LCD.Print(tempC);
button6state = digitalRead(button6); código para botón 6
Si (button6state == HIGH)
{
tL = tL + 0,5;
tH tH = 0,5;
lcd.setCursor(0,0);
LCD.Print(tL);
LCD.Print ("a");
LCD.Print(TH);
para (int i = 0; i < numTones; i ++)
{
tono (speakerPin, tones[4]);
Delay(30)
}
noTone(speakerPin);
}
if(TH > 55)
{
para (int i = 0; i < numTones; i ++)
{
tono (speakerPin, tones[0]);
Delay(100);
}
noTone(speakerPin);
tH = 55;
tL = 54;
para (int i = 0; i < 3; i ++)
{lcd.setCursor(9,0);
LCD.Print("")
Delay(300)
lcd.setCursor(9,0);
LCD.Print(TH);
Delay(300);
}
if(tL < 20)
{
para (int i = 0; i < numTones; i ++)
{
tono (speakerPin, tones[2]);
Delay(100);
}
noTone(speakerPin);
tH = 21;
tL = 20;
para (int i = 0; i < 3; i ++)
{
lcd.setCursor(0,0);
LCD.Print("");
Delay(300);
lcd.setCursor(0,0);
LCD.Print(tL);
Delay(300);
}
}
Si (tempC < tL)
{
digitalWrite(13,HIGH)
}
if(digitalRead(13)==High)
{
Serial.Print(tempC);
Serial.Print("\t");
Serial.println("1");
}
Delay(50);
}