ACS712을 사용하여 I2C가 있는 LCD1602 또는 LCD2004에 전류 표시하기
이 튜토리얼에서는 Allegro ACS712 전류 센서를 사용하여 AC 및 DC 전류를 모두 측정하고, I2C를 이용해 LCD1602 또는 LCD2004에 측정값을 표시하는 방법을 배웁니다. 이 프로젝트는 다양한 애플리케이션에서 전류를 모니터링하는 데 특히 유용하며, 실시간 전류 데이터를 시각적으로 표시합니다. 완료되면 LCD에 전류 측정값을 정확히 표시하는 작동하는 설정을 갖게 됩니다.


배선 및 코드에 대한 설명은 지정된 타임스탬프(영상 00:00)에서 영상을 확인하세요.
하드웨어 설명
이 프로젝트의 주요 구성 요소는 최대 30A까지 전류를 측정할 수 있는 ACS712 전류 센서입니다. 이 센서는 홀 효과를 이용하여 흐르는 전류를 비례하는 전압 출력으로 변환합니다. 이 전압 출력은 Arduino에서 읽어 전류 레벨을 계산하는 데 사용됩니다. 센서에는 전원용 VCC, 접지용 GND, 전압 신호용 OUT의 세 핀이 있습니다.
LCD1602 또는 LCD2004 디스플레이는 I2C로 연결되므로 전원과 접지 외에 두 개의 데이터 핀(SDA 및 SCL)만 사용하여 배선과 제어가 더 간편합니다. 이를 통해 여러 연결로 배선이 복잡해지지 않고 전류 측정값을 쉽게 표시할 수 있습니다.
데이터시트 세부 정보
| 제조사 | Allegro Microsystems |
|---|---|
| 부품 번호 | ACS712ELCTR-30A-T |
| 로직/IO 전압 | 4.5–5.5 V |
| 공급 전압 | 5 V |
| 출력 전류(채널당) | 30 A |
| PWM 주파수 가이드 | 해당 없음 |
| 입력 로직 임계값 | 0.5 V(무부하 출력) |
| 전압 강하 / RDS(on) / 포화 | 1.2 mΩ |
| 열 제한 | 최대 150 °C |
| 패키지 | TO-220 |
- 20A 이상의 전류에서는 적절한 방열을 보장하세요.
- 과열을 방지하려면 적절한 와이어 게이지(30A의 경우 12 AWG)를 사용하세요.
- 정상 작동을 위해 VCC를 5V에, GND를 접지에 연결하세요.
- OUT 핀이 Arduino의 아날로그 입력 핀(예: A0)에 연결되어 있는지 확인하세요.
- 다양한 ACS712 모델의 감도 차이를 인지하세요.
- 데이터시트에 명시된 대로 디커플링용 커패시터를 사용하세요.
배선 지침

ACS712 전류 센서를 Arduino 및 LCD와 배선하려면 먼저 ACS712의 VCC 핀을 Arduino의 5V 핀에 연결하세요. 다음으로 ACS712의 GND 핀을 Arduino의 접지 핀에 연결합니다. ACS712의 OUT 핀은 Arduino의 아날로그 핀 A0에 연결해야 하며, 여기서 전압 신호를 읽습니다.
LCD1602 또는 LCD2004의 경우 VCC 핀을 5V 핀에, GND 핀을 접지에 연결하세요. LCD의 SDA 핀은 Arduino의 SDA 핀(일반적으로 UNO에서 A4)에 연결하고, SCL 핀은 Arduino의 SCL 핀(일반적으로 UNO에서 A5)에 연결해야 합니다. 모든 연결이 안전한지 확인하여 제대로 작동하도록 하세요.
코드 예제 및 설명
코드에서 #define VIN A0으로 센서 출력을 읽기 위한 아날로그 입력 핀을 정의합니다. 이를 통해 프로그램 전체에서 센서가 연결된 핀을 쉽게 참조할 수 있습니다.
#define VIN A0 // Arduino 핀 A0를 전압 입력(V in)으로 정의
const float VCC = 5.0; // 공급 전압은 4.5~5.5V. 일반적으로 5V.
다음으로 사용 중인 ACS712 모델에 따라 감도를 설정합니다. 감도 값은 배열에 저장되어 모델 선택에 따라 쉽게 접근할 수 있습니다.

