4 wire fan speed control

I connected the power only cord to the Teensy

Is that the 12V power line? (please remember, we can't see what you've actually done without a new photo)

Officially, maximum voltage for Teensy power is 6V. Unofficially, Teensy 3.2 can handle higher, but 12V is really risky.

Also be extremely careful if the VUSB-VIN pads have not been cut apart. If you ever plug a USB cable in while the 12V power is connected to VIN, you could cause 12V to feed back into your computer... very likely causing damage to your USB port or even the whole computer!

Using more than 5V on VIN is pretty risky.
 
Is that the 12V power line? (please remember, we can't see what you've actually done without a new photo)

Officially, maximum voltage for Teensy power is 6V. Unofficially, Teensy 3.2 can handle higher, but 12V is really risky.

Also be extremely careful if the VUSB-VIN pads have not been cut apart. If you ever plug a USB cable in while the 12V power is connected to VIN, you could cause 12V to feed back into your computer... very likely causing damage to your USB port or even the whole computer!

Using more than 5V on VIN is pretty risky.
No, see post #40 I'm using a power only cord for the Teensy, it's plugged into a wall wort. I was trying to figure how to add the analog write. It's cycling from slow to full speed about every 5 sec.
 
Last edited:
To learn how analogRead and analogWrite work, you probably should read (or actually do) these tutorials.


On the hardware side, you should connect the pot to 3.3V, not to 5V. The analog signal input range is 0 to 3.3V, so by using 0 to 5V you pot will send a signal too high for about 1/3rd of its range. The rest of the range should still work.

Normally you shouldn't expect us to just write the code for you, but this one is so simple that I'll do it right now. Hopefully this helps. Please if you have time, read the 4th tutorial and compare this use of analogRead with that info in the tutorial.

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
  start_time = millis();
  count = 0;
}

void loop() {
  //
  // every time loop runs, read the pot and update motor output
  int in = analogRead(A0);
  int out = map(in, 0, 1023, 50, 255);
  analogWrite(fan_control_pin, out);
  //
  // once per second, print RPM and other info
  while ((millis() - start_time) >= 1000) {
    rpm = count * 30;  //60/2
    start_time = millis();
    count = 0;
    Serial.print("in = ");
    Serial.print(in);
    Serial.print(", out = ");
    Serial.print(out);
    Serial.print(" % , speed = ");
    Serial.print(rpm);
    Serial.println(" rpm");
  }
}

void counter() {
  count++;
}
 
Back
Top