شِفر (کود) جستجو

حساس(حس کننده) جریان Allegro ACS758 با نمایشگر LCD و حفاظت در برابر اضافه‌جریان برای آردوینو

حساس(حس کننده) جریان Allegro ACS758 با نمایشگر LCD و حفاظت در برابر اضافه‌جریان برای آردوینو

در این آموزش یاد می‌گیریم چگونه از حساس(حس کننده) جریان Allegro ACS758 همراه با یک LCD برای نمایش مقادیر جریان استفاده کنیم و حفاظت در برابر اضافه‌جریان را پیاده‌سازی کنیم. این پیکربندی به ما اجازه می‌دهد جریان را مانیتور کنیم و در صورتی که از حد از پیش تعیین‌شده فراتر رود، بار را به‌طور خودکار قطع کنیم. این پروژه ترکیبی از اجزای سخت‌افزاری و نرم‌افزاری است تا یک سیستم نظارت بر جریان کاربردی ایجاد کند.

با دنبال کردن این راهنما می‌توانید قطعات را به‌درستی سیم‌کشی کنید و منطق برنامه‌نویسی پشت شِفر (کود) را درک کنید. برای توضیحی تصویری‌تر، حتماً ویدیوی مرتبط را (در ویدیو در 00:00) مشاهده کنید.

سخت‌افزار به زبان ساده

اجزای کلیدی در این پروژه شامل حساس(حس کننده) جریان Allegro ACS758، نمایشگر LCD1602 با رابط I2C و یک برد آردوینو هستند. حساس(حس کننده) ACS758 جریان عبوری از آن را اندازه‌گیری کرده و ولتاژی متناسب با جریان را خروجی می‌دهد. نمایشگر LCD1602 مقادیر جریان و پیام‌های وضعیت را نمایش می‌دهد، در حالی که آردوینو داده‌ها را پردازش کرده و برای حفاظت در برابر جریان بیش از حد ریلی را کنترل می‌کند.

حساس(حس کننده) ACS758 بر پایهٔ مفهومی به نام حسگری اثر هال کار می‌کند که امکان اندازه‌گیری جریان بدون تماس الکتریکی مستقیم را فراهم می‌آورد. ولتاژ خروجی بسته به مقدار جریان عبوری تغییر می‌کند و روشی ایمن و کارآمد برای پایش بارهای الکتریکی ارائه می‌دهد.

جزئیات مشخصات فنی

تولیدکننده الگرو میکروسیستمز
شماره قطعه ACS758
ولتاژ منطقی/ورودی-خروجی 3.3V / 5V
ولتاژ تغذیه ۵ ولت
جریان خروجی (برای هر کانال) حداکثر 200A
جریان اوج (برای هر کانال) 200A
راهنمای فرکانس PWM غیرقابل‌اعمال
آستانه‌های منطقی ورودی 0.5 x VCC (دوطرفه)
افت ولتاژ بر Rدرین-سورس (روشن)/ اشباع نامرتبط
محدودیت‌های حرارتی 150°C
بسته نصب روی برد مدار چاپی
یادداشت‌ها / واریانت‌ها چندین مدل برای محدوده‌های مختلف جریان موجود است

  • اگر نزدیک به حداکثر مقادیر نامی کار می‌کنید، از هیت‌سینک مناسب اطمینان حاصل کنید.
  • برای تثبیت ولتاژ منبع تغذیه از خازن‌های دکوپلینگ استفاده کنید.
  • بررسی کنید که ریلی مورد استفاده می‌تواند حداکثر جریان بار را تحمل کند.
  • در سیم‌کشی مراقب باشید تا از اتصال کوتاه جلوگیری شود.
  • اشتباهات رایج شامل ورودی‌های شناور است؛ مطمئن شوید که همهٔ اتصالات محکم باشند.
  • در استفادهٔ طولانی‌مدت بر گرم شدن بیش از حد حساس(حس کننده) نظارت کنید.

قطعات مورد نیاز

  • حساس(حس کننده) جریان ACS758
  • ریلی 12 ولت 100 آمپر
  • LCD1602 با I2C (4 سیم)
  • ترانزیستور 2N2222 یا 2N3904
  • 1k اهم 1/4 وات یا هر مقاومت توانی
  • منبع تغذیه برای ریلی
  • منبع تغذیه برای بار شما
  • بردبورد
  • سیم‌های جامپر

دستورالعمل سیم‌کشی

Arduino wiring for ACS758 current sensor with LCD and protection relay
Arduino wiring for ACS758 current sensor with LCD and protection relay

