Hi, I'm trying to do a very simple circuit with Arduino to control my AC unit.
What I did so far:
- used the IR Receiver to get the IR codes for on/off
- I have a tempereature sensor and an IR Blaster setup on the board, I tested them both, they are correctly wired and the blaster does send some IR data
However, my AC unit (or units, I've tried with 2) don't react to that.
So now I am a bit lost a to what is going on.
#include <IRremote.hpp>
#include <DHT.h>
#define RAW_BUFFER_LENGTH 400
uint16_t rawOn[] = { 3150, 1500, 550, 1050, 550, 1000, 550, 150, 650, 150, 650, 150, 700, 1000, 550, 150, 650, 150, 650, 1050, 500, 1050, 550, 150, 650, 1050, 550, 150, 600, 150, 700, 1000, 600, 1000, 550, 150, 650, 1000, 550, 1050, 550, 150, 650, 150, 650, 1000, 600, 100, 650, 150, 700, 150, 650, 1000, 550, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 100, 700, 150, 650, 150, 650, 150, 650, 150, 700, 100, 700, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 1050, 500, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 200, 650, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 100, 700, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 1000, 550, 150, 650, 1050, 550, 150, 650, 150, 650, 1050, 500, 1050, 550, 150, 650, 0 };
const uint16_t rawOnLen = sizeof(rawOn) / sizeof(rawOn[0]);
uint16_t rawOff[] = { 3150, 1500, 500, 1050, 550, 1050, 500, 150, 650, 150, 700, 150, 650, 1050, 550, 150, 600, 150, 700, 1000, 550, 1050, 500, 150, 700, 1000, 550, 150, 650, 150, 650, 1050, 550, 1000, 550, 150, 650, 1050, 550, 1000, 550, 150, 650, 150, 650, 1050, 550, 150, 650, 150, 650, 150, 650, 1050, 550, 150, 650, 150, 650, 150, 650, 200, 650, 150, 650, 150, 650, 150, 650, 150, 650, 200, 650, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 200, 650, 150, 650, 1050, 500, 150, 650, 200, 650, 150, 650, 150, 650, 150, 650, 150, 650, 200, 650, 150, 650, 150, 650, 150, 650, 150, 650, 200, 650, 150, 650, 150, 650, 150, 650, 150, 650, 200, 650, 150, 650, 150, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 650, 200, 650, 150, 650, 150, 650, 150, 650, 150, 650, 200, 650, 150, 650, 150, 650, 150, 650, 150, 650, 200, 600, 200, 600, 200, 650, 150, 650, 150, 650, 150, 700, 150, 650, 150, 650, 150, 650, 150, 700, 100, 700, 150, 650, 150, 650, 200, 600, 200, 600, 250, 600, 200, 600, 200, 600, 150, 650, 250, 550, 250, 600, 1000, 550, 200, 600, 1000, 550, 250, 600, 200, 600, 1000, 550, 1050, 550, 200, 600, 0 };
const uint16_t rawOffLen = sizeof(rawOff) / sizeof(rawOff[0]);
// ==== END PASTE ====
// Pins
const uint8_t IR_SEND_PIN = 3; // IR LED via NPN transistor (UNO default carrier pin)
const uint8_t DHT_PIN = 7;
const uint8_t DHT_TYPE = DHT11;
const uint8_t CARRIER_KHZ = 38; // most remotes
// Thresholds & state
const float ON_THRESHOLD = 20.0; // >= -> send ON
const float OFF_THRESHOLD = 16.0; // <= -> send OFF
enum State { S_UNKNOWN, S_ON, S_OFF };
State state = S_UNKNOWN;
DHT dht(DHT_PIN, DHT_TYPE);
void setup() {
Serial.begin(9600);
dht.begin();
IrSender.begin(IR_SEND_PIN); // correct IRremote 4.x signature
Serial.println("Thermostat ready (DHT11 on D7, IR send on D3).");
}
void loop() {
static unsigned long last = 0;
if (millis() - last < 2000) return; // read every ~2s
last = millis();
float t = dht.readTemperature();
if (isnan(t)) {
Serial.println("DHT read failed");
return;
}
Serial.print("Temp = ");
Serial.print(t, 1);
Serial.println(" °C");
if (t >= ON_THRESHOLD && state != S_ON) {
Serial.println(">= 20°C → SEND ON");
IrSender.sendRaw(rawOn, rawOnLen, CARRIER_KHZ);
state = S_ON;
} else if (t <= OFF_THRESHOLD && state != S_OFF) {
Serial.println("<= 16°C → SEND OFF");
IrSender.sendRaw(rawOff, rawOffLen, CARRIER_KHZ);
state = S_OFF;
}
}
This is the code I've tried so far.
Any help would be highly appreciated!