What I'm using is the Arduino Uno. I'm simulating a temperature control system just like the ac in your cars. The problem with my code is that. I'm using the Up & Down button on my IR remote. The UP button is suppose to increased the desired temperature by one and the down button decreases it by one. But for some reason when I push the down button, it increases the value by one. Another problem is that, when the value of the desired temperature goes over +2 of the value of the current temperature, it stops and won't allow me to changed the desired temperature without resetting the system. I want it to be continuous. Please help thank you!
CODE :
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
#include <TinyDHT.h>
#include <IRremote.h>
#define DHTPIN 2
#define DHTTYPE DHT11
#define UP 0xFF629D
#define DOWN 0xFFA857
const int THpin = 2;
const int DCONE = 3;
const int DCTWO = 4;
const int IRPIN = 5;
const int COOLPIN = 8;
const int HEATPIN = 9;
LiquidCrystal_PCF8574 lcd(0x27);
DHT dht(DHTPIN, DHTTYPE);
IRrecv irrecv(IRPIN);
decode_results results;
int TEMP = 0;
int DETEMP = 70;
int DISTEMP = 70;
int CURTEMP = 70;
unsigned long NETEMP;
unsigned long CUTIME;
void setup() {
int error;
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(0x27);
error = Wire.endTransmission();
Serial.print("Error: ");
Serial.print(error);
lcd.begin(16, 2);
lcd.setBacklight(255);
lcd.clear();
dht.begin();
pinMode(DCONE, OUTPUT);
pinMode(DCTWO, OUTPUT);
irrecv.enableIRIn();
pinMode(COOLPIN, OUTPUT);
pinMode(HEATPIN, OUTPUT);
int16_t readTemperature(bool S = true);
NETEMP = millis();
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if (results.value = UP) {
TEMP = 1;
DETEMP++;
}
else if (results.value = DOWN) {
TEMP = 1;
DETEMP--;
}
irrecv.resume();
delay(100);
}
if (TEMP = 1) {
DISTEMP = DETEMP;
}
else {
DISTEMP = CURTEMP;
DETEMP = CURTEMP;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(DETEMP);
if (CURTEMP<(DETEMP-2)) {
digitalWrite(COOLPIN, LOW);
digitalWrite(HEATPIN, HIGH);
analogWrite(DCONE,0);
analogWrite(DCTWO,250);
}
else if (CURTEMP>(DETEMP+2)) {
digitalWrite(COOLPIN, HIGH);
digitalWrite(HEATPIN, LOW);
analogWrite(DCONE,0);
analogWrite(DCTWO,250);
}
else {
digitalWrite(COOLPIN, LOW);
digitalWrite(HEATPIN,LOW);
analogWrite(DCONE,0);
analogWrite(DCTWO,0);
}
CUTIME = millis();
if (CUTIME>NETEMP) {
int16_t t = dht.readTemperature(1);
NETEMP = CUTIME + 60000;
}
delay(200);
int16_t t = dht.readTemperature(1);
if (t==BAD_TEMP) {
Serial.println("Failed to read from DHI");
}
else {
Serial.print("Temperature:");
Serial.print(t);
Serial.println(" *F");
}
delay(2000);
}