Archive

Posts Tagged ‘test’

LM335 – Calibration

July 24, 2012 Leave a comment

After attempting to hook up an LCD to display the temperature and getting readings of above 90°F inside a well air conditioned room, I decided that attempts to determine the accuracy of the LM335A sensor were in order. (LM335A datasheet here .PDF) I will be attempting multiple calibrating procedures, but the easiest and most basic one should be the boiling point, which is most frequently used for calibrating kitchen thermometers.

I was going to check the accuracy of the sensor using the know temperature of freezing (32°F or 0°C) and boiling water (212°F or 100°C), but seeing as electricity and water don’t mix very well I needed some way to protect the sensor and the Arduino.

There was no way I was going to do these tests with the sensor on a breadboard so I had to hook it up to a cable. To prevent signal degradation due to noise caused by electromagnetic interference, which the datasheet specifically warns about, I decided to use the shortest cable I could find. The cable came from a disposable pulse-oximetry sensor, which happened to be well shielded (bonus!).

The Setup:

I stripped the cable and soldered it into the same configuration that was on the breadboard. One end of the cable was attached to the sensor, and the other to the breadboard via headers (whose plastic melted and loosened up the pins, rendering the header much less useful).

The sensor end of my cable required special consideration as it would be immersed in both boiling and freezing water. I needed a waterproof way to contain the sensor without decreasing thermal conductivity, using something that wouldn’t melt at 100°C. To do this I fit the sensor within a disposable thermometer probe cover whose tip I filled with thermal grease. An alternative would have been to use heat shrink tubing, as recommended in the datasheet.

Before going into the extremes I decided to compare readings against the outdoor temperature at my location. I pulled up the temperature from Weather.com and sat the sensor probe against the mesh of an open window. The results were rather surprising:

(Note: the Weather.com temperature was two hours old when this picture was taken, in which time the temperature had rose. The temperature was 4°F more three hours later.)

Could it be that the LM335A was already acceptably calibrated? It appeared to be within the +/- 1°C (+/- 1.8°F) uncalibrated temperature error at 25°C (77°F) specified in the datasheet. The only way to find out was to continue with the tests.

For the freezing temperature test the setup is seemingly simple; get a bunch of ice and put it in water. The problem is that the temperature will not be exactly accurate to freezing, and the elevation, and atmospheric pressure could alter our results, but for my purpose it was good enough:

Interesting, so it would appear that my sensor was giving me a reading that was too low for the expected temperature of freezing water. While expecting 0°C (32°F), we got -2°C (29°F), so we are low by about 2°C in this test.

Next test is boiling temperature, again the elevation plays a part, as does atmospheric pressure. (Fun Fact: In Denver, Colorado, which is at an elevation of about one mile, water boils at approximately 95 °C.) One important thing to know is that there are different stages of “boiling”, which I found out after performing this test. Unfortunately, it seems that I may have never reached the true boiling point of water. I was using a small sauce pan, and was unable to achieve a rolling boil of required, so these results may have been less useful:

Even though these results may be too low, and less useful, they were still relatively close to the expected value. While expecting 100°C (212°F), we got 97°C (206°F), so we are low by about 3°C in this test.

Interestingly, the most useful and entertaining result came from my attempting to obtain a sublingual temperature. Human body temperature, as it turns out, is a relatively stable and reliable source for temperature calibration; varying by only a few degrees from person to person and through the day.

The normal core body temperature of a healthy, resting adult human being is stated to be at 98.6 degrees fahrenheit or 37.0 degrees celsius. Though the body temperature measured on an individual can vary, a healthy human body can maintain a fairly consistent body temperature that is around the mark of 37.0 degrees celsius.

The normal range of human body temperature varies due to an individuals metabolism rate, the higher (faster) it is the higher the normal body temperature or the slower the metabolic rate the lower the normal body temperature. Other factors that might affect the body temperature of an individual may be the time of day or the part of the body in which the temperature is measured at. The body temperature is lower in the morning, due to the rest the body received, and higher at night after a day of muscular activity and after food intake.

Source

The typical oral temperature measurement is slightly cooler, at 36.8° +/- 0.4°C (98.2° +/- 0.7°F), which means the oral temperature results of 33°C (92°F) meant my sensor was still off by about 3.8°C (6.2°F), . Seeing as average body temperature varies by about a degree, I would say that this method would be sufficient for achieving around +/- 1°C (1.8°F) calibration in a pinch.

All in all, I can definitively say that this sensor is reading 1 – 2°C (1.8 – 3.6°F) low through the range of 0 – 100°C. While I did not calibrate the sensor yet (that will be in part two of this post, which will come eventually) I ended up learning a whole lot about taking measurements, comparing expected vs actual values, looking for variables that could modify my results unexpectedly and setting up tests.

