Lilo ACS712 lati Ṣe Afihan Agbara lori LCD1602 tabi LCD2004 pẹlu I2C
Nínú ẹ̀kọ́ yìí, a óò kọ́ bí a ṣe le lo Allegro ACS712 current sensor láti wọn àkópọ̀ AC àti DC current, kí a sì fi àbájáde rẹ̀ hàn lórí LCD1602 tàbí LCD2004 nípa lílo I2C. Iṣẹ́ yìí wúlò pàtàkì fún mímójútó current nínú oríṣiríṣi àwọn ohun èlò, tí ó ń pèsè ìfihàn ojú tí ó hàn ní àkókò gidi fún data current. Ní ìparí, ìwọ yóò ní ètò tí ó ń ṣiṣẹ́ tí ó lè fi àwọn ìwọ̀n current hàn lórí LCD ní pípé.


Fún ìṣàlàyé nípa bí a ṣe so àwọn okun àti kóòdù, rí i dájú pé o wo fídíò náà ní àwọn àkókò tí a mọ̀ (nínú fídíò ní 00:00).
Ohun èlò Tí A Ṣàlàyé
Ohun èlò pàtàkì nínú iṣẹ́ yìí ni ACS712 current sensor, èyí tí ó lè wọn ìwọ̀n current títí di 30A. Ó ń ṣiṣẹ́ nípa lílo Hall effect láti yí current tí ó ń ṣàn ní inú rẹ̀ padà sí ìwọ̀n voltage tí ó bá mu. Ìwọ̀n voltage yìí ni Arduino lè kà láti ṣe ìṣirò ìwọ̀n current náà. Sensor náà ní àwọn pin mẹ́ta fún ìsopọ̀: VCC fún agbára, GND fún ilẹ̀, àti OUT fún àmì voltage.
LCD1602 tàbí LCD2004 display ń sopọ̀ nípasẹ̀ I2C, èyí tí ó jẹ́ kí ìsopọ̀ okun àti ìdarí rọrùn nípa lílo àwọn pin data méjì péré (SDA àti SCL) yàtọ̀ sí agbára àti ilẹ̀. Èyí jẹ́ kí ó rọrùn láti fi àwọn ìwọ̀n current hàn láìsí bí àwọn ìsopọ̀ púpọ̀ ṣe ń dàrú.
Àwọn Àlàyé Datasheet
| Olùṣe | Allegro Microsystems |
|---|---|
| Nọ́mbà apá | ACS712ELCTR-30A-T |
| Logic/IO voltage | 4.5–5.5 V |
| Voltage ìpèsè | 5 V |
| Current ìjàde (fún ikanni kọ̀ọ̀kan) | 30 A |
| Ìtọ́sọ́nà ìgbohùnsáfẹ́fẹ́ PWM | N/A |
| Àwọn ìpele ìfisílẹ̀ logic | 0.5 V (ìjàde ìsinmi) |
| Ìdínkù voltage / RDS(on) / ìkún | 1.2 mΩ |
| Àwọn ààlà ooru | 150 °C títóbi jù |
| Àpótí | TO-220 |
- Rí i dájú pé o tú ooru dáradára fún àwọn current tí ó ju 20A lọ.
- Lo ìwọ̀n okun tí ó yẹ (12 AWG fún 30A) láti yẹra fún gbígbóná púpọ̀.
- So VCC pọ̀ mọ́ 5V àti GND pọ̀ mọ́ ilẹ̀ fún iṣẹ́ tí ó tọ́.
- Rí i dájú pé a so pin OUT pọ̀ mọ́ pin input analog lórí Arduino (bíi A0).
- Mọ̀ nípa àwọn ìyàtọ̀ sensitivity fún oríṣiríṣi àwọn awoṣe ACS712.
- Lo àwọn capacitors fún decoupling gẹ́gẹ́ bí a ti sọ nínú datasheet.
Àwọn Ìtọ́sọ́nà Ìsopọ̀ Okun

