Soldered Support:
I assume it’s a 5V fan. You can use this code in void loop():
int brzinaVentilatora = map(temperatura, 15, 35, 0, 255);
analogWrite(pinVentilatora, brzinaVentilatora);
where:
- brzinaVentilatora - the speed at which the fan will rotate (0-255, equivalent to 0V-5V)
- temperatura - the temperature read from the sensor
- pinVentilatora - PWM pin of Arduino (if you are using Croduino these are: 3,5,6,9,10,11) → connected to the fan’s positive pole (red wire)
Explanation:
The speed will increase proportionally with temperature increase. So at temperature 15, the speed will be 0, while at temperature 35 the speed will be 255 (maximum). You can set the temperature range as needed. Be careful about what happens when temperature falls below 15 or exceeds 35. You can solve this problem this way:
// if temperature is less than 15, temperature becomes 15
if(temperatura < 15) temperatura = 15;
if(temperatura > 35) temperatura = 35;
Original message (Croatian)
pretpostavljam da je 5V ventilator.
Možete koristiti ovaj kod u void loop():
int brzinaVentilatora = map(temperatura, 15, 35, 0, 255);
analogWrite(pinVentilatora, brzinaVentilatora);
gdje je:
brzinaVentilatora - brzina kojom će se ventilator okretati (0-255, odnosno 0V-5V)
temperatura - ocitana temperatura sa senzora
pinVentilatora - PWM pin Arduina (ako koristite Croduino to su: 3,5,6,9,10,11) → plus pol ventilatora(crvena zica)
objašnjenje:
brzina će se povećavati proporcionalno s povećanjem temperature. Tako da pri temperaturi 15, brzina će biti 0, dok pri temperaturi 35 brzina će biti 255 (maksimalna). Raspon temperature možete sami postaviti kako Vam odgovara. Pripazite što će se dogoditi kada temperatura padne ispod 15, odnosno iznad 35. Problem mozete rješiti na ovaj način:
// ako je temperatura manja od 15, temperatura je 15.
if( temperatura 35 ) temperatura = 35;