Burning up Arduinos trying to control 12v pwm fan with 24v ground signal on 3d printer

I have burnt up a hand full of Arduino Nanos, most of which weren't authentic, trying to figure this out and I am tired of my failed efforts to do so. I am reaching out the the community hoping that someone could help me. I am hoping that it is as simple as adding a diode or something like that but I just need a little guidance.


I have been trying to follow a "guide" [Ender 3 v2 silent fan upgrade][Youtube video where he talks about the wiring] on upgrading the fans on my Ender 3 v2 and everything has worked other than the part when it comes to the PWM part cooling fan being controlled by an Arduino Nano. I believe that I have everything wired up correctly and the code looks good to me. Some people even claim that it worked great for them and for a moment with a fresh Nano it'll work for me... but then it stops working and once I have everything off and touch the Nano it is hot.

The provided wiring diagram from the "guide":

The provided code:

const byte OC1A_PIN = 9; // PWM pin wire to fan
const int inputPin = 4; //sense wire from printer neg fan wire
const word PWM_FREQ_HZ = 25000; //Adjust this value to adjust the frequency
const word TCNT1_TOP = 16000000 / (2 * PWM_FREQ_HZ);

int inputValue = 0;  
unsigned long fanFull = 50;
unsigned long fanSpeed = 0;
unsigned long durationHigh = 0;
int durationHighms = 0;
unsigned long durationLow = 0;
int durationLowms = 0;
int durationTotal = 0;
float durationPeriod = 0;
int dutyCycle = 0;

void setup() {
  Serial.begin(115200); //enable the serial monitor

  pinMode(OC1A_PIN, OUTPUT); //set the output pwm pin
  pinMode(inputPin, INPUT_PULLUP); //set the input voltage divider sense pin. 
  
  // Register magic to output at 25KHz
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
  TCCR1A |= (1 << COM1A1) | (1 << WGM11);
  TCCR1B |= (1 << WGM13) | (1 << CS10);
  ICR1 = TCNT1_TOP;
  Serial.println("Setup completed");
}

void loop()
{
  durationHigh = pulseIn(inputPin, LOW, 1000000);
  durationLow = pulseIn(inputPin, HIGH, 1000000);

  inputValue = digitalRead(inputPin);
  Serial.print(inputValue); //display input voltage as a duty cycle scaled across 25v
  Serial.println(" - inputValue");

  if (durationHigh == 0 && inputValue == LOW) {
    Serial.println("input full");
    fanFull = 100;
  }

  if (durationHigh |= 0) {
    Serial.println("input pulse");
    fanFull = 0;
  }

  if (durationHigh == 0 && inputValue == HIGH) {
    Serial.println("input zero");
    fanFull = 0;
  }

  durationHighms = durationHigh / 1000;
  durationLowms = durationLow / 1000;
  durationTotal = durationHighms + durationLowms;
  durationPeriod = float(durationHighms) / float(durationTotal);
  dutyCycle = durationPeriod * 100;
  fanSpeed = fanFull + dutyCycle;

  //Serial.print(fanSpeed);
  //Serial.println(" - FanSpeed");
  setPwmDuty(fanSpeed);
  
 /* Serial.print(durationHigh); //display input voltage as a duty cycle scaled across 25v
  Serial.println(" - DurationHigh");

  Serial.print(durationHighms); //display input voltage as a duty cycle scaled across 25v
  Serial.println(" - DurationHighMs");

  Serial.print(durationLow); //display input voltage as a duty cycle scaled across 25v
  Serial.println(" - DurationLow");

  Serial.print(durationLowms); //display input voltage as a duty cycle scaled across 25v
  Serial.println(" - DurationLowMs");

  Serial.print(durationTotal);
  Serial.println(" - Duration Total");

  Serial.print(durationPeriod);
  Serial.println(" - duration period");

  Serial.print(dutyCycle);
  Serial.println(" - duty cycle");

  Serial.print(fanFull);
  Serial.println(" - Fan Full");

  Serial.print(fanSpeed); //display input voltage as a duty cycle scaled across 25v
  Serial.println(" - Duty Cycle");

  Serial.print(fanSpeed);
  Serial.println(" - Fan Speed");
  Serial.println();*/

 // delay(10);
}

