Arduino, Pca9685 and 16 fans 12v - art installation

Hello,

I've been trying to make small installation to work properly. I've connected 16 fans 12v 2 pins. I'm trying to control them with PCA9685 and Arduino setup. I've connected everything and i works well when i'm trying to send one code to all of them like this:

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

Adafruit_PWMServoDriver pca1(0x40);
Adafruit_PWMServoDriver pca2(0x41);


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

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

}

void loop() {
  pca1.setPin(0, 4095);
  pca1.setPin(1, 4095);
  pca1.setPin(2, 4095);
  pca1.setPin(3, 4095);
  pca1.setPin(4, 4095);
  pca1.setPin(5, 4095);
  pca1.setPin(6, 4095);
  pca1.setPin(7, 4095);
  pca1.setPin(8, 4095);
  pca1.setPin(9, 4095);
  pca1.setPin(10, 4095);
  pca1.setPin(11, 4095);
  pca1.setPin(12, 4095);
  pca1.setPin(13, 4095);
  pca1.setPin(14, 4095);
  pca1.setPin(15, 4095);
}

This works perfectly, all of them start to rotate, everything is as intended. But when i want to add some steps so each fan is starting after certain amount of time, it stops responding at all.

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

Adafruit_PWMServoDriver pca1(0x40);
Adafruit_PWMServoDriver pca2(0x41);

unsigned long t0 = 0;
int step = 0;

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

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

}

void loop() {
  if(step == 0) {
    for(int i = 0; i < 16; i++) pca1.setPin(i,0);
    t0 = millis();
    step = 1;
  }

  if(step == 1 && millis() - t0 >= 5000) {
    pca1.setPin(0, 4095); // fan0 kick-start
    t0 = millis();
    step = 2;
  }

  if(step == 2 && millis() - t0 >= 5000) {
    pca1.setPin(0, 2048); // and then slowing it down. I want to have low rotation.
    t0 = millis();
    step = 3;
  }

  if(step == 3 && millis() - t0 >= 3000) {
    pca1.setPin(1, 4095);
    t0 = millis();
    step = 4;
  }

  if(step == 4 && millis() - t0 >= 5000) {
    pca1.setPin(1, 2048);
    t0 = millis();
    step = 5;
  }

  if(step == 5 && millis() - t0 >= 10000) {
    t0 = millis();
    step = 0;
  }
}

What am i doing wrong? Is it even possible to make sequence like this work on arduino + pca. My whole setup have separate 12v supply, mosfets, condensers, resistors 330 Ohm and 10k Ohm soldered on the PCBs. Like i said, if i put the first code - it works. So i'm not sure if it is hardware issue. I'm not specialist, i'm musician, i can barely code so i guess that’s where the problem lies. I tried to do it with delay(); but with the same results. Whenever i'm adding certain steps it stops working. Thank you for any help!

Welcome, @leonthepeon! Congratulations for posting so nicely, first time out!

Since I don’t see a problem with your code, I suspect your hardware.

