検索コード

ACS712を使用してI2C接続のLCD1602またはLCD2004に電流を表示する

ACS712を使用してI2C接続のLCD1602またはLCD2004に電流を表示する

このチュートリアルでは、Allegro ACS712 電流センサーを使って交流(AC)と直流(DC)の両方の電流を測定し、I2C を使って LCD1602 または LCD2004 に測定値を表示する方法を学びます。このプロジェクトはさまざまな用途で電流を監視するのに特に役立ち、リアルタイムの電流データを視覚的に表示します。最後まで進めば、LCD に正確な電流表示が行える実用的なセットアップが完成します。

LCD1602-I2C display module with 4 wires

配線とコードについての説明を確認するには、指定されたタイムスタンプ(動画の00:00)を必ずご覧ください。

ハードウェア解説

このプロジェクトの主要部品はACS712電流センサーで、最大30Aまでの電流を測定できます。ホール効果を利用して流れる電流をそれに比例した電圧出力に変換して動作します。この電圧出力はArduinoで読み取って電流値を算出できます。センサーにはVCC(電源)、GND(接地)、OUT(電圧信号)の3つのピンがあります。

LCD1602やLCD2004のディスプレイはI2Cで接続でき、電源とグランドに加えてデータ用のSDAとSCLの2本のピンだけで配線や制御が簡単になります。これにより、複数の接続で配線が煩雑になることなく、現在の測定値を表示することが容易になります。

データシートの詳細

製造元アレグロ・マイクロシステムズ
部品番号ACS712ELCTR-30A-T
ロジック/IO電圧4.5〜5.5 V
供給電圧5 V
出力電流(チャンネルあたり)30アンペア
PWM周波数に関するガイダンス該当なし
入力論理閾値0.5 V(無信号時出力)
電圧降下 / RDS(オン)/ 彩度1.2 mΩ
熱限界最大150°C
パッケージTO-220

  • 20Aを超える電流に対しては、適切な放熱を確保してください。
  • 過熱を避けるため、適切な電線ゲージ(30Aには12 AWG)を使用してください。
  • 正しく動作させるために、VCCを5Vに、GNDを接地(グランド)に接続してください。
  • OUTピンがArduinoのアナログ入力ピン(例: A0)に接続されていることを確認してください。
  • 各種ACS712モデル間の感度差に注意してください。
  • データシートに記載されているとおりにデカップリング用コンデンサを使用してください。

配線手順

Arduino wiring for Allegro ACS712 current sensor with LCD

ACS712電流センサーをArduinoとLCDに配線するには、まずACS712のVCCピンをArduinoの5Vピンに接続します。次にACS712のGNDピンをArduinoのGNDピンに接続します。ACS712のOUTピンはArduinoのアナログピンに接続してください。A0Arduino上で電圧信号が読み取られる場所。

LCD1602またはLCD2004の場合、VCCピンを5Vピンに、GNDピンをグラウンドに接続してください。LCDのSDAピンはArduinoのSDAピンに接続してください(通常A4(UNOの場合)、SCLピンは通常ArduinoのSCLピンに接続する必要があります(A5UNO上)。正常に動作するよう、すべての接続が確実であることを確認してください。

コード例とウォークスルー

コード内では、センサーの出力を読み取るためのアナログ入力ピンを定義します#define VIN A0これにより、プログラム全体でセンサーが接続されているピンを簡単に参照できます。

#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.

次に、使用しているACS712のモデルに基づいて感度を設定します。感度の値は配列に格納されており、モデル選択に応じて簡単にアクセスできます。

const int model = 2; // enter the model number (0, 1, or 2 for 5A, 20A, or 30A)
float sensitivity[] = {0.185, 0.100, 0.066}; // sensitivity values for each model

その中でsetup()この関数では、シリアルモニタとLCDディスプレイを初期化します。これにより、デバッグのためにLCD上とシリアルモニタの両方で現在の読み取り値を確認できます。

void setup() {
    Serial.begin(9600); // initialize serial monitor
    lcd.begin(); // initialize the LCD
    lcd.backlight(); // turn on the backlight
    lcd.print("Robojax ACS712"); // display initial text
    delay(2000); // wait for 2 seconds
}

そのloop()関数はセンサーから電圧を読み取り、感度に基づいて電流を計算し、それに応じて結果を表示します。電流が指定されたカットオフ値を超える場合はその値を表示し、そうでなければ電流が検出されないことを示します。

デモンストレーション/当日の流れ

回路に電源を入れると、LCDには「Robojax ACS712」が表示され、その後に測定された電流値(アンペア)が「Current: 」とともに表示されます。電流がカットオフ限界以下の場合、表示は「No Current.」になります。高い電流でテストする際はセンサーが熱くなることがあるので注意してください(ビデオの12:00)。

セットアップをテストするために、ACS712に流れる電流を徐々に増やし、LCDとシリアルモニターの表示の変化を観察してください。破損を避けるため、電流がセンサーの定格値を超えないようにしてください。

画像

Allegro ACS712 DC/AC電流センサー LCD1602/LCD2004 I2C付き Arduinoコード
Allegro ACS712 DC/AC電流センサー LCD1602/LCD2004 I2C付き Arduinoコード
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
ACS712_in_series_with_load
ACS712_in_series_with_load
allegro_ACS712_module-1
allegro_ACS712_module-1
allegro_ACS712_module-2
allegro_ACS712_module-2
allegro_ACS712_module-4
allegro_ACS712_module-4
allegro_ACS712_module-0
allegro_ACS712_module-0
Arduino wiring for Allegro ACS712 current sensor with LCD
Arduino wiring for Allegro ACS712 current sensor with LCD
131-Allegro ACS712 DC/AC current sensor with LCD1602/LCD2004 I2C and Arduino code
言語: C++
/*
 * 
 * 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);
}

必要かもしれないもの

ファイル📁

Arduinoライブラリ(zip)

データシート(pdf)

フリッツィングファイル