Arduino code for an LM75A temperature sensor
In this tutorial, we will learn how to use the LM75A temperature sensor with an Arduino to measure temperature in both Celsius and Fahrenheit. The LM75A sensor communicates via the I2C protocol, making it easy to integrate with Arduino boards. By the end of this tutorial, you will have a working setup that displays temperature readings every second.

To make the most of this tutorial, I recommend watching the associated video, which provides visual guidance on the setup and code implementation (in video at 20:29).
Hardware Explained
The LM75A temperature sensor is a digital sensor capable of measuring ambient temperature with high precision. It operates over the I2C communication protocol, allowing multiple sensors to be connected to the same bus. The sensor features an over-temperature shutdown function, which can help save power when not in use.
This sensor is typically available either as a standalone chip or as a PCB module. The module includes essential pins such as VCC, GND, SDA, and SCL, which are required for communication with the Arduino. When using this sensor, it is important to ensure proper connections and to select the correct I2C address for communication.
Datasheet Details
| Manufacturer | NXP / Texas Instruments |
|---|---|
| Part number | LM75A |
| Logic/IO voltage | 2.7 V to 5.5 V |
| Supply voltage | 2.7 V to 5.5 V |
| Output current (per channel) | 3 mA |
| Peak current (per channel) | 10 mA |
| PWM frequency guidance | N/A |
| Input logic thresholds | 0.3 VCC (high), 0.2 VCC (low) |
| Voltage drop / RDS(on) / saturation | 0.5 V max |
| Thermal limits | -55 °C to +125 °C |
| Package | SOIC-8 / TSSOP |
| Notes / variants | Available in different I2C addresses |
- Ensure the correct I2C address is set in your code.
- Use pull-up resistors on the SDA and SCL lines if necessary.
- Power the sensor with a stable voltage (2.7 V to 5.5 V).
- Monitor for overheating; the sensor can operate up to 125 °C.
- Handle the sensor gently to avoid damage during installation.
Wiring Instructions

To wire the LM75A temperature sensor to your Arduino, start by connecting the ground pin of the sensor to the ground pin of your Arduino. Next, connect the VCC pin of the sensor to the 5V pin on the Arduino. For the I2C communication, connect the SDA pin of the sensor (usually marked in green) to the A4 pin on the Arduino, and the SCL pin (usually marked in blue) to the A5 pin. If you're using a different Arduino model, ensure you are connecting to the correct I2C pins; for instance, on an Arduino Mega, SDA connects to pin 20 and SCL to pin 21.
If you are using the LM75A as a bare chip rather than a module, ensure to connect the corresponding pins correctly: the 1st pin connects to A4 (SDA), the 2nd pin connects to A5 (SCL), the 4th pin connects to ground, and the 8th pin connects to VCC. Leave the other pins unconnected. This setup ensures that the sensor can communicate properly with the Arduino.
Code Examples & Walkthrough
The following code initializes the LM75A sensor and reads the temperature every second. The key identifier in this code is lm75a_sensor, which is an instance of the LM75A class. This instance is used to retrieve temperature readings from the sensor.
LM75A lm75a_sensor(false, false, false);
This line creates an instance of the LM75A class, passing parameters that represent the state of the A0, A1, and A2 pins. The default state can be set to false if these pins are not used.
In the setup() function, we initialize the serial communication at 9600 baud rate, which is crucial for displaying the temperature readings on the serial monitor.
void setup(void) {
Serial.begin(9600);
Serial.println("Robojax LM75A Test");
}
This snippet sets up the serial monitor, allowing us to view the temperature readings as they are printed each second.
In the loop() function, we retrieve the temperature in degrees Celsius and check for any errors. If the temperature is valid, we print it alongside its Fahrenheit equivalent.
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)");
}
This segment of code demonstrates how to handle the temperature reading and print it in both Celsius and Fahrenheit to the serial monitor. It includes error handling for invalid readings.
For the complete code, check the loading section below the article.
Demonstration / What to Expect
Once you have completed the wiring and uploaded the code to your Arduino, you should see the temperature readings displayed on the serial monitor every second. You can test the sensor's responsiveness by touching it or using a heat gun, and you should observe the readings change accordingly. Be cautious of reversed polarity when connecting the sensor, as it may damage the module.
Resources & references
No resources yet.
Files📁
Fritzing File
-
LM75 Temperature Sensor
application/zip0.01 MB