1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Tutorial arduino fan speed controlled by temp

Discussion in 'DIY peripherals' started by bruce stephen, Sep 24, 2015.

  1. bruce stephen

    bruce stephen Hammer doesnt fix it, must be electrical

    Joined:
    Jun 7, 2015
    Messages:
    1,286
    Occupation:
    general contractor
    Location:
    michigan
    Balance:
    9,110Coins
    Ratings:
    +1,238 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform, 6DOF
    http://www.electroschematics.com/9540/arduino-fan-speed-controlled-temperature/

    going to try this looks interesting for fancying up a control box. gonna use it for north bridge cooler on top of moto vnh chips. ill use nano also for this. pics to follow.
    • Like Like x 2
  2. bruce stephen

    bruce stephen Hammer doesnt fix it, must be electrical

    Joined:
    Jun 7, 2015
    Messages:
    1,286
    Occupation:
    general contractor
    Location:
    michigan
    Balance:
    9,110Coins
    Ratings:
    +1,238 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform, 6DOF
    ok ive compiled a parts list. now just wait for stuff in the mail.

    fan speed controller parts list

    1n4007 rectifier x 1
    bd139 transistor x 1
    100uf/16v capacitor x 1
    1k resistor x 2 v
    red led x 1 v
    16x2 lcd x 1 v
    lm35 temp sensor x 1 v
    photo resistor x 1 v
    12v fan 40mm x 2 v
    arduino x 1 v
    proto/bread board x 1 v
    • Like Like x 1
    Last edited: Sep 29, 2015
  3. bruce stephen

    bruce stephen Hammer doesnt fix it, must be electrical

    Joined:
    Jun 7, 2015
    Messages:
    1,286
    Occupation:
    general contractor
    Location:
    michigan
    Balance:
    9,110Coins
    Ratings:
    +1,238 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform, 6DOF
    EDIT:THIS CODE DOES NOT COMPILE I HAVE POSTED A SIMPLER VERSION BELOW


    This is the code i intend to use.

    [​IMG] krowvin on March 10, 2015 at 3:48 am
    reply
    I modified your code to do a few things. I haven’t got to test it with the hardware yet (waiting on it to be delivered), but it seems to compile. Here’s my code if anyone would like to take a look.

    Added LDR (photo resistor to control LCD back light)
    Added a second fan (fans should function at the same speed)
    Add scenarios for when temp is below and above threshold
    (below fans turn off, above fans go to max)
    Also added code to show LCD as 0% or 100% Author has the line
    fanSpeed = 0; but I think he meant to use fanlcd = 0;

    #include <LiquidCrystal.h>
    //original: http://www.electroschematics.com/9540/arduino-fan-speed-controlled-temperature/
    LiquidCrystal lcd(7,6,5,4,3,2);
    int tempPin = A1; // the output pin of LM35
    int photoPin = A0; //photoresistor for LCD backlight
    int fan1 = 11; // the pin where fan is
    int fan2 = 10;
    int lcdbl = 9; // LCD backlight pin (connect to pin +15 on LCD
    // (NOTE: pin 16 is -)
    int led = 8; // led pin for HIGH temp warning
    int temp;
    int tempMin = 27; // 27C = 80.6F the temperature to start the fan
    int tempMax = 40; // 40C = 104F the maximum temperature when fan is at 100%
    int ldr = -1; //0..1023
    int fanSpeed;
    int fanLCD;

    void setup() { //set pins as input or outputs
    pinMode(fan1, OUTPUT);
    pinMode(fan2, OUTPUT);
    pinMode(led, OUTPUT);
    pinMode(lcdbl, OUTPUT);
    pinMode(tempPin, INPUT);
    lcd.begin(16,2);
    }

    void loop() {
    temp = readTemp(); // get the temperature
    if(temp = tempMin) && (temp tempMax) { // if temp is higher than max temp
    digitalWrite(led, HIGH); // turn on led
    digitalWrite(fan1, HIGH); //set fans to max
    digitalWrite(fan2, HIGH);
    fanLCD = 100; //Shows 100% use on LCD for fan
    } else { // else turn off led
    digitalWrite(led, LOW);
    }

    ldr=analogRead(photoPin);
    if(ldr<=511) { //if ldr is <= 511 turn backlight on
    digitalWrite(lcdbl, HIGH);
    } else {
    digitalWrite(lcdbl, LOW); //if greater, turn LCD BL off
    }
    lcd.print("TEMP: ");
    lcd.print(temp); // display the temperature
    lcd.print("C ");
    lcd.setCursor(0,1); // move cursor to next line
    lcd.print("FANS: ");
    lcd.print(fanLCD); // display the fan speed
    lcd.print("%");
    delay(200); //give time to read text before changing
    lcd.clear();
    }

    int readTemp() { // get the temperature and convert it to celsius
    temp = analogRead(tempPin);
    return temp * 0.48828125;
    }


    +++++++++NEW CODE+++++++++++
    #include<LiquidCrystal.h>
    //source: http://www.electroschematics.com/9540/arduino-fan-speed-controlled-temperature/
    LiquidCrystal lcd(7,6,5,4,3,2);
    int tempPin = A1;// the output pin of LM35
    int fan =11;// the pin where fan is
    int led =8;// led pin
    int temp;
    int tempMin =30;// the temperature to start the fan
    int tempMax =70;// the maximum temperature when fan is at 100%
    int fanSpeed;
    int fanLCD;
    void setup(){
    pinMode(fan, OUTPUT);
    pinMode(led, OUTPUT);
    pinMode(tempPin, INPUT);
    lcd.begin(16,2);
    }
    void loop(){
    temp = readTemp();// get the temperature
    if(temp < tempMin){// if temp is lower than minimum temp
    fanSpeed =0;// fan is not spinning
    digitalWrite(fan, LOW);
    }
    if((temp >= tempMin)&&(temp <= tempMax)){// if temperature is higher than minimum temp
    fanSpeed = map(temp, tempMin, tempMax,32,255);// the actual speed of fan
    fanLCD = map(temp, tempMin, tempMax,0,100);// speed of fan to display on LCD
    analogWrite(fan, fanSpeed);// spin the fan at the fanSpeed speed
    }
    if(temp > tempMax){// if temp is higher than tempMax
    digitalWrite(led, HIGH);// turn on led
    }else{// else turn of led
    digitalWrite(led, LOW);
    }
    lcd.print("TEMP: ");
    lcd.print(temp);// display the temperature
    lcd.print("C ");
    lcd.setCursor(0,1);// move cursor to next line
    lcd.print("FANS: ");
    lcd.print(fanLCD);// display the fan speed
    lcd.print("%");
    delay(200);
    lcd.clear();
    }
    int readTemp(){// get the temperature and convert it to celsius
    temp = analogRead(tempPin);
    return temp *0.48828125;
    }​
    • Useful Useful x 1
    Last edited: Oct 2, 2015
  4. jaco73

    jaco73

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    interesting !! Thank you
  5. tombo

    tombo Active Member

    Joined:
    Oct 5, 2013
    Messages:
    269
    Location:
    Germany
    Balance:
    2,436Coins
    Ratings:
    +246 / 2 / -0
    My Motion Simulator:
    DC motor, Arduino
    Looks interesting. Thanks for sharing, maybe I can include this in my Diy Led Lamp.