4 wire fan speed control

It's not the cable, I'm aware of the power only ones. I have a nano every that uses the same cable and it works fine. The last time I used the teensy I had a windows 7 PC, as I recall the teensy showed up in the boards manager even with no board connected. I did get this 1,8 from the Arduino site should I have gotten the admin one? would an older one work? Not sure why it shows up on the 1.8 but says only works on 2.x or higher and yet it doesn't show up on 2.x version.
Anyway I have use for several of these fans if I can get the code to work. If a Teensy 3.2 would work I would buy a few more.
 

Attachments

  • DSCN24.jpg
    DSCN24.jpg
    199.7 KB · Views: 16
  • Screenshot 2024-12-15 122218.png
    Screenshot 2024-12-15 122218.png
    42.8 KB · Views: 15
Last edited:
I did get this 1,8 from the Arduino site should I have gotten the admin one? would an older one work?

If using Arduino IDE 1.8.x, get 1.8.19 (the last of the 1.8 releases). Do not use 1.8.18.

Only 6 specific 1.8.x versions are supported. 1.8.18 is NOT one of them,

1734307840214.png


When you run the installer program, it also clearly says which versions of Arduino IDE it supports on the first page:

1734308337301.png




Not sure why it shows up on the 1.8 but says only works on 2.x or higher and yet it doesn't show up on 2.x version.

Again, as I tried to explain in msg #24 and Defragster said in msg #25 and is documented clearly on the download page, you need to click File > Preferences in Arduino IDE 2.x.x and add the Teensy URL.

The URL is https://www.pjrc.com/teensy/package_teensy_index.json

1734308104642.png


You MUST add this URL first. Then with the URL in place, Teensy will appear in Arduino IDE 2.3.4 Boards Manager. Without this URL, Arduino IDE 2.3.x can not know where to find the info for Teensy.
 
The first screenshot is of the 1.8x the dropdown menu gives these options,

select version
1.58.2
1.57.3
1.56.2
0.60.1
I used the URL you said . Teensy does not show up in the list of boards. It used to on my old PC

The second screenshot is of the 2.xx version there is no where or way to paste the URL
 

Attachments

  • Screenshot 2024-12-15 181052.png
    Screenshot 2024-12-15 181052.png
    16.5 KB · Views: 14
  • pref.png
    pref.png
    35.8 KB · Views: 19
Last edited:
For IDE 2.x the scroll bar on the preferences can be very slight on the edge - scroll down to add the URL. Seems that was documented on the install page as it was a common issue.

For IDE 1.8.19 once that supported version is installed. Close the IDE and run the TeensyDuino installer and point it to the location the IDE was installed. Before IDE 2.0 the Board Manager does not Teensy install options for the current boards.
 
I was finally able to find a 1.8.19 download, I had to dig for it. On the Arduino site the next available version is 1.8.18 is that coincidence? So I got it working on the windows 10 PC but not the windows 11 with the 2.0. the box that appears when I hit preferences has no options to paste URL nor can I find any place to.
 

Attachments

  • Screenshot 2024-12-15 184034.png
    Screenshot 2024-12-15 184034.png
    36.8 KB · Views: 10
  • Screenshot 2024-12-16 095836.png
    Screenshot 2024-12-16 095836.png
    68 KB · Views: 11
the box that appears when I hit preferences has no options to paste URL nor can I find any place to.
It's hidden below the bottom of the dialog box, you need to scroll down. Due to windows 11 being stupid, it doesn't show the vertical scroll bar / auto-hides it.

index.php
 
I've tried clicking all over that box there is no scroll bar on mine. Should I have installed as admin.?
 
I've tried clicking all over that box there is no scroll bar on mine. Should I have installed as admin.?
Try clicking on the "Auto save" checkbox (make sure to leave it in the desired CHECKED/UNCHECKED mode before moving on), then hit the TAB key twice. I see from your earlier screen capture that you can't even see the "Auto save" check box, so instead, try clicking on the "Verify code after upload" checkbox (make sure to leave it in the desired CHECK/UNCHECKED mode before moving on), then hit the TAB key three times. Does that get you to the URL entry box ??

