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.