Turning 220V AC /24V DC Fan on and off using relay

I have a project where I need to use arduino to turn on/off all 10 parallel connected fans at the same time. I have bought a 24V relay. Is there anything else I need to buy?

The fans run at 220V AC 0.05A or 24V DC 0.05A.

Thank you in advance. Cheers

What determines the fans on and off events ?

Button, time, doggy door ?

AC or DC? Is it capable of switching 10 Amps?

Can you confirm these numbers?


This is the relay I bought.

I'm planning to run on a 24V 5A DC adapter. The fan takes up 24V 0.05A each. In parallel total would be 24V and 0.5A.

There will be three buttons (start, stop and reset) as of now. The buttons act as on/off buttons only

Sorry, I can't see the terminal labels on that picture. Incorrectly connecting a 24V relay to your 5V Arduino could be disastrous so I'll pass.


I wonder does this helps in seeing the terminal labels?

No, that's a 5V relay with only 3 control terminals instead of the 4 in your first picture.

Maybe I'll send another one when I receive the item. Thank you in advance

I'll be watching. Good luck. :slightly_smiling_face:

Screenshot 2024-07-04 at 1.02.51 PM
This is an example 12v DC relay with the terminals. I ordered a 24V DC. Hope this will help.

Connect 24V+ (positive) to DC+, 24V- (negative) to DC-, Arduino 5V to VREF, Arduino output pin to CH1. Relay should activate when output pin is LOW.

Thank you for your detailed explanation. Appreciate it. Will try when the relay arrives this weekend :smiling_face_with_three_hearts:

I have bought 2 relays. One is 5V and another one is 24V. I have connected the 5V relay and apparently it works. The seller advised me to use a 5V relay as the Arduino can only output maximum 5V to the relay in order to turn it on and off. Is there still a need to change to 24V relay?

This is my code for reference.

#include <LiquidCrystal.h>

const int relayPin = 6;     // Relay pin to control the fan
const int buttonPin = 4;    // Button pin
const int greenLedPin = 3;  // Green LED pin
const int redLedPin = 5;    // Red LED pin
const int piezoPin = 2;     // Piezo pin

bool deviceOn = false;      // State of the device
unsigned long startTime;    // Start time for the fan
unsigned long runTime = 10000; // 30 minutes in milliseconds

// Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

void setup() {
  Serial.begin(9600);       // Start the Serial communication
  pinMode(relayPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP); // Use internal pull-up resistor
  pinMode(greenLedPin, OUTPUT);
  pinMode(redLedPin, OUTPUT);
  pinMode(piezoPin, OUTPUT);

  // Set up the LCD's number of columns and rows
  lcd.begin(16, 2);
  lcd.print("Press button to");
  lcd.setCursor(0, 1);
  lcd.print("turn on device");

  // Ensure the fan and LEDs are off initially
  digitalWrite(relayPin, LOW);
  digitalWrite(greenLedPin, LOW);
  digitalWrite(redLedPin, HIGH);
}

void loop() {
  // Check if the button is pressed
  if (digitalRead(buttonPin) == LOW) {
    delay(50); // Debounce delay
    while (digitalRead(buttonPin) == LOW); // Wait for button release
    deviceOn = !deviceOn; // Toggle device state

    if (deviceOn) {
      lcd.clear();
      lcd.print("Device is ON");
      delay(1000); // Display message for 1 second
      lcd.clear();
      lcd.print("Fan is running");

      // Turn on the fan and green LED, turn off the red LED
      digitalWrite(relayPin, HIGH);
      digitalWrite(greenLedPin, HIGH);
      digitalWrite(redLedPin, LOW);

      // Record the start time
      startTime = millis();
    } else {
      // Emergency stop
      lcd.clear();
      lcd.print("Emergency Stop");
      delay(1000); // Display message for 1 second
      lcd.clear();
      lcd.print("Press button to");
      lcd.setCursor(0, 1);
      lcd.print("turn on device");

      // Turn off the fan and green LED, turn on the red LED
      digitalWrite(relayPin, LOW);
      digitalWrite(greenLedPin, LOW);
      digitalWrite(redLedPin, HIGH);

      // Ensure no sound notification
      digitalWrite(piezoPin, LOW);
    }
  }

  // If the device is on, calculate the remaining time
  if (deviceOn) {
    unsigned long elapsedTime = millis() - startTime;
    unsigned long remainingTime = runTime - elapsedTime;

    // Update the LCD display with the remaining time
    lcd.setCursor(0, 1); // Move to the second line
    lcd.print("Time left: ");
    lcd.print(remainingTime / 60000); // Display minutes
    lcd.print(" m");

    // Check if the time is up or emergency stop
    if (elapsedTime >= runTime || !deviceOn) {
      // Turn off the fan and green LED, turn on the red LED
      digitalWrite(relayPin, LOW);
      digitalWrite(greenLedPin, LOW);
      digitalWrite(redLedPin, HIGH);

      // Notify with the piezo if the time is up
      if (elapsedTime >= runTime) {
        lcd.clear();
        lcd.print("Process complete");
        for (int i = 0; i < 5; i++) {
          digitalWrite(piezoPin, HIGH);
          delay(500);
          digitalWrite(piezoPin, LOW);
          delay(500);
        }
      }

      // Update the device state
      deviceOn = false;
      lcd.clear();
      lcd.print("Press button to");
      lcd.setCursor(0, 1);
      lcd.print("turn on device");
    }
  }
}

If your project works OK with the 5V relay, I see no need to change it.

Thank you for your help. :smiling_face_with_three_hearts:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.