Attiny85 Fan Controller Advice

Hi All
My first post here - I'm a beginner so show mercy :slight_smile: .

I am programming the Attiny85 with SpenceKonde core via my Uno - no problems there. I've been able to use the Attiny to blink an LED, sense a button press and activate other parts of my power supply circuit - again no problems.

I am having an issue though with controlling the 12v brushless fan speed with the AnalogWrite function. Here is the schematic of the controller:

When I measure the voltage sent to the fan I get 11.7v irrespective of the analogWrite(fanPin, value?) I use - the fan is either off or at full speed. Here's the code FWIW - I've removed all the other code to only focus on the fan control:

const byte tempPin = 2;  // temp input pin from LM35
const byte fanPin = 0;  // drive pin for the fan
const byte LEDPin = 4; // drive pin for the LED 
const byte powerPin = 3; //  drive pin for PSU on off
const byte buttonPin = 1; // button input pin

int temp = 0;  // start temp read zero

const byte tempMin = 82;  // the temperature to start the fan; (40 degC x 0.01 V/degC / 0.0048828175 V/bit)
const byte tempMax = 123;  // the maximum operational temperature allowed before power supply shutdown (60 degC x 0.01 V/degC / 0.0048828175 V/bit)

void setup() // do this once at startup
{  
  pinMode(fanPin, OUTPUT);
  pinMode(LEDPin, OUTPUT);
  pinMode(tempPin, INPUT);
  pinMode(powerPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop()
{  
  temp = analogRead(tempPin);
  analogWrite(fanPin, map(temp, tempMin, tempMax, 32, 255)); 
  
  // irrespective of what value I substitute for MAP fucntion I can't get the fan to run slower
}

Any ideas?

(deleted)

Hi Drew

Tried your code and the fan cycled from off to on in a loop - legendary! Thanks!

I measured the voltage and it did step from about 11.2v up to 12.0v so the PMW signal is working (relief).

I guess what has me confused now is why that range? I would expected bigger voltage "steps" from maybe 6v to 12v. Any ideas?

It's PWM, not an analog voltage.

You can't usually measure PWM on a multimeter and get meaningful results; the rapidly changing voltage confuses the meter.