Arduino, Pca9685 and 16 fans 12v - art installation

  • PWM does not lower the voltage.
    PWM turns ON then OFF the voltage to your fan.

  • Like turning ON a light for 1 second then OFF for 4 seconds
    OR
    ON for 2 seconds and OFF for 3 seconds; the total is always 5 seconds.
    PMW is much faster :smiling_face_with_sunglasses:

  • 50 Amps means you must supply fuses to each bank of X number of fans.
    Fuses are to be placed at the power supply terminals !
    • Example: 6 fans can use the same fuse, 6 * 500mA = 3 amp, use a 4 amp fuse.
    • Suggest the Arduino Mega 12V connection at Vin have its own fuse @ 1 Amp.

  • You must select the correct wire gauge for the currents that flows.

What I meant is that these fans are rated at 1000 RPM, so if I lower the voltage, their maximum speed will be around 700–800 RPM. That means I’m operating within a range of 0–800 rather than 0–1000. That’s why I added an LM2596 to each PCB board (each of which controls four fans). During my tests, I noticed that when the PWM is too low, the fans sometimes simply stop or don’t have enough voltage to spin. For example, when I set

pca1.setPin(0, 20);

My thinking was that in such cases I could just lower the supply voltage, allowing me to reach even lower RPMs. This is a sound-based installation, so the number of hits against the zip tie was important to me.

But since you suggest than i should just skip it, then i will do it. It is less work i guess.

I was using this BusBar: Amazon.com: RVBOATPAT Power Distribution Block 12V 150A 1/4" Stud Marine Bus Bar 12 Volt DC Battery Busbar for Boat Automotive Solar Wiring : Electronics

And I connected each PCB with its own wire. I guess i can add fuses there?

Arduino is connected separately with this: 12V Power Supply, 12 Volt 2A 24W DC Power Supply with On Off Switch, Black Switching LED Power Adapter, AC 110V to 12V Wall Wart Transformer Plug for LED Strip Lights with 5.5/2.1 DC Female Connector - Amazon.com

It is not using the same power supply as fans. It was easier for me to just connect it the power outlet in the wall like this.

[Edit: Yes, i'm using 14 AWG to connect from 12 V Power Supply to BusBar and 18 AWG wire to each PCB. Busbar has 16 fans right now, so i guess i'm in a safe range]

  • No, the fans are rated at 12V.
    Goggle and read about PWM Motor control

  • I think you are very confused.

    • In the code below, you are setting the PWM frequency to 1000Hz.
      Hence the waveform will repeat every 1 millisecond, your software adjusts the Duty Cycle
      pca2.setPWMFreq(1000);

pca1.setPin(0, 20);

  • 0 (Channel): Specifies the pin/channel on the PCA9685 module (0-15).
  • 20 (Value): Represents the PWM value, often in a 12-bit range (0–4095).
  • Result: This sets a very low duty cycle on channel 0

Oh, okay. That makes more sense. So i was trying to lower voltage but PWM is already lowering average power delivery. So in fact i was lowering it twice?

Yes, this i understand and i believe i was doing correctly.

  • If you have further questions ask . . .

PCA9685 Duty Cycle Calculation

To determine the duty cycle, we need to look at how the PCA9685 handles its 12-bit resolution.

The PCA9685 divides each PWM cycle into 4096 steps (from 0 to 4095). When you use the setPin(pin, value) function in most common libraries (like the Adafruit PWM Servo Driver library), the "value" represents the "ON" time in terms of these steps, assuming the pulse starts at 0.

The Calculation

pca1.setPin(0, 20);
The duty cycle is the ratio of the "ON" time to the total cycle length.

  • Resolution: 4096 steps
  • Set Value: 20
  • Formula: Duty Cycle = (value/4096) * 100 ≈ 0.5%
    Freq = 1000Hz
    Motor on time = 0.001 * 0.005 = 0.000005 seconds.

Okay, i feel like i'm starting to get it. Thank you. It's hard to say if the result with the fans that i received could be any references point. I will try to fix it. Thank you!


#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pca1 = Adafruit_PWMServoDriver();

//Adafruit_PWMServoDriver pca1(0x40);  // <------<<<<< Change as needed.

void setup() 
{
  pca1.begin();
  pca1.setPWMFreq(200); // 200Hz
}

void loop() 
{
  // Set pin 0 to 25% duty cycle.
  pca1.setPin(0, 1024);

  delay(1000);

  // Set pin 0 to 50% duty cycle.
  pca1.setPin(0, 2048);

  delay(1000);

  // Set pin 0 to 100% duty cycle.
  pca1.setPin(0, 4095);

  delay(1000);
}

  • Try the above code, what do you observe ?



  • Now try the code below, what do you observe ?
    • Then make this change:
      • for(unsigned int x = 0; x < 512; x++)
    • Then:
      • for(unsigned int x = 0; x < 257; x++)