const int model = 2; // 모델 번호 입력(5A, 20A, 30A의 경우 0, 1, 2)
float sensitivity[] = {0.185, 0.100, 0.066}; // 각 모델의 감도 값
setup() 함수에서 시리얼 모니터와 LCD 디스플레이를 초기화합니다. 이를 통해 디버깅을 위해 LCD와 시리얼 모니터 모두에서 전류 측정값을 확인할 수 있습니다.
void setup() {
Serial.begin(9600); // 시리얼 모니터 초기화
lcd.begin(); // LCD 초기화
lcd.backlight(); // 백라이트 켜기
lcd.print("Robojax ACS712"); // 초기 텍스트 표시
delay(2000); // 2초 대기
}
loop() 함수는 센서에서 전압을 읽고 감도에 따라 전류를 계산한 후 결과를 표시합니다. 전류가 지정된 차단 한계를 초과하면 값을 표시하고, 그렇지 않으면 전류가 감지되지 않았음을 나타냅니다.
시연 / 기대 효과
회로에 전원을 공급하면 LCD에 "Robojax ACS712" 다음에 "Current: "와 측정된 전류 값(암페어)이 표시됩니다. 전류가 차단 한계보다 낮으면 디스플레이에 "No Current"가 표시됩니다. 센서가 뜨거워질 수 있으므로 높은 전류로 테스트할 때 주의하세요(영상 12:00).
설정을 테스트하려면 ACS712를 통과하는 전류를 점차 증가시키고 LCD와 시리얼 모니터의 변화를 관찰하세요. 손상을 방지하려면 전류가 센서의 정격 한계를 초과하지 않도록 하세요.
이미지
/*
*
* Arduino Sketch for Allegro ACS712 Current Sensor with LCD1602/LCD2004 with I2C
* This sensor can measure current at a range of up to 30A.
* The current is measured and displayed on LCD1602 or LCD2004.
* The current is also displayed on the Serial monitor (click Tools->Serial monitor).
* It operates with 5V.
* Please watch the video instruction and explanation for this code.
*
* Written by Ahmad Shamshiri on July 14, 2018 at 07:02 in Ajax, Ontario, Canada
* for Robojax.com
* View the video instruction at https://youtu.be/kzXouSzvcp8
* This code has been downloaded from Robojax.com
* You must watch the following two videos before you can understand this:
* 1- Introduction to ACS712 Current Sensor: https://www.youtube.com/watch?v=DVp9k3xu9IQ
* 2- LCD1602 with I2C display: https://www.youtube.com/watch?v=q9YC_GVHy5A
*/
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const float VCC = 5.0;// supply voltage is from 4.5 to 5.5V. Normally 5V.
const int model = 2; // enter the model number (see below)
float cutOffLimit = 1.01;// set the current which, below that value, doesn't matter. Or set 0.5
/*
"ACS712ELCTR-05B-T",// for model use 0
"ACS712ELCTR-20A-T",// for model use 1
"ACS712ELCTR-30A-T"// for model use 2
Sensitivity array is holding the sensitivity of the ACS712
current sensors. Do not change. All values are from page 5 of the data sheet
*/
float sensitivity[] ={
0.185,// for ACS712ELCTR-05B-T
0.100,// for ACS712ELCTR-20A-T
0.066// for ACS712ELCTR-30A-T
};
const float QOV = 0.5 * VCC;// set quiescent Output voltage of 0.5V
float voltage;// internal variable for voltage
// 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() {
//Robojax.com ACS712 Current Sensor
Serial.begin(9600);// initialize serial monitor
Serial.println("Robojax Tutorial");
Serial.println("ACS712 Current Sensor");
// initialize the LCD
lcd.begin();
lcd.backlight();
lcd.print("Robojax ACS712");
lcd.setCursor(0,1);
lcd.print("Demo");
delay(2000);
}
void loop() {
//Robojax.com ACS712 Current Sensor with LCD1601
float voltage_raw = (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
voltage = voltage_raw - QOV + 0.012 ;// 0.000 is a value to make voltage zero when there is no current
float current = voltage / sensitivity[model];
if(abs(current) > cutOffLimit ){
Serial.print("V: ");
Serial.print(voltage,3);// print voltage with 3 decimal places
Serial.print("V, I: ");
Serial.print(current,2); // print the current with 2 decimal places
Serial.println("A");
//start of loop Robojax code ACS712 with LCD1602 and I2C
lcd.clear();
lcd.setCursor (0,0); // set to line 1, char 0
lcd.print("Robojax ACS712");
lcd.setCursor (0,1); // set to line 1, char 0
lcd.print("Current: ");
lcd.setCursor (9,1); // go to start of 2nd line
lcd.print(current);
lcd.setCursor (14,1); // go to start of 2nd line
lcd.print("A");
}else{
Serial.println("No Current");
lcd.clear();
lcd.setCursor (0,0); // set to line 1, char 0
lcd.print("No Current");
}
delay(500);
}
필요할 수 있는 것들
-
아마존Buy LCD1602-I2C from Amazonamzn.to
-
아마존
-
이베이Purchase LCD1602-I2C from eBayebay.us
-
알리익스프레스Purchase 10pcs LCD1602-I2C from AliExpresss.click.aliexpress.com
자원 및 참고자료
-
외부
파일📁
아두이노 라이브러리 (zip)
-
LCD1602 LCD Arduino library from Robojax
robojax-LCD1602-I2C-library-master.zip0.01 MB
데이터시트 (pdf)
-
Allegro ACS712 AC/DC 4A, 20A, 30A Current Sensor Datasheet
robojax-allegro_ACS712_current_sensor.pdf0.65 MB
프리징 파일
-
LCD LCD1602-I2C module with 4 wires
LCD1602-I2C.fzpz0.01 MB -
Allegre ACS712 Current Sensor
Allegreo ACS712 Current Sensor.fzpz0.03 MB