#include <Arduino.h>
#define IR_SEND_PIN 12
#include <IRremote.hpp>
#include "DHT.h"
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
//#define LED_PIN 3
//#define LED_PIN2 4
#include <TM1637.h>
TM1637 TM1;
const int buttonPin = 8;
const int buttonPin2 = 9;
const int buttonPin3 = 10;
int oldValue = LOW;
int oldValue2 = LOW;
int oldValue3 = LOW;
int oldValuepot = LOW;
float artis = 0;
float ayar = 28;
int autom = 1;
int bekleme = 0;
int klima = 0;
float hic = ayar - 1;
int incomingByte = 0;
void setup() {
TM1.begin(2, 3, 4); // clockpin, datapin, #digits
TM1.displayClear();
TM1.setBrightness(7);
pinMode(A0, INPUT);
Serial.begin(115200);
dht.begin();
lcd.init();
lcd.backlight();
// pinMode(LED_PIN, OUTPUT);
// pinMode(LED_PIN2, OUTPUT);
Serial.println("----------------Basladi.------------------");
lcd.print("Basladi.");
tone(4, 262, 250);
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(4, OUTPUT);
IrSender.begin(); // Start with IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin and enable feedback LED at default feedback LED pin
disableLEDFeedback(); // Disable feedback LED at default feedback LED pin
}
void loop() {
int newValue = digitalRead(buttonPin);
int newValue2 = digitalRead(buttonPin2);
int newValue3 = digitalRead(buttonPin3);
int newValuepot = analogRead(A0);
if (autom == 0){
lcd.clear();
lcd.noBacklight();
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
int cosan = incomingByte;
Serial.println(cosan);
if (cosan == 113) {
baslat();
}
}
if (newValue3 != oldValue3) {
if (newValue3 == HIGH && autom == 0) {
baslat();
}
oldValue3 = newValue3;
return;
}
//Serial.println("stand by...");
delay (100);
return;
}
if (newValue != oldValue) {
if (newValue == HIGH) {
ayar = ayar + artis;
buton();
delay(100);
return;
}
else {
//Serial.println(("up")); // tuşu bırakınca
}
oldValue = newValue;
return;
}
if (newValue2 != oldValue2) {
if (newValue2 == HIGH) {
ayar = ayar - artis;
buton();
delay(100);
return;
}
else {
//Serial.println(("up")); // tuşu bırakınca
}
oldValue2 = newValue2;
return;
}
if (newValue3 != oldValue3) {
if (newValue3 == HIGH && autom == 1) {
//Serial.println("b kapandi...");
kapat();
}
else {
}
oldValue3 = newValue3;
return;
}
if (newValuepot != oldValuepot) {
float value = analogRead(A0);
ayar = value/56+18;
buton();
delay(150);
oldValuepot = newValuepot;
return;
}
// Serial.println((bekleme));
if (bekleme == 50) {
kontrol();
lcd.clear();
lcd.noBacklight();
artis = 0;
}
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
//Serial.print("I received: ");
//Serial.println(incomingByte, DEC);
int cosan = incomingByte;
Serial.println(cosan);
if (cosan == 113){
//Serial.println("kkapandi...");
kapat();
}
}
bekleme++;
delay(100); }
////fonksiyonlar//////////////////////////////////////////////////////////////////////
void kontrol() {
bekleme = 0;
Serial.println("kontrol...");
float sicaklik;
sicaklik = okuma();
if (ayar < sicaklik) {
if (klima == 0) {
klimaac(); //Klima çalıştır
}
}
if (ayar > sicaklik) {
if (klima == 1) {
klimakapat(); //Klima Kapat
}
}}
void kapat() {
autom = 0;
lcd.backlight();
lcd.setCursor(0, 0);
lcd.println("Kapandi... ");
delay(2000);
return; }
void baslat() {
autom = 1;
lcd.backlight();
lcd.setCursor(0, 0);
lcd.println("Tekrar basladi. ");
delay(2000);
return; }
void buton() {
bekleme = 0;
float sicaklik;
sicaklik = okuma();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Sicaklik: ");
lcd.print(sicaklik);
lcd.setCursor(0, 1);
lcd.print(F("Ayar: "));
lcd.print(ayar);
lcd.print(" ");
artis = 0.1;
}
float okuma() {
float h = dht.readHumidity();
float t = dht.readTemperature();
float hic = dht.computeHeatIndex(t, h, false);
return hic;
}
void klimaac() {
//digitalWrite(LED_PIN, LOW);
//digitalWrite(LED_PIN2, HIGH);
lcd.clear();
lcd.print("Klima Acildi.");
IrSender.sendLG(0x88, 0x34, 1);
klima = 1;
delay (2000); }
void klimakapat() {
//digitalWrite(LED_PIN, HIGH);
//digitalWrite(LED_PIN2, LOW);
lcd.clear();
lcd.print("Klima Kapandi.");
IrSender.sendLG(0x88, 0xC005, 1);
klima = 0;
delay (2000); }