void setPwmDuty(byte duty) {
  /*Serial.print(duty);
  Serial.println(" - duty");
  Serial.print(TCNT1_TOP);
  Serial.println(" - TCNT1_TOP");*/

  OCR1A = (word) (duty * TCNT1_TOP) / 100;
  //Serial.print(OCR1A);
  //Serial.println(" - OCR1A");
}



This is how I have the PWM fan and Nano part of this hooked up currently and I am waiting to get another Nano as I type this.

I believe that is issue with the wire which runs from the negative terminal on the 3d printer mobo fan plug to D4 on the Nano and that there is no protection against negative voltages. When I put a multimeter along that gray dashed line I'm getting -22v. I am thinking if I add a diode [fan plug----|<--- D4] that should be fix things but I am not confident in that as the answer with the little bit of knowledge that I have. I am hoping that one of you all could give a little input on if this is the fix or not. Or what the fix would be.

Thank you for any help!

This image appears to feed 12V(?) into the 3.3V output pin of the Nano.

Yes I noticed that as well and did not do that. I have 12v going into the VIN not the 3.3V.. in that diagram I think it was more to generally demonstrate how the wires should run not the actual pins they should go into.

why you not control fan with 3d pr mo bo?
grafik

1 Like

it is not what the Nano is invented for

1 Like

like pwm comes from the ground pin?
I'd not pursue anything so badly documented.

image

2 Likes

Why are you taking the measurement with +12v as the reference?
Are you using the exact same voltage regulator as the original circuit, almost sounds like you do not have a common ground reference between the printer motherboard and the Nano.

I would expect the fan connection at the printer motherboard to have +24V on the red pin, with the black pin being the open end of a transistor being used to switch the ground, so the only voltage on the black pin is being supplied by the internal pull-up in the Nano. A schematic would be needed to be sure (or direct examination of the motherboard).

Safest thing would be to use an opto-coupler between the fan plug of the printer motherboard and the Nano.

Disconnect from nano and measure voltage between printer GND and fan connector GND when fan is set off.
3dPrinter PWM Fan Wiring

It sure isn't and that's why I'm not hooking anything back up until I get this figured out so I don't waste any more Nanos

Ya it is my understanding from what I have read that

the pwm signal from the mainboard is just switching on and off the ground connection and is supplying constant 24V,


Ya when I first read that "guide" it made sense and seemed like it'd work fine but I suppose I only know enough to get myself into trouble and not to keep myself out of this situation.

I don't have an answer for that. My only thought I have seen some posts that suggests that the fan will not kick on under 40%. But I am sure that this could work. I assume that if a PWM fan is only hooked up to 12v and GND it will run at 100%, is that correct? Also is that a npn/pnp transistor and resistor in your diagram?

When the fan is set to off it's getting 22.64V
When it is set to 100% it gets 0V.

So it has pullup to 24V. Not good for arduino, right?
Use optocoupler or even circuit on post#4

I was actually measuring across the -12v and -24v of the fan header on the 3d printer. I did that because I figured that could be a good nubmer to know seeing that it is was the Nano is hooked up to.

I do not believe that I have a common ground. With you asking I assume that I should. To achieve that would I have the GND from the Nano or the -12v from the buck converter go to the ground on the printer motherboard?

I'm not using the exact same buck converter as what is in the "guide" but it is a LM2596S like what is suggested.

That is kind of my understanding as well but I am not sure if it done via a transistor or maybe a MOSFET. But it is my understanding that it is the ground is getting switched on and off the control what was a 24v fan.

The printer motherboard is just a Creality v4.2.7 I'm sure I could find you the schematic if you'd like.

I do believe that you are right that opto-coupler would be the safest route.

It's getting switched between GND and 24V pullup.

you picture fan plug with only 2 pins, so you cannot use 3pin fan. normally 3pin fan gives RPM on the third wire, only 4pin fans have additional to tacho wire PWM pin.
so, if you don't want to buy 24V fan, you can:
connect a relay module where is 12V fan connected instead of relay itself. optoisolator current must be adjusted to 24V.
or
using schematic from post #4. resitor can be placed on lower wire(GND) when common ground is issue.

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