If your delay(0 attempt was as simple as

set a given channel to a speed
delay
set the next channel to a speed
delay
etc

Then again, I don’t see a problem, so I suspect your hardware.

Pictures, schematic will be required for further diagnosis there.

Thanks

1 Like

Welcome!

Thanks for reading the guidelines and using code tags!

The odds are high that it is a hardware problem. Determining what the problem is extremely difficult without knowing what you have in the language of electronics an annotated schematic. Also you need to post links to the technical informarion on the hardware you are using. The PCA9685 can be gotten in several different ways, IC level, board name (several of these).

[quote="leonthepeon, post:1, topic:1429631"]

  • Always show us a good schematic of your proposed circuit.
    Show us good images of your ‘actual’ wiring.

By that, do you mean all motors performed perfectly as expected?

Hello,

Thank you replies! I tried my best to draw it, i've recorded even the sample how it works and made a photos. I created a schemat of the circuit in adobe illustrator because i don't have those fancy tools to draw something professionally and to be honest, i can't really do it. I'm classical musician. I'm attaching everything i could do. I've also recorded effects when i uploaded this code (i believe i can't attach here videos, there are on google drive Fans Project - Google Drive although it is probably not necessary to watch them. The noise is zip tie taped to the fan, that is pretty much whole point of the installation):

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

Adafruit_PWMServoDriver pca1(0x40);
Adafruit_PWMServoDriver pca2(0x41); 

unsigned long t0 = 0;
int step = 0;

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

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

  pca2.begin();
  pca2.setPWMFreq(1000);

}

void loop() {
  pca1.setPin(0, 0);
  pca1.setPin(1, 0);
  pca1.setPin(2, 0);
  pca1.setPin(3, 4095);
  pca1.setPin(4, 0);
  pca1.setPin(5, 0);
  pca1.setPin(6, 0);
  pca1.setPin(7, 4095);
  pca1.setPin(8, 0);
  pca1.setPin(9, 0);
  pca1.setPin(10, 0);
  pca1.setPin(11, 0);
  pca1.setPin(12, 0);
  pca1.setPin(13, 0);
  pca1.setPin(14, 0);
  pca1.setPin(15, 0);
}

I wanted those two fans to rotate and it works. Only when i'm trying to do the steps over time it stops responding (i sent 0 to everything else as a demonstration, it is not necessary for it to work). Sorry for the mess in schemat and mess in cables, that is my first project like this with arduino, i was playing on pin board before, so all the soldering and other stuff might look like amateur work but i am one. There was many mistakes in the process, but it the end i kinda works. I can set any fan to rotate at any speed but when i'm trying to make a sequence it becomes a problem. I have 5 pcb like the one on schemat so far. My plan is eventually to have around 50-60 fans rotating. Each pcb control 4 fans. I want to control all 60 of them. It's around 16 on 1 wooden frame, then i want to scale it, make the same setup for different frames but place fans in different way. The LM is to slow down the fans, I tested if it is Voltage issue and i believe it is not, i set 9V and 11V and 12 V and it the same effects. [Edit: Now i've spotted that i didn't sign the transistor on schemat (the black rectangle on "pcb") it is MOSFET IRLZ44N. Sorry about that. Each fan has one of those]



Mosfet i used: ALLECIN IRLZ44N IRLZ44 MOSFET Transistors 47A 55V IRLZ44NPBF Logic Level Mosfets 47 Amp 55 Volt TO-220 (Pack of 10Pcs): Amazon.com: Industrial & Scientific
Capacitor: Tnisesm 20Pcs 100UF 25V Electrolytic Capacitor 100 UF MFD 25 Volt with Aluminum Radial Leads: Amazon.com: Industrial & Scientific
PCA 9685: Amazon.com: PCA9685 16 CH 12Bit PWM Servo Motor Driver Board Controller IIC Interface for Arduino Raspberry Pi Zero/Zero W/Zero WH/2B/3B/3B+ and Robot (2pcs) : Industrial & Scientific

  • Please draw out one of the MOSFET circuits in the last image.
  • Write a diagnostic sketch moving this into setup().
    Then change 4095 to 2048, what happens.
    Run it twice, 4095 and then 2048.

  pca1.setPin(0, 4095);
  pca1.setPin(1, 4095);
  pca1.setPin(2, 4095);
  pca1.setPin(3, 4095);
  pca1.setPin(4, 4095);
  pca1.setPin(5, 4095);
  pca1.setPin(6, 4095);
  pca1.setPin(7, 4095);
  pca1.setPin(8, 4095);
  pca1.setPin(9, 4095);
  pca1.setPin(10, 4095);
  pca1.setPin(11, 4095);
  pca1.setPin(12, 4095);
  pca1.setPin(13, 4095);
  pca1.setPin(14, 4095);
  pca1.setPin(15, 4095);

Here is what i could draw out:



[edit: added photos of the one pcb that i prepared for other fans that are not connected yet]

When i tested code it can slow down, be visibly when i put 100 not 2024. It probably slows down too, but i can't really clearly see it. But if i go super low, like 80-100 here are effects:

  • It appears :roll_eyes: the capacitor is across the motor terminals.
    If so, why ?
    This means the MOSFET will conduct large (short circuit) current when the transistor turns on

  • Going to have to draw this out for you to confirm the circuit . . .

  • Your drawing is confusing. :woozy_face:
    Need to get things clarified.

  • Compare the schematic below to your MOSFET wired circuits.
    Does this schematic match ?

Hmm, I’m not sure. The + of the capacitor is on 12 V, the − is on the MOSFET drain. I believe the gate is correct, and the source is connected to GND. It appears to be the same, but that’s how I placed it on my PCB. I thought it was supposed to go that way, so I soldered 12 V to the drain. It’s probably not logical from an engineer’s point of view, but I have no technical background, so that was the easiest way for me to think about it. Sorry about that.

[Edit: And why capacitor is there - I was working with AI and it suggested me to do it so it provides stability for the fan, i was testing everything on the pin board in the same placement and it was working so i started soldering it. There is not much more explanation i can give you :grimacing:, sorry]

  • Wish you had consulted us first.
    Your circuit should look like this, no capacitor.
220R should be 330R

So, just to clarify: should I change the capacitor to a diode? Could you explain why this would solve the issue of the delay/sequence not working? What type of diode should be used?

  • A capacitor initially behaves like a short circuit when it is first connected to a voltage source. In this case, that means the MOSFET briefly connects +12 V directly to ground each time it turns on.

  • At a PWM frequency of 1000 Hz, the MOSFET is effectively shorting +12 V to ground 1000 times per second.

  • While capacitors can be used to suppress electrical noise from motors, in a circuit like yours the value should be reduced from 100 µF to 0.1 µF—a reduction by a factor of 1000.

  • If the fan generates any kickback voltage when the MOSFET turns off, adding a diode will eliminate it. A 1N400X series diode (for example, a 1N4007) is suitable. This diode must be connected with the banded end (cathode) to +12 V and the anode to the MOSFET drain.

  • When we help people with projects like this, we take a holistic approach and look for both hardware and software issues. While these circuit changes alone may not fully resolve your problem, they are essential and should be implemented regardless.


  • So others can chime in, believe this represents what you are doing.
  • Please confirm the following.
    • Fans are powered by 9V or 12V ?
    • How is the Arduino getting its 5V power ?




Edit:

  • It's a bit late now but you might find this informative:

Yes, I believe it is really close. I’m powering the PCA VCC with an additional 5V power supply because I was planning to operate 5V motors later on, and I was also planning to use several PCAs connected in a row - 5 in total, so i thought i can just connect them to stronger power supply than arduino. Mega is getting a 12V power supply from the external power input.

The fans are supposed to run at 12V, but my goal was to slow them down as much as possible because I wanted a slow rotation to create rhythmic patterns while the fans are rotating. So I lowered the 12V to 9V using an LM2596. Is this also wrong? Since the whole hardware setup might be wrong, maybe lowering the voltage is not required - or maybe it was a wrong idea from the beginning? I don’t care about fan lifespan, as you might notice, I cut out some of the fan blades so that when they hit the zip tie, they create rhythmic groups.

On your drawing there is no capacitor, even the 0.1 µF. Would just not included it at all? Generally seems fixable, or at least i believe so!

Thanks for the links and help, promise to clean soldering flux with IPA in the future!

  • The whole idea of PWM is to adjust the duty cycle (D.C.) in software.
    This will slow or increase the motors speed.
    If the motor are rated at 12V, use 12V.

Frequency is constant 1000Hz; it’s the D.C. that adjusts the motor's speed.

  • Suggest you omit the 0.1uF capacitor.

This should be more accurate:

Important

  • Make sure the motor's +12V connections and the MOSFET's source's GND connections are star configured (connected right at the 12V power supply terminals.
  • Give use a LINK to the fans you are using.

Alright, I’ll try to fix the hardware in the coming days using your advice. Thank you. If I encounter more problems (and most likely I will), I’ll continue replying in this thread. Thanks once again.

Link to the fans: Amazon.com: DS White 120MM PC Case Fans, 37CFM High Performance Cooling, 19.89dBA Low Noise, Hydraulic Bearing for Computer Case Full Tower Mid Tower (6Pack PC Fan Kit) : Electronics

[Edit: My idea of slowing it down was exactly that - duty cycle is percentage. If i lower down voltage, the maximum number of RPM is reduced, therefore i can slow the fans even more, which was my goal. I wanted to be able to listen each blade hitting zip tie, not zip tie bouncing really fast. I'm not sure if my explanation make sense.]

  • Looks like the fans are 12V 6W.
    Therefore 500mA running current.

  • You must size the 12V power supply to handle all the fans that you have running.

I'm using this one: Amazon.com: 50A 600W 12V DC Power Supply, Universal Regulated Switching AC 110V/220V to DC Converter (SMPS) Transformer Driver Adapter for LED Strip Lights, CCTV Camera System, 3D Printer, Radio, Computer Project : Electronics