Arduino용 SSD1306 OLED 디스플레이와 Allegro ACS758 전류 센서를 사용하여 전류 측정하기
이 튜토리얼에서는 Allegro ACS758 전류 센서를 사용하여 전류를 측정하고 그 결과를 SSD1306 OLED 디스플레이에 표시하는 과정을 안내합니다. 이 프로젝트는 회로에 흐르는 전류를 읽고 그 데이터를 OLED 화면에 시각적으로 표현하여 쉽게 모니터링할 수 있도록 합니다. 구성 요소를 연결하는 방법, 코드 작성 방법, 그리고 모든 것이 어떻게 함께 작동하는지 이해하게 될 것입니다.


코드와 그 기능을 이해하고 싶다면 비디오에서 더 자세한 설명을 확인하세요 (비디오 02:45 부분).
하드웨어 설명
이 프로젝트의 주요 구성 요소는 Allegro ACS758 전류 센서와 SSD1306 OLED 디스플레이입니다. ACS758은 도체에 흐르는 전류를 높은 정확도로 측정하고 이 전류에 비례하는 출력 전압을 제공하는 홀 효과 전류 센서입니다. 최대 200A의 전류를 처리할 수 있으며 3.3V 또는 5V에서 작동합니다.
SSD1306 OLED 디스플레이는 I2C를 통해 통신하는 소형 저전력 디스플레이입니다. 통합이 쉽고 그래픽과 텍스트를 명확하게 표시할 수 있어 Arduino 프로젝트에서 일반적으로 사용됩니다. 이러한 구성 요소들이 함께 다양한 응용 분야에서 전류를 모니터링하는 강력한 도구를 만듭니다.
데이터시트 세부 정보
| 제조업체 | Allegro Microsystems |
|---|---|
| 부품 번호 | ACS758ECB-200U |
| 로직/IO 전압 | 3.3 V / 5 V |
| 공급 전압 | 5 V |
| 출력 전류 (채널당) | 200 A |
| 피크 전류 (채널당) | 200 A |
| PWM 주파수 가이드 | 해당 없음 |
| 입력 로직 임계값 | 0.3 V (낮음), 2.7 V (높음) |
| 전압 강하 / RDS(on) / 포화 | 0.05 V |
| 열 제한 | -40 ~ 125 °C |
| 패키지 | SOIC-8 |
| 참고 사항 / 변형 | 양방향 및 단방향 모델 사용 가능 |
- 정확한 판독을 위해 ACS758 센서의 방향을 올바르게 설정하세요.
- 과열을 방지하기 위해 최대 전류 한계 근처에서 작동할 때 방열판을 사용하세요.
- 안정적인 작동을 위해 센서의 전원 공급 장치를 디커플링하세요.
- 오류 판독을 유발할 수 있는 플로팅 입력을 피하기 위해 배선 연결을 확인하세요.
- 정확한 전류 측정을 위해 센서 출력을 보정하세요.
배선 지침

