코드 검색

LM75A 온도 센서와 LCD1602 I2C

LM75A 온도 센서와 LCD1602 I2C

이 튜토리얼에서는 I2C 통신을 사용하여 LM75A 온도 센서로 측정한 온도를 섭씨와 화씨로 LCD1602 화면에 표시하는 방법을 배웁니다. LM75A는 -55°C에서 +125°C까지 측정할 수 있어 다양한 응용 분야에 적합합니다. 설정이 완료되면 LCD 디스플레이에서 실시간 온도 판독값을 볼 수 있습니다.

LCD1602-I2C display module with 4 wires

이 프로젝트에서는 I2C로 연결된 LM75A 센서와 LCD1602 모듈을 사용합니다. 이를 통해 배선이 더 간단해지고 Arduino에서 사용되는 핀이 줄어듭니다. 목표는 온도를 지속적으로 읽어 LCD에 표시하는 시스템을 만드는 것입니다. 과정 중 이해가 안 되는 부분이 있으면 비디오 튜토리얼(비디오 00:00)을 확인하세요.

하드웨어 설명

이 프로젝트의 주요 구성 요소는 LM75A 온도 센서와 LCD1602 디스플레이입니다. LM75A는 정확한 온도 판독값을 제공하는 I2C 온도 센서입니다. SDA(데이터 라인)와 SCL(클록 라인) 두 가닥의 전선만으로 Arduino와 통신하므로 프로젝트에 쉽게 통합할 수 있습니다.

LCD1602은 한 번에 최대 32자를 표시할 수 있는 16x2 문자 디스플레이입니다. I2C 인터페이스를 사용하면 추가 전선 두 가닥만으로 제어할 수 있어 배선 과정이 크게 간소화됩니다. LCD의 백라이트 기능은 어두운 환경에서도 가시성을 높여줍니다.

데이터시트 세부 정보

제조업체텍사스 인스트루먼트
부품 번호LM75A
로직/IO 전압2.7V ~ 5.5V
공급 전압2.7V ~ 5.5V
출력 전류(채널당)해당 없음
피크 전류(채널당)해당 없음
PWM 주파수 가이드해당 없음
입력 로직 임계값0.3 * Vcc(낮음), 0.7 * Vcc(높음)
전압 강하 / RDS(on) / 포화해당 없음
열 제한작동: -55°C ~ +125°C
패키지SOT-23
참고 사항 / 변형여러 I2C 주소로 제공

  • 적절한 전원 공급(2.7V ~ 5.5V)을 확인하세요.
  • 필요한 경우 SDA 및 SCL 라인에 풀업 저항을 사용하세요.
  • 여러 장치의 I2C 주소 구성을 확인하세요.
  • 간섭을 최소화하려면 배선을 짧게 유지하세요.
  • 온도 범위(-55°C ~ +125°C)를 모니터링하세요.
  • 온도 판독값 디버깅에는 시리얼 모니터를 사용하세요.
  • 코드에서 오류 상태를 효과적으로 처리하세요.
  • 디스플레이의 전원 요구 사항에 주의하세요.

배선 지침

Arduino_wiring_LM75A_LCD_bb

LM75A 온도 센서와 LCD1602을 배선하려면 먼저 전원 공급을 연결하세요. LM75A와 LCD1602의 VCC 핀을 모두 Arduino의 5V 핀에 연결합니다. 그런 다음 두 모듈의 접지(GND) 핀을 Arduino의 GND 핀에 연결합니다.

다음으로 I2C 통신 라인을 연결합니다. LM75A의 SDA 핀은 Arduino의 A4 핀에 연결하고, SCL 핀은 A5 핀에 연결해야 합니다. 이를 통해 센서와 Arduino 간의 I2C 통신이 가능해집니다. 통신 오류를 방지하려면 연결이 확실한지 확인하세요.

코드 예제 및 설명

코드에서 먼저 LM75A 센서와 LCD1602 디스플레이에 필요한 라이브러리를 포함합니다. 다음 발췌문은 LM75A 센서의 인스턴스를 만드는 방법을 보여줍니다:

LM75A lm75a_sensor(false, false, false);

이 줄은 LM75A 센서 객체를 초기화합니다. 부울 매개변수는 LM75A의 A0, A1, A2 핀에 해당하며, 필요한 경우 다른 I2C 주소를 허용합니다.

다음으로 시리얼 모니터를 설정하고 LCD 디스플레이를 초기화합니다:

void setup(void) {
  Serial.begin(9600);
  lcd.begin();  
  lcd.backlight();
  lcd.print("Robojax LM75A");
}

여기서 9600 보드로 시리얼 통신을 시작하고 LCD 디스플레이를 초기화합니다. 백라이트가 켜지고 초기 메시지가 화면에 출력됩니다.

메인 루프에서는 온도를 지속적으로 읽어 표시합니다:

float temperature_in_degrees = lm75a_sensor.getTemperatureInDegrees();
if (temperature_in_degrees == INVALID_LM75A_TEMPERATURE) {
  Serial.println("Error while getting temperature");
}

이 섹션은 센서에서 온도를 가져옵니다. 판독값이 유효하지 않으면 오류 메시지가 시리얼 모니터로 전송됩니다. 그렇지 않으면 온도를 처리하여 LCD에 표시할 수 있습니다.

시연 / 예상 결과

모든 배선이 완료되고 코드가 업로드되면 LCD1602 디스플레이에서 섭씨와 화씨가 번갈아 표시되는 온도 판독값을 볼 수 있습니다. LM75A 센서가 올바르게 작동하면 표시된 온도가 매초 지속적으로 업데이트됩니다. 극성 반전이나 잘못된 배선과 같은 문제가 있는 경우 연결을 확인하고 올바른 핀이 사용되었는지 확인하세요(비디오 00:00).

이미지

LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LM75a-1
LM75a-1
LM75a-3
LM75a-3
LM75a-12
LM75a-12
Arduino_wiring_LM75A_LCD_bb
Arduino_wiring_LM75A_LCD_bb
129-LM75A temperature sensor with LCD1602 I2C
언어: C++
/*
 * \brief Show temperature in degrees Celsius 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
 * 
 * Modified by Ahmad Shamshiri on July 12, 2018 at 22:40 for Robojax.com
 * in Ajax, Ontario, Canada
 * Watch video instructions for 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 the 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();// clear 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 Celsius:
             0, // character 0 
             0, // line 0
             "Celsius: ", 

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

  lcdDisplay(
             // to print Fahrenheit:
             0, // character 0 
             1, // line 1
             "Fahrenheit: ", 

             // 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 want to display: "Voltage: 13.56mV" starting from the first character
 * on the second row.
 * use:
 * lcdDisplay(0, 1, "Voltage: ", 13.56)
 *   
 * tc  is the character number  (0)
 * tr is the row number in the LCD (1)
 * title is the text ("Voltage:")
 * vc is the character number for the value
 * vr is the row number for the value
 * 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);
 
}

필요할 수 있는 것들

자원 및 참고자료

파일📁

프리징 파일

다른 파일들