Other Arduino Codes and Videos by Robojax

LM75A Temperature Sensor with LCD1016 I2C Robojax.com

LM75A Temperature Sensor with LCD1016 I2C

In this page you will get the code and library for LM75A Sensor that displays the temperature on LCD1602 with I2C. Watch video instruction on how to use LM75A


 /*
 * \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
 * ersion 1.0
 * 
 * Video instruction by Ahmad Shamshiri on July 12 at 22:40 2018 for Robojax.com
 * in Ajax, Ontario, Canada
 * watch video instruction of this code: https://youtu.be/hVo_msVMlaI
For this sketch you need to connect:
VCC to 3.3V or 5V and GND to GND of arduino
SDA to A4 and SCL to A5

 */

#include <LM75A.h>

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


// start of settings for LCD1602 with I2C
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// end of settings for LCD1602 with I2C

void setup(void)
{
  Serial.begin(9600);
  Serial.println("Robojax LM75A Test");
  // initialize the LCD
  lcd.begin();  
  lcd.backlight();
  lcd.print("Robojax LM75A");
  lcd.setCursor(0,1);
  lcd.print("Demo"); 
  delay(2000); 
}

void loop()
{
   lcd.clear();// clearn previous values from screen
  // Robojax.com LM75A Test
  float temperature_in_degrees = lm75a_sensor.getTemperatureInDegrees();

  if (temperature_in_degrees == INVALID_LM75A_TEMPERATURE) {
    Serial.println("Error while getting temperature");
  } else {
    Serial.print("Temp: ");
    Serial.print(temperature_in_degrees);
    Serial.print(" C (");
    float tmpF = LM75A::degreesToFahrenheit(temperature_in_degrees);
    Serial.print(tmpF);
    Serial.println(" F)");
  lcdDisplay(
             // to print cilius:
             0, // character 0 
             0, // line 0
             "Celsius: ", 

             // to print cilius
             11, // character 10
             0, // line 0
             temperature_in_degrees 
             );  

  lcdDisplay(
             // to print fahrenheit:
             0, // character 0 
             1, // line 1
             "Fahrenh.: ", 

             // to print Fahrenheit
             11, // character 9
             1, // line 0
             tmpF   
             );                 
  }

  delay(1000);
}


/*
 * lcdDisplay(int tc, int tr, String title, int vc, int vr, float value)
 * displays value and title on LCD1602
 * How to use:
 * If you wan to diaplay: "Voltage: 13.56mV" starting from first character
 * on second row.
 * use:
 * lcdDisplay(0, 1, "Voltage: ", 13.56)
 *   
 * tc  is character number  (0)
 * tr is row in the lcd (1)
 * title is the text (Voltage:)
 * vc value for character 
 * vr value for  row or line
 * value is the value (13.56)
 */
void lcdDisplay(int tc, int tr, String title, int vc, int vr, float value)
{
   // Robojax.com LCD1602 for LM75A Demo
   lcd.setCursor (tc,tr); //
   lcd.print(title);
   
   lcd.setCursor (vc,vr); //
   lcd.print(value);
 
}