Láti so ACS712 current sensor pọ̀ mọ́ Arduino àti LCD, bẹ̀rẹ̀ nípa sísopọ̀ pin VCC ti ACS712 pọ̀ mọ́ pin 5V lórí Arduino. Nígbà tí ó tẹ̀lé, so pin GND ti ACS712 pọ̀ mọ́ pin ilẹ̀ kan lórí Arduino. Pin OUT ti ACS712 yẹ kí a so pọ̀ mọ́ pin analog A0 lórí Arduino, níbi tí a óò ti kà àmì voltage náà.
Fún LCD1602 tàbí LCD2004, so pin VCC pọ̀ mọ́ pin 5V àti pin GND pọ̀ mọ́ ilẹ̀. Pin SDA ti LCD yẹ kí a so pọ̀ mọ́ pin SDA lórí Arduino (nígbà gbogbo A4 lórí UNO), àti pin SCL yẹ kí a so pọ̀ mọ́ pin SCL lórí Arduino (nígbà gbogbo A5 lórí UNO). Rí i dájú pé gbogbo àwọn ìsopọ̀ ṣe dáradára láti rí i dájú pé iṣẹ́ tòótọ́.
Àwọn Àpẹẹrẹ Kóòdù & Ìṣàlàyé
Nínú kóòdù náà, a ṣàlàyé pin input analog fún kíkà ìjàde sensor pẹ̀lú #define VIN A0. Èyí jẹ́ kí a lè tọ́ka sí pin níbi tí a ti so sensor náà rọrùn ní gbogbo ètò náà.
#define VIN A0 // ṣàlàyé pin A0 ti Arduino gẹ́gẹ́ bí input voltage (V in)
const float VCC = 5.0; // voltage ìpèsè wà láti 4.5 sí 5.5V. Nígbà gbogbo 5V.
Nígbà tí ó tẹ̀lé, a ṣeto sensitivity dá lórí awoṣe ACS712 tí a ń lò. Àwọn iye sensitivity ni a fipamọ́ nínú array, tí ó jẹ́ kí ó rọrùn láti wọlé sí wọn dá lórí ìyàn awoṣe.

const int model = 2; // fi nọ́mbà awoṣe sí (0, 1, tàbí 2 fún 5A, 20A, tàbí 30A)
float sensitivity[] = {0.185, 0.100, 0.066}; // àwọn iye sensitivity fún awoṣe kọ̀ọ̀kan
Nínú iṣẹ́ setup(), a bẹ̀rẹ̀ serial monitor àti LCD display. Èyí jẹ́ kí a lè wo àwọn ìwọ̀n current lórí LCD àti nípasẹ̀ serial monitor fún ṣíṣàtúnṣe àṣìṣe.
void setup() {
Serial.begin(9600); // bẹ̀rẹ̀ serial monitor
lcd.begin(); // bẹ̀rẹ̀ LCD
lcd.backlight(); // tan iná ẹ̀yìn
lcd.print("Robojax ACS712"); // fi ọ̀rọ̀ ìbẹ̀rẹ̀ hàn
delay(2000); // dúró fún ìṣẹ́jú àáyá 2
}
Iṣẹ́ loop() ka voltage láti sensor, ṣe ìṣirò current dá lórí sensitivity, àti fi àwọn àbájáde hàn ní ìbámu. Bí current bá ju ààlà ìdánilẹ́kọ̀ọ́ kan lọ, ó fi iye náà hàn; bí bẹ́ẹ̀ kọ́, ó tọ́ka sí pé kò sí current tí a rí.
Ìfihàn / Ohun Tí O Lè Retí
Nígbà tí a bá tan iná sí ètò náà, LCD yẹ kí ó fi "Robojax ACS712" hàn, tí ó tẹ̀lé "Current: " pẹ̀lú iye current tí a wọn ní amperes. Bí current bá kéré ju ààlà ìdánilẹ́kọ̀ọ́ lọ, ìfihàn náà yóò fi "No Current" hàn. Ṣọ́ra nígbà tí o bá ń dánwò pẹ̀lú àwọn current gíga, nítorí sensor lè gbóná (nínú fídíò ní 12:00).
Láti dánwò ètò náà, mú current pọ̀ sí i díẹ̀díẹ̀ nípasẹ̀ ACS712 kí o sì ṣàkíyèsí àwọn ìyípadà lórí LCD àti serial monitor. Rí i dájú pé current kò ju àwọn ààlà tí a fún sensor lọ láti yẹra fún ìbàjẹ́.
Aworan
/*
*
* 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);
}
Ohun ti o le nilo
-
AmazonBuy LCD1602-I2C from Amazonamzn.to
-
Amazon
-
eBayPurchase LCD1602-I2C from eBayebay.us
-
AliExpressPurchase 10pcs LCD1602-I2C from AliExpresss.click.aliexpress.com
Orisun & itọkasi
-
Ita gbangba
Fáìlìs📁
Awọn ile-ikawe Arduino (zip)
-
LCD1602 LCD Arduino library from Robojax
robojax-LCD1602-I2C-library-master.zip0.01 MB
Fọọmu data (pdf)
-
Allegro ACS712 AC/DC 4A, 20A, 30A Current Sensor Datasheet
robojax-allegro_ACS712_current_sensor.pdf0.65 MB
Fayile Fritzing
-
LCD LCD1602-I2C module with 4 wires
LCD1602-I2C.fzpz0.01 MB -
Allegre ACS712 Current Sensor
Allegreo ACS712 Current Sensor.fzpz0.03 MB