PWM fan speed control with 2N2222

All I'm getting is max speed no matter what I enter.

int pwmPin = 4;

void setup() {
Serial.begin(9600);
pinMode( pwmPin, OUTPUT);

}
void loop () {

analogWrite(pwmPin, 300);
delay(5000);

analogWrite(pwmPin, 1000);
delay(5000);
}

Try with 3,5,6,9,10,11, the analogWrite()/PWM capable pins.

Syntax:
analogWrite(pin, value)

Parameters:
pin: the Arduino pin to write to. Allowed data types: int.
value: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int.

(from analogWrite() - Arduino Reference )

Thanks for answering a dumb question in a helpful manner.

Cheers.

SEE ATTACHED

Also, analogWrite() only uses 0 to 255. Anything higher gets cut off.

300 = 0x012C, only the lower 8 bits are used, so 0x2C = 44 decimal

Same for 1000, = 0x03e8 -> 0xe8 = 232 decimal.

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