Reference:

Allfoodbusiness: How To Calibrate Thermometers (This is an excellent guide for thermometer calibration that I will be using in my next post.)

Physics Fact Book: Temperature of a Healthy Human

Wiki: Shielded Cable

Understanding Cable Shielding (.PDF)

Advertisements

SparkFun Free Day is Today

January 11, 2012 Leave a comment

Who doesn’t like free stuff?

Basically, it’s just a server stress test for SparkFun Read more…

Categories: Other Tags: , , , , ,

for Loop

January 11, 2012 Leave a comment

I’m going to do a quick run though the “for” loop, using a part of this guide as a foundation.

Using the Arduino.cc explanation here you can get a basic understanding of how it works.

The for statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. The for statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins.

There are three parts to the for loop header:

for (initialization; condition; increment) {
    //statement(s);
}
The initialization happens first and exactly once. Each time through the loop, the condition is tested; if it’s true, the statement block, and the increment is executed, then the condition is tested again. When the condition becomes false, the loop ends.

So now that you have a basic understanding of the for loop, lets see how we can apply it…

I will use my own version of the original example sketch from tronixstuff to illustrate how the for loop functions.

Click here for Pastebin with syntax highlighting for the following code.

void setup(){
    pinMode(9, OUTPUT);
}
void loop(){
    for (int x = 1; x <= 5; x++){
        digitalWrite(9, HIGH);
        delay(1000);
        digitalWrite(9, LOW);
        delay(1000);
    }
    delay(10000);
}

Here’s whats actually happening in the for loop in human language:

    for (set x equal to 1; is x less than or equal to 5?; increase x by 1){
        set pin 9 high;
        wait one second;
        set pin 9 low;
        wait one second;
    }
    wait 10 seconds;

The steps taken in our loop are;

  1. a variable “x” is set to equal to 1, this is done once
  2. a test is done to check if x is equal to or less than 5
  3. if the test is passed, the statements inside the braces are acted upon
  4. x is set to equal x + 1
  5. steps 2 through 4 are done until the test fails, in which case the loop is terminated

The physical result of the sketch – if you have an LED hooked up to pin 9 of the Arduino – will be that the LED will blink 5 times, wait 10 seconds, blink 5 times… and so on, for infinity.

That’s pretty much it. You can do more complicated things with the for loop, but the fundamentals can be summarized to: initialize, test, incrament/decrement.

if Test

January 9, 2012 Leave a comment

The “if” is a test you give to the Arduino. In this test you make the questions and you determine what happens when it passes or fails. If the test that you made is passed, as in something happens that you wanted to happen, then you want the Arduino to do a certain action. Optionally, if the test is failed or something unexpected happens and the test is failed, you can tell the Arduino to take a different action.

If you wanted to make a test on the Arduino that would turn on a light for 5 seconds every time someone walked through a door it would look something like this:

if (PersonWalkingThroughDoor == 1) {
 digitalWrite(LIGHT, HIGH);
 delay(5000);
 digitalWrite(LIGHT, LOW);
 }

And a translated human readable version to understand whats going on:

if (a person walks through the door) {
 turn on the light;
 wait 5 seconds;
 turn off the light;
 }

Now, let’s try to understand the Arduino version of the test and see why it works…

A person can only be walking through the door or not, we can represent this as 1 or 0, respectively. Then, we can assign this state to a certain variable – which can be thought of as a digital box that can hold thing – we’ll call this variable “PersonWalkingThroughDoor”.

If a person is walking though a door our variable PersonWalkingThroughDoor would equal 1, otherwise it would be 0. Given this basic setup we can run a test, and that is exactly what this part of our code does:

if (PersonWalkingThroughDoor == 1) {

If our variable PersonWalkingThroughDoor is equal to 1, then it would pass our test and go into the action phase, where it would preform a certain task.

digitalWrite(LIGHT, HIGH);
delay(5000);
digitalWrite(LIGHT, LOW);
}

What happens in our “action phase” are just some basic commands, first we use digitalWrite() to set the pin attached to the LIGHT variable to HIGH (turning on the light), then we wait 5000 milliseconds, then we turn the light off.
Finally, if you want to expand the function of the test then you can include an “else” clause which would look something like this:


 if (PersonWalkingThroughDoor == 1) {
 digitalWrite(LIGHT, HIGH);
 delay(5000);
 digitalWrite(LIGHT, LOW);
 }
 else {digitalWrite(LIGHT, LOW);}

In that case, if the initial test is failed you can tell the Arduino to take a different action. In our case it would simply keep the light off if there is nobody walking through the door, and it truly inessential as the light is turned off by default after 5 seconds.

So that’s it, that’s the basic overview of an if function. You might know it, but the best way to understand it is to try it out yourself.