A temperature controlled relay automatically switches AC-powered fans, heaters, or other loads based on temperature readings. This is the foundation for thermostat projects, incubators, fermentation chambers, and HVAC control. This guide covers building a safe, reliable temperature-controlled relay switch for both cooling and heating applications.
What Is a Temperature Controlled Relay?
A temperature controlled relay combines a temperature sensor (DS18B20 or DHT22), a microcontroller (Arduino), and a relay module to switch AC mains loads. When temperature exceeds a threshold, the relay activates a fan for cooling. When temperature drops below another threshold, the relay activates a heater. With proper hysteresis, this provides stable, automatic temperature control.
Components and Circuit Design
- Arduino Uno or Nano
- DS18B20 temperature sensor
- Relay module (5V, rated for your AC load)
- AC fan or heater (the load being controlled)
- 4.7kΩ pull-up resistor (for DS18B20)
- Enclosure rated for mains voltage
- Mains-rated wire (1.5mm² minimum for loads up to 10A)
For loads above 10A: Use an SSR (Solid State Relay) instead of a mechanical relay. SSRs handle higher currents, switch faster, and have no contact wear.
Relay Control Components
Wiring for AC Fan Control
AC fan cooling circuit:
- DS18B20 → Arduino pin 2 (with 4.7kΩ pull-up)
- Arduino pin 7 → Relay module IN
- AC mains Live → Relay COM (Common)
- Relay NO (Normally Open) → AC fan Live input
- AC mains Neutral → AC fan Neutral
When temperature rises above threshold, Arduino sets pin 7 HIGH, relay closes, fan runs. When temperature drops below threshold minus hysteresis, relay opens, fan stops.
IMPORTANT: The relay only switches the Live wire. Neutral connects directly to the load. This is a safety requirement — never switch Neutral while Live remains connected.
Wiring for AC Heater Control
AC heater control circuit: Same wiring as fan, but the logic is reversed — relay closes when temperature drops below the set point, and opens when temperature rises above the set point.
For a combined heating/cooling system (like an incubator), use two relays: one for the heater (activated below set point – hysteresis) and one for the fan/cooler (activated above set point + hysteresis). The dead zone between heater-off and cooler-on prevents both running simultaneously.
Arduino Code with Hysteresis
#include <OneWire.h>
#include <DallasTemperature.h>
#define SENSOR_PIN 2
#define FAN_RELAY 7 // Cooling relay
#define HEATER_RELAY 8 // Heating relay
#define SETPOINT 37.5 // Target temperature
#define HYST 1.0 // Hysteresis (±1°C)
OneWire oneWire(SENSOR_PIN);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
pinMode(FAN_RELAY, OUTPUT);
pinMode(HEATER_RELAY, OUTPUT);
digitalWrite(FAN_RELAY, LOW);
digitalWrite(HEATER_RELAY, LOW);
}
void loop() {
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
// Cooling: ON above setpoint + hysteresis
if (temp >= SETPOINT + HYST) {
digitalWrite(FAN_RELAY, HIGH); // Fan ON
} else if (temp <= SETPOINT) {
digitalWrite(FAN_RELAY, LOW); // Fan OFF
}
// Heating: ON below setpoint - hysteresis
if (temp = SETPOINT) {
digitalWrite(HEATER_RELAY, LOW); // Heater OFF
}
Serial.print("Temp: "); Serial.print(temp);
Serial.print(" Fan: "); Serial.print(digitalRead(FAN_RELAY));
Serial.print(" Heater: "); Serial.println(digitalRead(HEATER_RELAY));
delay(2000);
}
Safety Considerations for Mains Switching
WARNING: This circuit switches AC mains voltage (230V in India). Improper wiring can cause electrocution or fire.
- Use relay modules rated for at least 1.5x your load current at 250V AC
- Use mains-rated wire (1.5mm² minimum, ISI marked)
- Enclose ALL mains connections in an insulated box — no exposed terminals
- Use a proper mains plug with earth connection
- Add a fuse rated for your load current in the Live line
- Test with a multimeter before connecting the load
- Keep low-voltage (Arduino) and high-voltage (mains) wiring physically separated
- Consider using an SSR for mains switching — no mechanical contacts to arc and weld
Recommended Components
Complete Temperature Control Kit
Common Applications
- Egg incubator: Maintain 37.5°C with heater and fan relays
- Mushroom growing chamber: Maintain 20-25°C with humidifier and exhaust fan
- Fermenter: Maintain lager temp 10-14°C or ale temp 18-22°C
- Server room backup: Emergency fan activation if main AC fails
- Greenhouse: Heating at night, ventilation during day
- Aquarium: Heater control for tropical fish (25-28°C)
Frequently Asked Questions
Can I switch AC mains with an Arduino relay?
Yes, using a relay module rated for 250V AC. The Arduino controls the relay coil at 5V; the relay contacts switch the AC mains. Always follow mains safety practices.
What relay should I use for a heater?
For heaters up to 2kW (8.7A at 230V), a 10A relay module works. For larger heaters, use a 25A or 40A SSR (Solid State Relay) with a heat sink.
What is the difference between SSR and mechanical relay?
SSRs have no moving parts — they switch using semiconductors. Faster switching, no contact wear, no arcing. Mechanical relays are cheaper and simpler. Use SSRs for frequent switching or high-current loads.
How much hysteresis should I use?
1-2°C for precise applications (incubators, fermenters). 3-5°C for comfort applications (room thermostats, server rooms). Less hysteresis = tighter control but more relay cycling.
Where can I buy relay modules in India?
Zbotic.in stocks 5V and 12V relay modules from ₹84, and SSR solid state relays from ₹108. Both work with Arduino and ESP32 for temperature-controlled switching.
Shop Cooling & Thermal Components at Zbotic
India’s trusted store for electronics components. Fast shipping, genuine products, and expert support.
Add comment