Mark J Culross
KD5RXT
 
Last edited:
Thinking outside of the box . . . glad you were able to succeed !! Now to select the proper Teensy & get back to your original pursuit !! Good luck !!

Mark J Culross
KD5RXT
 
Does your mouse have a scroll wheel?

Or can you click and drag the corner of the window to make it larger, so all the info is visible without scrolling?
 
The URL option seems to have magickly appeared, there still is no scroll bar on mine and no the box doesn't expand. Anyway I've moved on, I was able to upload the sketch on both the 3.6 and the 3.2 boards, unfortunately I've used up all my time for this project. I ordered a new fan, should get it in a week or so, try again then.
 

Attachments

  • Screenshot 2024-12-15 171747.png
    Screenshot 2024-12-15 171747.png
    80.3 KB · Views: 12
  • Screenshot 2024-12-16 145507.png
    Screenshot 2024-12-16 145507.png
    81.1 KB · Views: 13
I tried this code, when I connect the fan as in the photo the potentiometer does nothing, It just runs full speed. Any idea what's wrong? I'm using a Teensy 3.2

Code:
[code]
const int fan_control_pin = 9;  // Blue Wire on fan (about 25kHz PWM)
volatile int count = 0;
unsigned long start_time;
int rpm;

void setup() {
  analogWriteFrequency(fan_control_pin, 25000);
  analogWrite(fan_control_pin, 0);
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), counter, RISING);  // Yellow Wire
}

void loop() {
  for (int pwm = 0; pwm <= 255; pwm += 51) {
    analogWrite(fan_control_pin, pwm);
    delay(2000); // ?? time for fan to change speed ??
    start_time = millis();
    count = 0;
    while ((millis() - start_time) < 1000) {
    }
    rpm = count * 30;  //60/2
    Serial.print("PWM = ");
    Serial.print(map(pwm, 0, 255, 0, 100));
    Serial.print(" % , speed = ");
    Serial.print(rpm);
    Serial.println(" rpm");
  }
}
void counter() {
  count++;
}
[/CODE]

fan.png
 
Last edited:
The first step is to define how you are going to power the fan. For safety, it is convenient that you can turn it off or on at any time. To do this you can use a relay board, there are 2, 4, or 8, depending on what you want to connect. There are already relay boards that work with 3.3V. Apparently you already have a 12V power supply.

I would suggest using an ILI9341 touch screen, so that you can monitor your controller in real time. You can use a teensy pin to control the operation of the relay. In the always disconnected area of the relay you insert the 12 line from the source and the 12V power line from the fan. With a touch button on the TFT you can activate the relay.

You can use the touch TFT instead of the potentiometer and directly manipulate the PWM value with which the fan will be controlled, either through fixed values, established in buttons or through a slider designed in the TFT.
 
The relay is just a switch for the power supplied to the fan. This is the simplest example I can reduce the controller I built to:

Code:
int PINRELEFan1 =   39;//    Fan1 PWM
int PWMControlFan1= 33;//    Fan1 Rele
int SALIDAPWMFan1 = 1; //   RPM base = 759 RPM, Noctua NF-F12 industrialPPC- 3000 PWM

void setup() {
  pinMode(PINRELEFan1, OUTPUT);
  digitalWrite(PINRELEFan1, HIGH);  //RELE off
  pinMode(PWMControlFan1, OUTPUT);  //PWM pin

  digitalWrite(PINRELEFan1, LOW);   //RELE on
  analogWrite(PWMControlFan1, SALIDAPWMFan1);  //1-255
}
void loop(){}

The full version is somewhat more complex, since the control can be achieved with the slider on the TFT, I leave the complete example, using a 5" FT813 NHD TFT with a teensy 4.1, controlling an NF-F12 industrialPPC-3000 fan PWM

ControlPWM.jpg
 

Attachments

  • ControlFanV0_0.zip
    4.4 KB · Views: 9
Last edited:
I tried this code, when I connect the fan as in the photo the potentiometer does nothing, It just runs full speed. Any idea what's wrong?

