Zde je kód:
Kód: Vybrat vše
int zelena = A0;
int cervena = A1;
int modra = A2;
int zluta = A3;
#include "DHT.h"
#define typDHT11 DHT11
#define pinDHT 5
DHT mojeDHT(pinDHT, typDHT11);
// Include the libraries:
#include <TM1637Display.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
// Define the connections pins:
#define CLK 2
#define DIO 3
#define DHTPIN 4
// Create variable:
int temperature_celsius;
int temperature_fahrenheit;
// Create degree Celsius symbol:
const uint8_t celsius[] = {
SEG_A | SEG_B | SEG_F | SEG_G, // Circle
SEG_A | SEG_D | SEG_E | SEG_F // C
};
// Create degree Fahrenheit symbol:
const uint8_t fahrenheit[] = {
SEG_A | SEG_B | SEG_F | SEG_G, // Circle
SEG_A | SEG_E | SEG_F | SEG_G // F
};
// Set DHT type, uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Create display object of type TM1637Display:
TM1637Display display = TM1637Display(CLK, DIO);
// Create dht object of type DHT:
DHT dht = DHT(DHTPIN, DHTTYPE);
void setup() {
pinMode(zelena, OUTPUT);
pinMode(modra, OUTPUT);
pinMode(cervena, OUTPUT);
pinMode(zluta, OUTPUT);
// Set the display brightness (0-7):
display.setBrightness(0);
// Clear the display:
display.clear();
// Setup sensor:
dht.begin();
// Begin serial communication at a baud rate of 9600:
Serial.begin(9600);
// Wait for console opening:
delay(2000);
}
void loop() {
// Read the temperature as Celsius and Fahrenheit:
temperature_celsius = dht.readTemperature();
temperature_fahrenheit = dht.readTemperature(true);
// Print the temperature to the Serial Monitor:
Serial.println(temperature_celsius);
Serial.println(temperature_fahrenheit);
// Show the temperature on the TM1637 display:
display.showNumberDec(temperature_celsius, false, 2, 0);
display.setSegments(celsius, 2, 2);
delay(2000);
//display.showNumberDec(temperature_fahrenheit, false, 2, 0);
//display.setSegments(fahrenheit, 2, 2);
// delay(2000);
float teplota = mojeDHT.readTemperature();
//float vlhkost = mojeDHT.readHumidity();
if (isnan(teplota)){
Serial.println("Chyba při čtení z DHT senzoru!");
} else {
Serial.print("Teplota: ");
Serial.print(teplota);
Serial.print(" stupnu Celsia, ");
//Serial.print("vlhkost: ");
//Serial.print(vlhkost);
//Serial.println(" %");
}
if (teplota = 22){
digitalWrite(zelena, HIGH);
}
else if (teplota = 24){
digitalWrite(zluta, HIGH);
}
else if (teplota > 20){
digitalWrite(modra, HIGH);
}
else if (teplota < 26){
digitalWrite(cervena, HIGH);
}
delay(100);
digitalWrite(zelena, LOW);
digitalWrite(modra, LOW);
digitalWrite(cervena, LOW);
digitalWrite(zluta, LOW);
}