Étape 4: Programmation votre thermostat !
Maintenant, nous arrivons à notre thermostat du code. Ouvrez l’App Arduino (si vous ne l’avez pas, c’est gratuit ! Téléchargez-le ici : https://www.arduino.cc/en/Main/Software)
Je vais poster le code et utiliser les photos pour expliquer ce qui se passe à tous les stades.
#include
double refV ;
double tL = 25 ;
double tH = tL + 1 ;
const int button6 = 6 ; ce bouton affiche temp
const int button7 = 7 ; ce bouton affiche temp vers le bas
const int button8 = 8 ;
int speakerPin = 10 ;
int numTones = 5 ;
les tons int [] = {261, 294, 330, 370, 415} ;
int button6state = 0 ;
int button7state = 0 ;
int button8state = 0 ;
Innovente lcd(12,11,5,4,3,2) ;
void setup()
{
pinMode (button6, entrée) ;
pinMode (button7, entrée) ;
pinMode (button8, entrée) ;
pinMode (sortie 10,) ;
pinMode(13,OUTPUT) ;
LCD.Begin(16,2) ;
lcd.setCursor(0,0) ;
LCD.Print(TL) ;
LCD.Print ("to") ;
LCD.Print(TH) ;
analogReference(DEFAULT) ;
refV = 5 ;
pinMode(13,OUTPUT) ;
Serial.Begin(9600) ;
Serial.Print (« tL est: ") ;
Serial.Print("\t") ;
Serial.println(TL) ;
Serial.Print (« tH est: ") ;
Serial.Print("\t") ;
Serial.println(TH) ;
Serial.Print("Temp(C)") ;
Serial.Print("\t") ;
Serial.println("Status") ;
Serial.println("___") ;
Serial.println (« début de données: ") ;
}
void loop()
{
acc int = 0 ;
int N = 10 ;
pour (int i = 0; i < N; i ++) {}
ACC += analogRead(0) ; Delay(10) ;
}
double tension = refV*acc/1023./(double(N)) ;
double NC = (tension) * 100. ;
lcd.setCursor(0,1) ;
LCD.Print(tempC) ;
button6state = digitalRead(button6) ; code bouton 6
Si (button6state == HIGH)
{
tL = tL + 0,5 ;
e = e + 0,5 ;
lcd.setCursor(0,0) ;
LCD.Print(TL) ;
LCD.Print ("to") ;
LCD.Print(TH) ;
pour (int i = 0; i < numTones; i ++)
{
ton (speakerPin, tones[4]) ;
Delay(30)
}
noTone(speakerPin) ;
}
if(th > 55)
{
pour (int i = 0; i < numTones; i ++)
{
ton (speakerPin, tones[0]) ;
Delay(100) ;
}
noTone(speakerPin) ;
tH = 55 ;
tL = 54 ;
pour (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)
{
pour (int i = 0; i < numTones; i ++)
{
ton (speakerPin, tones[2]) ;
Delay(100) ;
}
noTone(speakerPin) ;
tH = 21 ;
tL = 20 ;
pour (int i = 0; i < 3; i ++)
{
lcd.setCursor(0,0) ;
LCD.Print("") ;
Delay(300) ;
lcd.setCursor(0,0) ;
LCD.Print(TL) ;
Delay(300) ;
}
}
Si (NC < tL)
{
digitalWrite(13,HIGH)
}
if(digitalRead(13)==High)
{
Serial.Print(tempC) ;
Serial.Print("\t") ;
Serial.println("1") ;
}
Delay(50) ;
}