The program doesn't have analogRead() to read the pot, so it can't possibly have any effect.

But the program does vary the speed from slow to fast. If the fan spins at a constant speed, then something about the hardware is wrong. Maybe if you show us actual photos of how you connected everything we might be able to notice something wrong. From only the diagram in msg #39 (not an actual photo) I really don't see what the problem could be. A real photo, or multiple photos from different angles if needed to really show the wiring, would let us see the hardware. If something is connected wrong, we're much better on this forum at guessing the hardware problem when we're able to actually see the wires.
 
The program doesn't have analogRead() to read the pot, so it can't possibly have any effect.

But the program does vary the speed from slow to fast. If the fan spins at a constant speed, then something about the hardware is wrong. Maybe if you show us actual photos of how you connected everything we might be able to notice something wrong. From only the diagram in msg #39 (not an actual photo) I really don't see what the problem could be. A real photo, or multiple photos from different angles if needed to really show the wiring, would let us see the hardware. If something is connected wrong, we're much better on this forum at guessing the hardware problem when we're able to actually see the wires.
Thanks, I can do it tomorrow. I got this fan used and the wires aren't colored. I was able to determine the 12v and GND pins but it is possible the other 2 are wrong. The fan runs with just the 12v and GND connected.
 
The board is wired like the diagram in #39 except the 12v and GND are reversed. There is conflicting info. online. I have a couple more fans ordered that have colored wires. In the mean time if I fry something it's not the end of the world.
 

Attachments

  • DSCN.JPG
    DSCN.JPG
    289.6 KB · Views: 10
  • DSCN2.JPG
    DSCN2.JPG
    321.2 KB · Views: 12
Last edited:
I don't see a USB cable (or any other way for Teensy to receive power) in your photo.

Do you have a voltmeter? Can you measure the 5V power? Connect red lead to 5V, black lead to GND.

If the fan is getting 12V power, but Teensy is unpowered, then obviously Teensy could not have any control over the fan speed.
 
Oh, I thought it got power from the yellow wire. I connected the power only cord to the Teensy and now the fan cycles from slow to full speed about every 5 seconds. No effect with the pot.
 
Post your most recent sketch. Your previously posted sketches did not have any calls to analogRead() like would be expected if you were wanting to read a value from a pot using an analog pin as input, or have I misunderstood what you are actually trying to do ??

Mark J Culross
KD5RXT
 
Post your most recent sketch. Your previously posted sketches did not have any calls to analogRead() like would be expected if you were wanting to read a value from a pot using an analog pin as input, or have I misunderstood what you are actually trying to do ??

Mark J Culross
KD5RXT
I really don't know how to write code for these things at all. I just want to control the fan speed with the pot.

Code:
const int fan_control_pin = 9;  // Blue Wire on fan (about 25kHz PWM)
volatile int count = 0;
unsigned long start_time;
int rpm;
int analogPin = A3; // potentiometer wiper (middle terminal) connected to analog pin 3
                    // outside leads to ground and +5V
int val = 0;  // variable to store the value read

void setup() {
  Serial.begin(9600);           //  setup serial
}

void loop() {
  val = analogRead(analogPin);  // read the input pin
  Serial.println(val);          // debug value
}

void setup() {
  analogWriteFrequency(fan_control_pin, 25000);
  analogWrite(fan_control_pin, 0);
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), counter, RISING);  // Yellow Wire
}

void loop() {
  for (int pwm = 0; pwm <= 255; pwm += 51) {
    analogWrite(fan_control_pin, pwm);
    delay(2000); // ?? time for fan to change speed ??
    start_time = millis();
    count = 0;
    while ((millis() - start_time) < 1000) {
    }
    rpm = count * 30;  //60/2
    Serial.print("PWM = ");
    Serial.print(map(pwm, 0, 255, 0, 100));
    Serial.print(" % , speed = ");
    Serial.print(rpm);
    Serial.println(" rpm");
  }
}
void counter() {
  count++;
}
 
Last edited:
Back
Top