Arduino and LM75A

Arduino and LM75A

The LM75A is a temperature sensor on an I2C bus. It has a very large range (-55°C to 125°C) with a moderate accuracy. In the range of -25°C to 100°C (the range you will probably be in), the accuracy is ±2°C.

In my experience the accuracy tends to be stable so what you could do is calibrate it against a sensor with higher accuracy and then take the deviation and subtract (or add) it to your measured temperature.

There already is a library for the sensor which you can download the library here. You have to install this library through Sketch, Include Library, Add .ZIP Library.

I have compiled the example that is included with the library against both the Arduino Nano and the ESP8266 and the same code worked for both. Remember to use the standard ports for I2C with the ESP8266 (D2, GPIO4 for SDA and D1, GPIO5 for SCL).

/*
 * \brief Show temperature in degrees and fahrenheit every second
 *
 * \author Quentin Comte-Gaz <quentin@comte-gaz.com>
 * \date 8 July 2016
 * \license MIT License (contact me if too restrictive)
 * \copyright Copyright (c) 2016 Quentin Comte-Gaz
 * \version 1.0
 */

#include <LM75A.h>

LM75A lm75a_sensor/*(false, //A0 LM75A pin state
                   false, //A1 LM75A pin state
                   false, //A2 LM75A pin state)*/; // Create I2C LM75A instance

void setup(void)
{
  Serial.begin(9600);
  Serial.println("Temperatures will be displayed every second:");
}

void loop()
{
  float temperature_in_degrees = lm75a_sensor.getTemperatureInDegrees();

  if (temperature_in_degrees == INVALID_LM75A_TEMPERATURE) {
    Serial.println("Error while getting temperature");
  } else {
    Serial.print("Temperature: ");
    Serial.print(temperature_in_degrees);
    Serial.print(" degrees (");
    Serial.print(LM75A::degreesToFahrenheit(temperature_in_degrees));
    Serial.println(" fahrenheit)");
  }

  delay(1000);
}

As you can see, the code is relatively straight forward, initial the library and read from the sensor.

Advertisements

One thought on “Arduino and LM75A

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s