From drawing to reality

Just wanted to show my way of solving my problems, and making the items needed.

My problem was that I put a cabinet up for all my network equipment.

And the QNAP TS-219P got 46C, but that isn’t really a problem for it. The problem was rather me, who wanted to have something to suck the air out anyways, just in case.

For that I found some fan’s that was close to perfect. They got PWM controller in, so I can just give them 12V and connect them to an ATmega328 with a temperature probe attached, and upload my own sketch to it, and then have a temperature controlled fan.

But why do it so simple? 😉 Instead I am going to connect the fan to an arduino with ethernet shield and a temperature probe. With this I am then able to show the temperature inside the cabinet on a webpage, and also send me emails and sms if the temperature is too high.

And… As always, I can’t stop thinking, so why stop here? Let’s bump it up, and add rpm counter for the fan, maybe a google chart over the temperature, RF receiver for the RF sender in the mailbox, and have it send an email when the postman was there… Hmm, what more… Control the outdoor lights? Also from a webpage…

But first things first, lets get the fan in the cabinet!

I could just drill a hole, and then put it in, but that is the way I normally do it, and I am never really pleased with the outcome, and this time I want it done right!

First the fan…

60mm, 12V, build-in pwm controller.

Let’s see if it works as expected…

The fan is a San Ace 60 (9G0612P1M051), and the black wire is GND, red 12V, green PWM, and yellow RPM

To make the fan turn, I attached the black to gnd, and the red to 12V from the external power supply. I then connected the arduino’s gnd to the external power supply’s gnd, and digital pin 3 (pwm) to the fan’s green wire.

For the testing of the speed, I simply wrote analogWrite(4, 127); which is roughly 50% of the speed, and the fan also turned down to around 50%, so that part was perfect!

Next up was the RPM function, which requred a bit more code, and the last wire.

The yellow wire returns the rpm, but to be able to read it, we need to understand what it actually does. And I found out, that it connects to GND, so for the arduino to read it, we need to pull it up to make it stop floating.

Pull up, what is that? The pull up resistor is the one you can see next to the yellow wire coming from the arduino. On the arduino I connected it to 5V, then down to the 10k Ohm resistor, and then the yellow wire from the fan on the other side. To read the rpm we connect the wire to the same side of the resistor as the fan, because we don’t want to shorten the 5V directly from the arduino.

After connecting the wires, we need to figure out how we want to sense the sensor inside the fan, and external interrupts are perfect for this, so after looking at the page on arduino.cc I could find that the attachInterrupt(0 was triggered by digital pin 2, so the wire from the 10k Ohm resistor goes to digital pin 2.

Only thing left, is to make a bit of code…

#define fanPin 3    // FAN connected to digital pin 9

volatile byte rpmcount;
unsigned long timeold;

void setup()
{
  attachInterrupt(0, count, RISING); //0 = Digital pin 2
  analogWrite(fanPin, 25);
  Serial.begin(9600);

  rpmcount = 0;
  timeold = 0;
}

void loop()
{
  if ((millis() - timeold) >= 1000)
  {
    Serial.println(30*1000/(millis() - timeold)*rpmcount, DEC);
    timeold = millis();
    rpmcount = 0;
  }
}

void count()
{
  rpmcount++;
}

This is all that is needed for the testing, and it will then return the RPM each second. It can also be shortened down, to ex. twice every second by changing the >= 1000 to >= 500, and the rpm*60 to rpm*120, or anything else, but for what I am going to use it for, once every second is plenty.

At full speed it returns around 6000 rpm, and at 50% around 3960 rpm, so it isn’t perfect, but the actual rpm isn’t critical either.

So the fan works, it can be controlled from an arduino, and even RPM works, let’s find out how to put it into the cabinet!

After measuring a bit, I came up with a design, and tried it in Inventor, and it looks pretty good if I should say so…

Let’s make a 2D drawing of it too…

And here it is. The material will be aluminium, because it is lightweight, and easy to work in.

Figured the CNC lathe would be bigger a hassle than the old manual one, so let’s get going 🙂

Drill a hole, and start removing the material… Then forget everything about taking more pictures…

After removing all the material, I used the little saw to cut the piece off I needed, then back to the lathe and make the sawed surface nice just like the others.

Drill the holes, and I could have used a normal drill, but like this it would be more precise (+/- 0,01mm)

And will the fan fit?

oooh yes it wil 😉

And now back to the coding again, because we need to add a temperature sensor.

For this I took a shortcut, and just connected a temperature brick from seeedstudio.

#define fanPin 3    // PWM pin from the fan connected to this digital pin
#define fanPWR 8    // Base pin of the TIP102 to switch the fan on/off

#define minTemp 30  // Fan will start at this temperature
#define maxTemp 50
#define hysTemp 2   // The hysteresis temperature of start and stop

#define minPWM 30   // Minimum speed the fan will run at
#define maxPWM 255  // Maximum speed the fan will run at

// Used by RPM counter
volatile byte rpmcount = 0;
unsigned long timeold = 0;

//Used by PWM control
int pwm = 0;
int hysPercent = 0;

void setup()
{
  attachInterrupt(0, count, RISING); //0 = Digital pin 2
  Serial.begin(9600);

  pinMode(fanPWR, OUTPUT);

  hysPercent = (maxTemp - minTemp / 100) * hysTemp;
}

void loop()
{
  if ((millis() - timeold) >= 1000)
  {
    int temp = temperature(analogRead(5));

    if (temp <= minTemp - hysTemp)
    {
      digitalWrite(fanPWR, LOW);
    }
    else if (temp >= minTemp + hysTemp)
    {
      digitalWrite(fanPWR, HIGH);
    }

    pwm = map(temp, minTemp, maxTemp, minPWM, maxPWM);
    analogWrite(fanPin, constrain(pwm, minPWM, maxPWM));

    Serial.print(temp);
    Serial.print("c - ");
    Serial.print(30*1000/(millis() - timeold)*rpmcount, DEC);
    Serial.print("rpm - ");
    Serial.print(pwm);
    Serial.println("pwm");
    timeold = millis();
    rpmcount = 0;
  }
}

void count()
{
  rpmcount++;
}

// Calculate the temperature
int temperature(int RawADC)
{
  float Temp;
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius
  return Temp;
}

Let’s put it in the cabinet, and see how it performs

Still got the arduino on the breadboard while debugging and adding features, and testing how the values should be for it to work exactly the way I want it to.

First tests shows that my QNAP nas dropped from 47C system temperature to 42C, and the arduino is set to 35-55C, time will show if I need to adjust it. 🙂

To know what was going on with the temperature, I could either use an Ethernet shield, a WiFi shield, or serial, this time I went with serial, but the problem here, is that I had to use a computer to read the output from the arduino. I already had a computer running 24/7, but it was in another part of the house, so I found my RF set (that I never really used for anything), and started to mess with that.
The result is now that the arduino in the network cabinet, sends messages via RF to another arduino connected to my htpc, which is then updating the MySQL database on my nas.

The current informations from my network cabinet is:

— More to come… —

Leave a Reply