Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Monstermotte
Published © CC BY-NC-SA

Make a Fan Controller with Arduino

You have a fan, but you don't know how to control it? Then you're right here.

BeginnerFull instructions provided37,793
Make a Fan Controller with Arduino

Things used in this project

Hardware components

Arduino Mini 05
Arduino Mini 05
You can also use any other Arduino
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Fan (with PWM pin)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

img_0150_LxZVUbAsjv.JPG

Code

FanController.ino

Arduino
#include <EEPROM.h>

#define FAN_PIN 3;
#define FS_ADDR 0x01
int fanSpeed;

void setup() {
  // put your setup code here, to run once:
  pinMode(3, OUTPUT);
  EEPROM.get(FS_ADDR, fanSpeed);
  if(fanSpeed < 1) fanSpeed = 255;
  analogWrite(FAN_PIN, fanSpeed);
  Serial.begin(9600);

}
char rx_byte = 0;
String input = "";

void loop() {
  if (Serial.available() > 0) {    // is a character available?
    rx_byte = Serial.read();       // get the character
  
    // check if a number was received
    if ((rx_byte >= '0') && (rx_byte <= '9')) {
      input.concat(rx_byte);
      
    }
    else if (rx_byte == '\n') {
      Serial.print("Received: ");
      Serial.println(input);
      if(input.toInt() < 256) {
        fanSpeed = input.toInt();
        EEPROM.put(FS_ADDR, fanSpeed);
      } else {
        Serial.println("Invalid Number");
      }
      input = "";
    }
    else {
      Serial.println("Not a number.");
    }
  } // end: if (Serial.available() > 0)
  analogWrite(FAN_PIN, fanSpeed);
}

Credits

Monstermotte
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.