Use 4 channel relay logic output to Arduino input

Hi, I plan to build an speed controller for PWM driven 12v fan using a ZigBee 4 Channel Relay Switch (Zigbee 4 channel relay) and an Arduino Uno or Nano.

The idea is using the Arduino to control the fan through PWM, the speed of the fan will be adjusted using 4 input pins, combining HIGH and LOW values to make up to 16 speed levels. A possible code for this would be this (thanks to ChatGPT BTW)

// Define the PWM values for each input combination
int pwmValues[] = {0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240};

// Read the input pins
int input1 = digitalRead(pin1);
int input2 = digitalRead(pin2);
int input3 = digitalRead(pin3);
int input4 = digitalRead(pin4);

// Determine which combination of inputs is being used and set the PWM value accordingly
int inputCombination = input1 + input2 * 2 + input3 * 4 + input4 * 8; // Convert binary input to decimal
int pwmValue = pwmValues[inputCombination];
analogWrite(outputPin, pwmValue); // set PWM value to the corresponding value in the array

The 4 pin input will be connected to the zigbee 4 channel module, so I will be able to control the speed of the fan remotelly turning ON or OFF each channel.

My main concern is how to connect the 4ch module with arduino.

First and easy aproach would be simply using the relay, connecting the COM to arduino pin and attach GND to NC and 5V to NO, so when the relay is open the pin will receive LOW and otherwise will receive HIGH.

Another aproach I've been thinking is to de-solder the relays and use the logical signal to the relay directly to arduino (in order to avoid hearing the ticks of the relays when they changes of state), but here is where I get lost. The relay has 2 logical inputs, when the relay is ON, there's a 5V difference between those 2 contacts, when it's OFF there's no V difference, buf I haven't found which one is GND or 5V. It seems that the relay is open when no V difference between contacts and closed when there's a 5V between contacts.

I haven't found the schematics for my module, but I found this on internet, which I think it's similar of the one I have:

Any ideas of how to connect this 4ch relay module to Arduino using the module logical signal, avoiding the relays?

Thanks in advance.

That’s a great reason why most people won’t help you.

The schematic offered is not even close to your module.

You will not have luck using a relay and PWM combination.

1 Like

I don't understand the purpose of the relays.  Are they to provide a logic signal to the Arduino as part of the speed select?  What operates the relays, switches?

You can use just two relay contacts (either COM and NO or COM and NC) like a regular on-off switch. Ground one contact and connect the to the Arduino. Enable the Arduino's built-in pull-up resistor and when the contacts are closed the pull-up will be "overpowered" and the input will read low.

This example shows a regular switch.

If it's 5V logic and you have a common ground you can make direct connections.

Or you can use an optical isolator, and probably the isolator from your relay module. Again, with the built-in pull-up (or an internal or external pull-up or pull-down resistor).

Hi!

The circuit to control fan speed can be like this:

Here the start point to learn how to control fan speed.

/*
  Fade

  This example shows how to fade an LED on pin 9 using the analogWrite()
  function.

  The analogWrite() function uses PWM, so if you want to change the pin you're
  using, be sure to use another PWM capable pin. On most Arduino, the PWM pins
  are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade
*/

int led = 9;         // the PWM pin the LED is attached to
int brightness = 0;  // how bright the LED is
int fadeAmount = 5;  // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

Best regards.

Hi, thanks all for your replies.

The idea, as I said (maybe I don't explain very well in english), is to control arduino remotely using a 4 relay board as proxy. The way to tell arduino which fan speed to set is "coding" different levels of speed using the 4 relays signals. Think in binary code, you have 4 bits one for each relay, 0=OFF, 1=ON, so you can code up to 16 different words, one assigned to each speed level. From 0000 = speed: 0 to 1111 = speed: 255.

But first I had to "communicate" the module with arduino through 4 input pins. My question was if I could do it without the relays, using the signal TO the relays. I found the solution, posted at the end.

FernandoGarcia, to control a 12V PC fan you need to trick arduino, because you must use a 25kHz signal. Look at https://projecthub.arduino.cc/tylerpeppy/b5618d48-7ae8-4fc0-bca5-a857c36fcc5e

DVDdoug Thanks to your ideas, I found the solution. I removed one relay and connected both 4ch module and arduino grounds. Then I connected one of the input pins of the relay directly to an arduino input and it received 5V signal when on and 0V when off. The other relay input pin was conencted to 5V, so I simply don't use it.

Thanks.

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