/*
*
* Arduino Sketch for Allegro ACS758 Current Sensor (Advanced)
* this sensor can measure current at range of up to 200A
* It operates with 3.3 or 5V
* Please watch video instruction and explanation for this code.
*
* Written by Ahmad Shamshiri on Saturday May 27,2018 at 13:19 at Ajax, Ontario, Canada
* for Robojax.com
* View the video instruction at
* This code has been downloaded from Robojax.com
*/
#define VIN1 A0
#define VIN2 A1
#define VIN3 A2
#define VIN4 A3// define the Arduino pin A0 as voltage input (V in)
const float VCC = 5;// supply voltage 5V or 3.3V. If using PCB, set to 5V only.
const int model = 7; // 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 sensitivy 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 factor for VCC that appears at output
* when the current is zero.
* for Bidirectional sensor it is 0.5 x VCC
* for Unidirectional sensor 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 voltage1;
float voltage2;
float voltage3;
float voltage4;// internal variable for voltage
float cutOff = FACTOR/cutOffLimit;// convert current cut off to mV
void setup() {
//Robojax.com ACS758 Current Sensor
Serial.begin(9600);// initialize serial monitor
Serial.println("MAGIC MYNA PVT LTD");
Serial.println("ACS758 Current Sensor CALIBRATION PROCESS");
}
void loop() {
//Robojax.com ACS758 Current Sensor
float voltage_raw1 = (VCC / 1023.0)* analogRead(VIN1);// Read the voltage from sensor
voltage1 = voltage_raw1 - (QOV )+ 0.007 ;// 0.007 is a value to make voltage zero when there is no current
float current1 = voltage1 / FACTOR;
float voltage_raw2 = (VCC / 1023.0)* analogRead(VIN2);// Read the voltage from sensor
voltage2 = voltage_raw2 - QOV + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
float current2 = voltage2 / FACTOR;
float voltage_raw3 = (VCC / 1023.0)* analogRead(VIN3);// Read the voltage from sensor
voltage3 = voltage_raw3 - QOV + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
float current3 = voltage3 / FACTOR;
float voltage_raw4 = (VCC / 1023.0)* analogRead(VIN4);// Read the voltage from sensor
voltage4 = voltage_raw4 - QOV + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
float current4 = voltage4 / FACTOR;
if(abs(voltage1 && voltage2 && voltage3 && voltage4) > cutOff )
{
Serial.print(" analog value of A0:");
Serial.print(analogRead(VIN1));
Serial.print(" voltage at A0 pin=");
Serial.print(voltage_raw1,3);
Serial.print(" V: ");
Serial.print(voltage1,3);// print voltage with 3 decimal places
Serial.print("V, I: ");
Serial.print(current1,3); // print the current with 2 decimal places
Serial.println("A");
/*Serial.print("value A1:");
Serial.print(analogRead(VIN2));
Serial.print(" A1 pin=");
Serial.print(voltage_raw2);
Serial.print(" V: ");
Serial.print(voltage2,7);// print voltage with 3 decimal places
Serial.print("V, I: ");
Serial.print(current2,7); // print the current with 2 decimal places
Serial.println("A");
/*Serial.println();
Serial.print("Current value A2:");
Serial.print(analogRead(VIN3),2);
Serial.print(" A2 pin=");
Serial.print(voltage_raw3,3);
Serial.print(" V: ");
Serial.print(voltage3,7);// print voltage with 3 decimal places
Serial.print("V, I: ");
Serial.print(current3,7); // print the current with 2 decimal places
Serial.println("A");
//Serial.println();
//Serial.println();
/*Serial.print("sensors Analog value A0 = ");
Serial.print(analogRead(VIN1), 2);
Serial.print(" A1 = ");
Serial.print(analogRead(VIN2),2);
Serial.print(" A2 = ");
Serial.println(analogRead(VIN3),2);
//Serial.println();
/*Serial.print("Raw volt value of pins A0 = ");
Serial.print(voltage_raw1,7);
Serial.print(" A1 = ");
Serial.print(voltage_raw2,7);
Serial.print(" A2 = ");
Serial.println(voltage_raw3,7);
Serial.print("voltage value of pins A0 = ");
Serial.print(voltage1,7);
Serial.print(" A1 = ");
Serial.print(voltage2,7);
Serial.print(" A2 = ");
Serial.println(voltage3,7);
Serial.print("Current value of pins A0 = ");
Serial.print(current1,7);
//Serial.print(" A");
Serial.print(" A1 = ");
Serial.print(current2,7); // print the current with 2 decimal places
//Serial.print(" A");
Serial.print(" A2 = ");
Serial.print(current3,7); // print the current with 2 decimal places
//Serial.println("A");
Serial.println();
Serial.println();
/*Serial.print("voltage value A3:");
Serial.print(analogRead(VIN4),2);
Serial.print(" A3 pin=");
Serial.print(voltage_raw4,7);
Serial.print(" V: ");
Serial.print(voltage4,7);// print voltage with 3 decimal places
Serial.print("V, I: ");
Serial.print(current4,7); // print the current with 2 decimal places
Serial.println("A");
Serial.println();*/
}else{
Serial.println("No Current");
}
delay(3000);
}