In my recent project, I'm working on 5V DC USB fan's speed controlling.
My fan motor looks like below:
Here fan controlling is done by PWM which is coming from Arduino NANO controller. For controlling the speed of FAN, I developed one circuit which is below:
Now, when I give full PWM means full value 255 and at that time when I measure the voltage across motor then it just around 3.50 V. I just thought it may be full 5 V. I don't know why this much loss happen? Any suggestion regarding this.
And my Arduino code is below:
const int kPinSw1 = 8;
const int kPinSw2 = 9;
const int kPinPWM = 3;
int oneBtnState = 0;
int lastOneBtnState = 0;
int twoBtnState = 0;
int lastTwoBtnState = 0;
int count = 0;
void setup() {
Serial.begin(9600);
pinMode(kPinSw1, INPUT_PULLUP);
pinMode(kPinSw2, INPUT_PULLUP);
pinMode(kPinPWM, OUTPUT);
}
void loop() {
//-------------------------------------//
oneBtnState = digitalRead(kPinSw1);
if(oneBtnState != lastOneBtnState)
{
if(oneBtnState == HIGH)
{
count--;
if(count <= 0)
{
count = 0;
}
}
delay(50);
}
lastOneBtnState = oneBtnState;
//-------------------------------------//
twoBtnState = digitalRead(kPinSw2);
if(twoBtnState != lastTwoBtnState)
{
if(twoBtnState == HIGH)
{
count++;
if(count >= 4)
{
count = 4;
}
}
delay(50);
}
lastTwoBtnState = twoBtnState;
Serial.println(count);
//-------------------------------------//
switch(count) {
case 1:
analogWrite(kPinPWM, 0);
break;
case 2:
analogWrite(kPinPWM, 128);
break;
case 3:
analogWrite(kPinPWM, 192);
break;
case 4:
analogWrite(kPinPWM, 255);
break;
default:
analogWrite(kPinPWM, 0);
break;
}
}