(solved by me) HELP! HOW TO: CONTROL FAN (INTEL CPU FAN) 4 WIRE VIA BLUETOOTH?

I HAVE THIS CODE:

while (Serial.available())
delay(3);
char c = Serial.read();
readString += c;
OCR2B = map(readString.toInt(), 0, 79, 0, 79);
}
if (readString.length() >0)
Serial.println(readString.toInt());
analogWrite(PWMPin,OCR2B );
readString="";

BUT IF I SLIDE (ON THE APP - VIA BT) THE ARDUINO SENDING ONLY "0" (ON THE "SERIAL SCREEN") AND DO NOT CHANGING THE SPEED OF THE FAN.

IF YOU HAVE A NEW CODE FOR THIS PROJECT OR ARE YOU KNOW HOW TO FIX THIS CODE - YOU ARE WELCOME :slight_smile:

P.S THE FAN SLOW DOWN TO THE MINIMUM SPEED WHAN I SLID AT THE APP.

THANKS

SHAI

Update:

I find this code:

const int PWMPin = 3; // Only works with Pin 3
const int PotPin = 0; // Analog 0

void setup()
{
pinMode(PWMPin, OUTPUT);
// Fast PWM Mode, Prescaler = /8
// PWM on Pin 3, Pin 11 disabled
// 16Mhz / 8 / (79 + 1) = 25Khz
TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(WGM22) | _BV(CS21);
// Set TOP and initialize duty cycle to zero(0)
OCR2A = 79; // TOP - DO NOT CHANGE, SETS PWM PULSE RATE
OCR2B = 0; // duty cycle for Pin 3 (0-79) generates 1 500nS pulse even when 0
Serial.begin(57600);
}

void loop()
{
int in, out;

in = analogRead(PotPin);
out = map(in, 0, 1023, 0, 79);
OCR2B = out;
delay(200);
}

how to change the "PotPin" to bluetooth input - send "commands" from bluetooth?

solved :
need to change the frequency of the bt to 57600.

NO NEED TO SHOUT!!!!!!!

jremington:
NO NEED TO SHOUT!!!!!!!

:slight_smile:

Thank you for your comments :slight_smile:

I am very beginner in this staff. if can you help me with this code?! (I will thank you)

const int PWMPin = 3; // Only works with Pin 3
const int PotPin = 0; // Analog 0

void setup()
{
pinMode(PWMPin, OUTPUT);
// Fast PWM Mode, Prescaler = /8
// PWM on Pin 3, Pin 11 disabled
// 16Mhz / 8 / (79 + 1) = 25Khz
TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(WGM22) | _BV(CS21);
// Set TOP and initialize duty cycle to zero(0)
OCR2A = 79; // TOP - DO NOT CHANGE, SETS PWM PULSE RATE
OCR2B = 0; // duty cycle for Pin 3 (0-79) generates 1 500nS pulse even when 0
Serial.begin(57600);
}

void loop()
{
int in, out;

in = analogRead(PotPin);
out = map(in, 0, 1023, 0, 79);
OCR2B = out;
delay(200);
}

how to change the "PotPin" to bluetooth input -changing the speed from bluetooth?

  1. I have a big project - (included: lcd, dht11, water level sensor, relay,etc). for now!!! only remaining to control the speed of the fan via bluetooth.

I don't care about the way (I prefer good way), but for now - i will need to control the speed of the fan via Bt.

  1. i got this error on your code:

" 'sbi' was not declared in this scope "

Thanks again

shai