//=========================================

#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pca1 = Adafruit_PWMServoDriver();

//Adafruit_PWMServoDriver pca1(0x40);  // <------<<<<< Change as needed.

//=========================================
void setup() 
{
  pca1.begin();
  pca1.setPWMFreq(100); //100Hz
  
}

//=========================================
void loop() 
{
  for(unsigned int x = 0; x < 2048; x++)
  {
      pca1.setPin(0, x);
      delay(4);
  }
 
}

They are DC brushless fans, so you won't be able to control the speed using PWM.
You should have bought the fans with 3 or 4 wires.

  • The last sketch in post #28 will prove if the OP can adjust the speed of their fan.

  • Using PWM and a MOSFET on a 2 wire brushless fan can damage the internal circuit capacitors, the OP said longevity is not an issue.

  • Need to settle on the PWM frequency and the effective duty cycle range that works for this selected fan.

I have tried both codes but unfortunately the fan is not responding to either of them. I cannot see any movement or indication that the fan are getting signal.

I double check after powering it up again if they react to this code (to make sure that everything is connected and responds to arduino):

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pca1(0x40);

void setup() {
  Serial.begin(115200);
  Wire.begin();

  pca1.begin();
  pca1.setPWMFreq(1000);

}

void loop() {
  pca1.setPin(0, 4095);
}

And it does normally.

  • That sounds like we are worse off today :frowning:

  • Place a LED from the output 0 pin to Arduino GND.
    Do you see the LED light up ?

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pca1(0x40);

//=======================================
void setup()
{
  Serial.begin(115200);
  Wire.begin();
  pca1.begin();
  pca1.setPWMFreq(1000);
}

//=======================================
void loop()
{
  pca1.setPin(0, 4095);
  delay(1000);
  pca1.setPin(0, 0);
  delay(1000);  
}

It doesn't work sadly with your code.

But when i just turn it on to check if connection works, it did work:

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pca1(0x40);

//=======================================
void setup()
{
  Serial.begin(115200);
  Wire.begin();
  pca1.begin();
  pca1.setPWMFreq(1000);
}

//=======================================
void loop()
{
  pca1.setPin(0, 4095); 
}

I'm clueless.

[Edit: The whole construction is at my university where I study. If there are more ideas, I’ll be able to try them tomorrow evening, because I’m heading home now to prepare for tomorrow’s lectures. Thank you Larry for your help!}

Also, check that it is not installed backwards !

Yes, this is the connection to the second PCA9685. These not connected pins are V+ and VCC. I am powering VCC directly from a 5 V power supply, not from the Arduino. Each PCA9685 is supplied separately, so there is an additional power cable from the 5 V power supply to the second PCA as well. GND is common for PCA, Arduino and 5V. This GND is also connected with GND that deals with fans. So i have two BusBars that i posted before, one for 5V and one for 12V. Those two GND are connected too, when i was working with Ai it suggested me to do it, is it wrong?

Do you mean if cables of 6pin wires are not connected backward? I believe it was correct and it was working. I'm writing on my phone, but i will double check tomorrow.

[Edit: Wait, now i've spotted that i'm wrong. Let me go back to University and check it, because i will not be able to sleep well today.]

You are a genius Larry. It was inverted, was supossed to omit VCC and V+ not GND na OE. Now everything works. Fans work too. My God, i wasted 8 days trying to figure it out. Thank you!

1 Like

:clap::+1:t3::zany_face:. Perfect

  • Glad you have it working. :+1:

  • Still don't fully understand how you have things wired.
    It is necessary the Arduino, and two PCA9685s be powered from the same source.

  • Highly recommended you wire the 3 PCBs as per the schematic below !

EDIT

  • Made minor changes to the schematic.

I see, I believe that makes things much easier. I will change it then.

I was also planning to use those motors:
3V~6V 130 DC Toy Motor DIY

I was using a 5V power supply because I was planning to eventually connect these motors to PWM as well, I've read that if there are many PCA connected in the row it's better to get external power supply. I was also planning to use a similar setup to the one I currently use for 12V fans. The idea was to copy the same MOSFETs and the same resistors, but without the capacitors.

Is it correct to use a similar setup for these motors? Can I use the same Arduino Mega to control them, or should I use a second Arduino?

  • Your link to the 3-6v motors does not work.