Allegro ACS758 전류 센서와 SSD1306 OLED 디스플레이를 배선하려면 먼저 전원을 연결하세요. ACS758의 VCC 핀을 Arduino의 5V 출력에 연결하고 GND 핀을 Arduino의 접지(GND)에 연결하세요. ACS758의 출력 신호 핀(Vout)은 Arduino의 아날로그 입력 핀 A0에 연결해야 합니다.
다음으로 SSD1306 OLED 디스플레이의 경우 VCC 핀을 Arduino의 5V 출력에 연결하고 GND 핀을 접지에 연결하세요. OLED의 SDA 핀을 Arduino의 SDA 핀(대부분의 Arduino 보드에서 A4)에 연결하고 OLED의 SCL 핀을 SCL 핀(대부분의 Arduino 보드에서 A5)에 연결하세요. 안정적인 작동을 위해 모든 연결이 확실한지 확인하세요.
코드 예제 및 설명
#define VIN A0 // Arduino 핀 A0을 전압 입력(V in)으로 정의
const float VCC = 5.0; // 공급 전압 5V 또는 3.3V
const int model = 2; // 모델 입력 (아래 참조)
코드에서 VIN 변수는 ACS758 센서의 전압을 읽을 아날로그 핀 A0에 할당됩니다. VCC 변수는 공급 전압을 설정하고, model 변수는 사용 중인 ACS758 모델을 정의하며, 이는 감도와 출력 전압 계산에 영향을 줍니다.
void loop() {
float voltage_raw = (5.0 / 1023.0) * analogRead(VIN); // 센서에서 전압 읽기
float current = voltage / FACTOR; // 전압을 기반으로 전류 계산
}
loop() 함수 내에서 코드는 analogRead(VIN)을 사용하여 센서의 원시 전압을 읽고 정의된 감도에 따라 전류 값으로 변환합니다. 이를 통해 회로에 흐르는 전류를 실시간으로 모니터링할 수 있습니다.
if(abs(voltage) > cutOff) {
display.clearDisplay();
robojaxText("Current:", 0, 22, 2, false);
}
이 조건문은 전압의 절대값이 cutOff 한계보다 큰지 확인합니다. 참이면 디스플레이를 지우고 전류 판독값으로 OLED를 업데이트합니다. 이는 중요한 전류 값만 표시되도록 하여 디스플레이의 혼란을 방지합니다.
시연 / 기대 효과
프로그램을 실행하면 OLED 디스플레이에 측정 중인 전류가 실시간으로 표시됩니다. 전류가 흐르지 않으면 디스플레이에 "No Current"가 표시됩니다. 극성 반전과 같은 문제로 인해 부정확한 판독이 발생하지 않도록 연결이 올바른지 확인하세요 (비디오 05:30 부분).
/*
* Arduino Sketch for Allegro ACS758 Current Sensor with SSD1306 OLED Display
* can be used with 128x64 or 128x32 OLED displays with SSD1306 chip
* this sensor can measure current at a range of up to 200A
* It operates with 3.3V or 5V
* This video requires you to watch the following 2 videos before using this code:
* 1- ACS758 Sensor https://www.youtube.com/watch?v=SiHfjzcqnU4
* 2- SSD1306 OLED Display https://www.youtube.com/watch?v=UmYiHTOz-5k
*
* View the video instructions for this code at https://youtu.be/aHg9UrK9s9c
* Written by Ahmad Shamshiri for Robojax Video channel www.Robojax.com
* Date: June 24, 2018, at 21:44 in Ajax, Ontario, Canada
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: This code is "AS IS" and for educational purposes only.
* This code has been downloaded from https://robojax.com
*
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 64
#define LOGO16_GLCD_WIDTH 128
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
///*** ACS758 settings starts
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const float VCC = 5.0;// supply voltage 5V or 3.3V. If using PCB, set to 5V only.
const int model = 2; // enter the model (see below)
float cutOffLimit = 1.00;// reading cutt off current. 1.00 is 1 Amper
/*
"ACS758LCB-050B",// for model use 0
"ACS758LCB-050U",// for model use 1
"ACS758LCB-100B",// for model use 2
"ACS758LCB-100U",// for model use 3
"ACS758KCB-150B",// for model use 4
"ACS758KCB-150U",// for model use 5
"ACS758ECB-200B",// for model use 6
"ACS758ECB-200U"// for model use 7
sensitivity array is holding the sensitivity of the ACS758
current sensors. Do not change.
*/
float sensitivity[] ={
40.0,// for ACS758LCB-050B
60.0,// for ACS758LCB-050U
20.0,// for ACS758LCB-100B
40.0,// for ACS758LCB-100U
13.3,// for ACS758KCB-150B
16.7,// for ACS758KCB-150U
10.0,// for ACS758ECB-200B
20.0,// for ACS758ECB-200U
};
/*
* Quiescent output voltage is a factor of VCC that appears at the output
* when the current is zero.
* For bidirectional sensors it is 0.5 x VCC
* For unidirectional sensors it is 0.12 x VCC
* For model ACS758LCB-050B, the B at the end represents Bidirectional (polarity doesn't matter)
* For model ACS758LCB-100U, the U at the end represents Unidirectional (polarity must match)
* Do not change.
*/
float quiescent_Output_voltage [] ={
0.5,// for ACS758LCB-050B
0.12,// for ACS758LCB-050U
0.5,// for ACS758LCB-100B
0.12,// for ACS758LCB-100U
0.5,// for ACS758KCB-150B
0.12,// for ACS758KCB-150U
0.5,// for ACS758ECB-200B
0.12,// for ACS758ECB-200U
};
const float FACTOR = sensitivity[model]/1000;// set sensitivity for selected model
const float QOV = quiescent_Output_voltage [model] * VCC;// set quiescent Output voltage for selected model
float voltage;// internal variable for voltage
float cutOff = FACTOR/cutOffLimit;// convert current cut off to mV
//**** ACS758 settings ends
void setup() {
Serial.begin(9600);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
}
void loop() {
//Robojax.com ACS758 Current Sensor values start
float voltage_raw = (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
voltage = voltage_raw - QOV + 0.003 ;// 0.007 is a value to make voltage zero when there is no current
float current = voltage / FACTOR;
if(abs(voltage) > cutOff ){
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");
display.clearDisplay();
robojaxText("V:", 0, 0, 2, false);
String voltageS = String(voltage);// get voltage and convert it to string for display
robojaxText(voltageS +"V", 20, 0, 2, false);
robojaxText("Current:", 0, 22, 2, false);
String currentS = String(current);// get current and convert it to string for display
robojaxText(currentS +"A", 0, 40, 3, false);
display.display();
}else{
Serial.println("No Current");
display.clearDisplay();
robojaxText("No Current", 0, 0, 2, false);
display.display();
}
//Robojax.com ACS758 Current Sensor values end
delay(500);
}
/*
* robojaxText(String text, int x, int y,int size, boolean d)
* text is the text string to be printed
* x is the integer x position of the text
* y is the integer y position of the text
* size is the text size, 1, 2, 3 etc
* d is either true or false. Use true to display immediately.
*/
void robojaxText(String text, int x, int y,int size, boolean d) {
display.setTextSize(size);
display.setTextColor(WHITE);
display.setCursor(x,y);
display.println(text);
if(d){
display.display();
}
delay(100);
}
필요할 수 있는 것들
-
아마존Purchase OLED 128x32 from Amazonamzn.to
-
아마존
-
알리익스프레스Purchase SSD1306 OLED 128x32 from AliExpresss.click.aliexpress.com
자원 및 참고자료
아직 자원이 없습니다.
파일📁
아두이노 라이브러리 (zip)
-
SSD1306-OLED-Adafruit_SSD1306-master
robojax-SSD1306-OLED-Adafruit_SSD1306-master.zip0.02 MB
데이터시트 (pdf)
-
SSD1306 display datasheetSSD1306 is a single-chip CMOS OLED/PLED driver with controller for organic / polymer light emitting diode dot-matrix graphic display system. It consists of 128 segments and 64commons. This IC is designed for Common Cathode type OLED panel. The SSD1306 embeds with contrast control, display RAM and oscillator, which reduces the number of external components and power consumption. It has 256-step brightness control. Data/Commands are sent from general MCU through the hardware selectable 6800/8000 series compatible Parallel Interface, I2C interface or Serial Peripheral Interface. It is suitable for many compact portable applications, such as mobile phone sub-display, MP3 player and calculator, etc.
SSD1306_display_datasheet.pdf1.79 MB
프리징 파일
-
OLED Mono 0.56 inch 128x32
OLED Mono 0.56 inch 128x32.fzpz0.01 MB -
SSD1306 0.96in 128x64 I2C Monochrome OLED Display
SSD1306 0.96in 128x64 I2C Monochrome OLED Display.fzpz0.01 MB
사용자 매뉴얼
-
SSD1306 OLED manual
robojax-SSD1306-OLED-manual.pdf1.79 MB
다른 파일들
-
Alegro ACS Current LibraryArduino library for Allegro ACS current sensor modules. Provides functions to read current measurements from ACS712 and similar sensors.
robojax_Alegro_ACS_Current_library.zip0.02 MB