Termostato con Arduino

Termostato con Arduino

Lista dei Materiali

Quantità Descrizione Proprietà
1 Arduino Leonardo (Rev3b) tipo Arduino Leonardo (Rev3)
1 Header 2 variant -jst-2-pth-no_silk; package jst-2-pth-ns
1 LCD screen tipo Character; pins 16
1 Red (633nm) LED colore Red (633nm); package 1206 [SMD]
1 220Ω Resistor resistenza 220Ω; tolerance ±5%; package 0805 [SMD]
1 Trimmer Potentiometer tipo Trimmer Potentiometer; track Linear; maximum resistance 10kΩ; size Trimmer – 12mm; package THT
1 10kΩ Resistor resistenza 10kΩ; tolerance ±5%; package 1206 [SMD]
1 Humidity and Temperature Sensor RHT03 output signal Digital Signal; power supply 3.3-5.5V DC; sensing element Polymer humidity capacitor
1 POT variant -rv16af-20; package pot_alpha_rv16af-20
1 RELAY-2 variant g5q; package relay-g5v

Circuito elettrico

 

Codice Arduino

#include <LiquidCrystal.h>
#include <DHT.h>
#define DHTPIN 13
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int regulatorPin = A0;
int regulatorValue = 0;
int relePin = 10;
String stato = "OFF";

void setup() {
  Serial.begin(9600);
  dht.begin();
  lcd.begin(16, 2);
  pinMode(relePin, OUTPUT);
  digitalWrite(relePin, LOW);
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  String umidita = "H2O: ";
  String temperatura = "Tem: ";
  
  regulatorValue = analogRead(regulatorPin);
  regulatorValue = map(regulatorValue, 0, 1023, 15, 26);
  if (t<regulatorValue) {
    digitalWrite(relePin, HIGH);
    stato = " ON";
  }
  else {
    digitalWrite(relePin, LOW);
    stato = "OFF";
  }

  umidita = umidita + int(h);
  umidita = umidita + "% S=";
  umidita = umidita + stato;  

  temperatura = temperatura + int(t);
  temperatura = temperatura + "C T=";
  temperatura = temperatura + regulatorValue;
  temperatura = temperatura + "C";
  
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print(temperatura);
  Serial.print("\n");
  Serial.println(umidita);

  lcd.setCursor(0, 0);
  lcd.print(temperatura);
  lcd.setCursor(0, 1);
  lcd.print(umidita);  
}

Stefano Mercurio

You must be logged in to post a comment