Home » Blog » Sensor Arus ACS712 5A, 20A, 30A – Serial Arus dan Tegangan

Sensor Arus ACS712 5A, 20A, 30A – Serial Arus dan Tegangan

Link Data Sheet ACD712 dari Allegro

Github Library ACS712 milik Rob Tilaard

GitHub – RobTillaart/ACS712: Arduino library for ACS Current Sensor – 5A, 20A, 30A

Skema Arus DC

Skema Arus AC

Kode Program Arus DC

// Protus Tanuhandaru
// www.progresstech.co.id

int pinOut = A0; // Deklarasi pin output ACS712
int analogOutput = 0; // Output pin analog

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Pembacaan pin analog
  analogOutput = analogRead(pinOut); 

  // ADC Arduino Uno
  float tegangan = analogOutput * 5 / 1023.0; 

  // Nilai 0 ACS712 dimulai dari VCC*0.5 
  // dan nilai step ACS712 5A adalah 185mV
  float arus = (tegangan - 2.5) / 0.185; 

  Serial.print("Arus : ");
  Serial.println(arus);
  delay(500);
}

Kode Program Arus AC

//
//    FILE: ACS712_20_AC_low_pass.ino
//  AUTHOR: Rob Tillaart
// PURPOSE: demo AC measurement with point to point with low pass filter
//     URL: https://github.com/RobTillaart/ACS712


#include "ACS712.h"


//  Arduino UNO has 5.0 volt with a max ADC value of 1023 steps
//  ACS712 5A  uses 185 mV per A
//  ACS712 20A uses 100 mV per A
//  ACS712 30A uses  66 mV per A


ACS712  ACS(A0, 5.0, 1023, 185);
//  ESP 32 example (might requires resistors to step down the logic voltage)
//  ACS712  ACS(25, 3.3, 4095, 185);

float value  = 0;
float weight = 0.2;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println(__FILE__);
  Serial.print("ACS712_LIB_VERSION: ");
  Serial.println(ACS712_LIB_VERSION);

  ACS.autoMidPoint();

  Serial.print("MidPoint: ");
  Serial.println(ACS.getMidPoint());
  Serial.print("Noise mV: ");
  Serial.println(ACS.getNoisemV());
  Serial.print("Amp/Step: ");
  Serial.println(ACS.getAmperePerStep(), 4);

  value = ACS.mA_AC();  // get good initial value
}


void loop()
{
  //  select sppropriate function
  float mA = ACS.mA_AC_sampling();
  // float mA = ACS.mA_AC();
  value += weight * (mA - value);  // low pass filtering

  Serial.print("weight: ");
  Serial.print(weight);
  Serial.print(" value: ");
  Serial.print(value, 0);
  Serial.print(" mA: ");
  Serial.print(mA);
  Serial.println();

  delay(1000);
}


// -- END OF FILE --

Kode Program Arus AC dengan LCD I2C

//
//    FILE: ACS712_20_AC_low_pass.ino
//  AUTHOR: Rob Tillaart
// PURPOSE: demo AC measurement with point to point with low pass filter
//     URL: https://github.com/RobTillaart/ACS712


#include "ACS712.h"
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // Set Alamat I2C khusus untuk 0x27 dan Ukuran LCD
//  Arduino UNO has 5.0 volt with a max ADC value of 1023 steps
//  ACS712 5A  uses 185 mV per A
//  ACS712 20A uses 100 mV per A
//  ACS712 30A uses  66 mV per A


ACS712  ACS(A0, 5.0, 1023, 185);
//  ESP 32 example (might requires resistors to step down the logic voltage)
//  ACS712  ACS(25, 3.3, 4095, 185);

float value  = 0;
float weight = 0.2;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println(__FILE__);
  Serial.print("ACS712_LIB_VERSION: ");
  Serial.println(ACS712_LIB_VERSION);

  ACS.autoMidPoint();

  Serial.print("MidPoint: ");
  Serial.println(ACS.getMidPoint());
  Serial.print("Noise mV: ");
  Serial.println(ACS.getNoisemV());
  Serial.print("Amp/Step: ");
  Serial.println(ACS.getAmperePerStep(), 4);

  value = ACS.mA_AC();  // get good initial value

  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Berikan Like");
  lcd.setCursor(0, 1);
  lcd.print("Ayo subscribe");

  delay(1000);
}


void loop()
{
  //  select sppropriate function
  float mA = ACS.mA_AC_sampling();
  // float mA = ACS.mA_AC();
  value += weight * (mA - value);  // low pass filtering

  Serial.print("weight: ");
  Serial.print(weight);
  Serial.print(" value: ");
  Serial.print(value, 0);
  Serial.print(" mA: ");
  Serial.print(mA);
  Serial.println();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Arus ");
  lcd.setCursor(0, 1);
  lcd.print(mA);
  lcd.print(" mA");
  delay(1000);
}


// -- END OF FILE --

Leave a Reply

Your email address will not be published. Required fields are marked *