برای سیم‌کشی حساس(حس کننده) جریان Allegro ACS758 و نمایشگر LCD1602، ابتدا با اتصال حساس(حس کننده) ACS758 شروع کنید. آن را وصل کنیدVCCپایه حساس(حس کننده) را به پایه 5V روی آردوینو وصل کنید. اینGNDپایه باید به یک پایه زمین روی آردوینو متصل شود. آنSپایه سیگنال حساس(حس کننده) باید به پایه ورودی آنالوگ متصل شود.A0روی آردوینو.

سپس، برای LCD1602، وصل کنیدVCCپایه را به پایه 5V روی آردوینو وGNDبه زمین میخکوب کردن. آنSDAپایه LCD باید بهA4پایه (SDA) روی آردوینو، در حالی کهSCLپایه باید به آن متصل شودA5پایه (SCL) روی آردوینو. در نهایت، یک ماجیول ریلی را به پایه دیجیتال متصل کنید.2برای کنترل بار بر اساس قرائت‌های جریان.

نمونه‌های شِفر (کود) و راهنمای گام‌به‌گام

در شِفر (کود) آردوینو، ما با تعریف شناسه‌های کلیدی مانند ... شروع می‌کنیمVIN، که نشان‌دهنده پایه ورودی آنالوگ متصل به حساس(حس کننده) ACS758 است. اینrelayPinبرای کنترل ریلی تنظیم شده است، در حالی کهmaxCurrentآستانه حفاظت در برابر اضافه‌جریان را تعریف می‌کند.

#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const int relayPin = 2; // set a digital pin for relay
const float maxCurrent = 15.00; // set maximum Current

آنsetup()این تابع LCD را مقداردهی اولیه می‌کند و پایه ریلی را به‌عنوان خروجی تنظیم می‌کند. همچنین یک پیام خوش‌آمدگویی روی LCD چاپ می‌کند که کاربر را دربارهٔ حساس(حس کننده) جریان مورد استفاده مطلع می‌سازد.

void setup() {
    pinMode(relayPin, OUTPUT); // set relayPin as output
    Serial.begin(9600); // initialize serial monitor
    lcd.begin(); // initialize the LCD
    lcd.backlight(); // Turn on the blacklight
    lcd.print("Robojax");
}

درloop()در این تابع، ما به‌طور مداوم ولتاژ را از حساس(حس کننده) می‌خوانیم و جریان را محاسبه می‌کنیم. اگر جریان از حد مجاز فراتر رود، ریلی فعال می‌شود تا بار را قطع کند. این منطق تضمین می‌کند که سیستم خود را در برابر شرایط اضافه‌جریان محافظت کند.

void loop() {
  float voltage_raw = (5.0 / 1023.0) * analogRead(VIN); // Read the voltage from sensor
  float current = voltage / FACTOR; // Calculate current
  if (current >= minCurrent) {
    if (current <= maxCurrent) {
      digitalWrite(relayPin, LOW); // turn the relay OFF to allow current
    } else {
      digitalWrite(relayPin, HIGH); // turn the relay ON to disconnect current
    }
  }
}

نمایش / آنچه انتظار می‌رود

پس از اینکه همه‌چیز سیم‌کشی شد و شِفر (کود) آپلود شد، نمایشگر LCD خوانش‌های جریان فعلی را نشان خواهد داد. اگر جریان از مقدار تعریف‌شده فراتر رودmaxCurrent, ریلی فعال می‌شود و بار را قطع می‌کند. شما می‌توانید این را با افزایش تدریجی جریان بار و مشاهدهٔ تغییرات روی LCD و در نمایشگر مسلسل امتحان کنید. مطمئن شوید از اتصالات با پلاریته معکوس خودداری کنید، زیرا این می‌تواند به قطعات آسیب برساند (در ویدئو در 10:15).

تصاویر

LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
ACS758-sensor-0
ACS758-sensor-0
ACS758-sensor-1
ACS758-sensor-1
ACS758-sensor-3
ACS758-sensor-3
ACS758-sensor-4
ACS758-sensor-4
Arduino wiring for ACS758 current sensor with LCD and protection relay
Arduino wiring for ACS758 current sensor with LCD and protection relay
111-Arduino Code for Allegro ACS758 Current Sensor with LCD160
زبان: C++
/*
 * 
 * Arduino Sketch for Allegro ACS758 Current Sensor with LCD1602 & I2C module and current protection
 * This sensor can measure current at a range of up to 200A. It has overcurrent protection with a relay to disconnect the load if 
 * the current reaches beyond the limit.
 * It operates with 3.3V or 5V.
 * This sketch requires you to watch the following 2 videos before using this code:
 * 1- ACS758 Sensor https://www.youtube.com/watch?v=SiHfjzcqnU4
 * 2- LCD1602 with I2C https://www.youtube.com/watch?v=q9YC_GVHy5A
 * 3- Combined 1 and 2 in one video https://www.youtube.com/watch?v=tug9wjCwDQA
 * 4- Allegro ACS with Robojax Library (latest video and code) https://youtu.be/sB6EULTix2k
 * 
 * Written by Ahmad Shamshiri on Tuesday, June 26, 2018 at 17:56 in Ajax, Ontario, Canada
 * for Robojax.com
 * You can watch a detailed video on the ACS758 Current sensor at: https://youtu.be/SiHfjzcqnU4
 * This code has been explained in this video: https://youtu.be/GE4I10IZ1jY
 * This code has been downloaded from Robojax.com
 */
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const int relayPin = 2;// set a digital pin for relay
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)

const float maxCurrent = 15.00;// set maximum Current 
int maxCurrentWait = 6000;// wait time before current is connected

float minCurrent = 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   
The sensitivity array holds 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


// ======== start of LCD1602 with i2C settings
#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  LCD1602 with i2C settings
void setup() {
    //Robojax.com ACS758 Current Sensor 
    pinMode(relayPin,OUTPUT);// set relayPin as output
    Serial.begin(9600);// initialize serial monitor
    Serial.println("Robojax Tutorial");
    Serial.println("ACS758 Current Sensor");
    Serial.println("with LCD1602 & I2C");    
    // initialize the LCD, 
    lcd.begin();   
  // Turn on the blacklight and print a message.
  lcd.backlight(); 
    lcd.clear();
  lcd.print("Robojax");
  lcd.setCursor (0,1); // go to start of 2nd line 
  lcd.print("ACS758 Current Sensor"); 
  delay(2000); 
  lcd.clear();  
}

void loop() {
  //Robojax code ACS758 with LCD1602 and I2C
  float voltage_raw =   (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
  voltage =  voltage_raw - QOV + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
  float current = voltage / FACTOR;
  if( current >= minCurrent){
     if(current <= maxCurrent)
     {
              Serial.print("Current Limit: ");
              Serial.print(maxCurrent,3);// print voltage with 3 decimal places
              Serial.print("A, I: ");
              Serial.print(current,2); // print the current with 2 decimal places
              Serial.println("A");
              //start of loop Robojax code ACS758 with LCD1602 and I2C
              lcd.clear();
              lcd.setCursor (0,0); // set to line 1, char 0  
              lcd.print("Current: ");
              lcd.setCursor (9,0); // go to start of 2nd line
              lcd.print(current);
              lcd.setCursor (15,0); // go to start of 2nd line
              lcd.print("A");
            
              lcd.setCursor (0,1);    
              lcd.print("I Limit: ");
              lcd.setCursor (9,1); // go to start of 2nd line
              lcd.print(maxCurrent);
              lcd.setCursor (15,1); // go to start of 2nd line
              lcd.print("A");   
              lcd.backlight();
             //end of loopcode Robojax code ACS758 with LCD1602 and I2C

              digitalWrite(relayPin,LOW);// turn the relay OFF to allow the current.
     }else{
      // the lines bellow will execute if current reaches above the maxCurrent value
              digitalWrite(relayPin,HIGH);// turn the relay ON to disconnect the current.
              
              Serial.print("Max Reached:");
              Serial.print(maxCurrent,3);// print the maxCurrent
              Serial.println("A");              
              Serial.print("Disconnected ");

              //start of loop Robojax code ACS758 with LCD1602 and I2C
              lcd.clear();
              lcd.setCursor (0,0); // set to line 1, char 0  
              lcd.print("I Max: ");
              lcd.setCursor (8,0); // go to start of 2nd line
              lcd.print(maxCurrent);
              lcd.setCursor (15,0); // go to start of 2nd line
              lcd.print("A");
            
              lcd.setCursor (0,1);    
              lcd.print("Disconnected");    
              lcd.backlight();
             //end of loopcode Robojax code ACS758 with LCD1602 and I2C 
             delay(maxCurrentWait );// wait for maxCurrentWait  seconds     
     }
    
  }else{
    Serial.println("No Current");
  lcd.clear();    
  lcd.setCursor (0,0);    
  lcd.print("No Current");
  digitalWrite(relayPin,LOW);// turn the relay OFF to allow the current.
          
  }
  delay(500);
}

مواردی که ممکن است به آن‌ها نیاز داشته باشید

فایل‌ها📁

برگه مشخصات (pdf)