ACS712 Current Sensor with arduino Code
The ACS712 provides economical and precise solutions for AC or DC current sensing in industrial, commercial, and communications systems.
The device package allows for easy implementation by the customer.
Typical applications include motor control, load detection and management, switched-mode power supplies, and over current fault protection.
Current Sensor ACS712 Pinout and its Specifications
The ACS712 Module uses the famous ACS712 IC to measure current using the Hall Effect principle.
The module gets its name from the IC (ACS712) used in the module, so for you final products use the IC directly instead of the module.
ACS712 Current Sensor Circuit Diagram
The ACS712 module has two phoenix terminal connectors (green colour ones) with mounting screws as shown above. These are the terminals through which the wire has to be passed.
In our case I am measuring the current drawn by the motor so the wires that is going to the load (motor) is passed through the ACS 712 Module.
Current Sensor ACS712 Pinout and its Specifications
Make sure the module is connected in series with the load and be extra cautious to avoid shorts.
On the other side we have three pins. The Vcc is connected to +5V to power the module and the ground is connected to the ground of the MCU (system).
Then the analog voltage given out by the ACS712 module is read using any analog pin on the Microcontroller.
ALL SENSOR DETAILS:
1. HC-05 – Bluetooth
2. Mpu 6050 accelerometer-gyroscope- -module
3. Flame-sensor
4. Rotary-encoder
5. Force-sensor-fsr400
6. Current-sensor-acs712
7. Flex-sensor
8. IR-sensor-tcrt5000
9. Pulse-sensor-pin
10. Color-sensor-tcs230
11. SD-card-module
12. Oled-with-arduino
13. Addressable-rgb-led-strip-ws1812
14. Relay-module
15. TFT-1-8-display-st7735r
16. 8×8-dot-matrix-display-max7219
17. Smoke-sensor-mq-2
18. Ultrasonic-sensor-HC-sr04
19. PIR-motion-sensor-hc-sr501
20. Tilt-sensor-sw-520d
21. Microphone-sound-sensor
22. Reed-switch-reed-sensor
23. Rfid-reader-Em18
24. Rfid-tag
25. RTC-real-time-clock-ds1307
26. Temperature-sensor-ds18b20
27. Moisture-sensor
28. Rain-sensor
29. Pressure-sensor
30. Accelerometer
31. MOC-3021-circuit
32. DHT11-DHT22-temperature-and-humidity-sensor
SPECIFICATIONS:
1. Measures both AC and DC current.
2. Available as 5A, 20A and 30A module.
3. Provides isolation from the load.
4. Easy to integrate with MCU, since it outputs analog voltage.
5. Scale Factor.
FEATURES AND BENEFITS:
1. Low-noise analog signal path.
2. Device bandwidth is set via the new FILTER pin.
3. 5 μs output rise time in response to step input current.
4. 80 kHz bandwidth.
5. Total output error 1.5% at TA = 25°C.
6. Small footprint, low-profile SOIC8 package
7. 1.2 mΩ internal conductor resistance.
8. 2.1 kVRMS minimum isolation voltage from pins 1-4 to pins 5-8.
9. 5.0 V, single supply operation.
10. 66 to 185 mV/A output sensitivity.
11. Output voltage proportional to AC or DC currents.
12. Factory-trimmed for accuracy.
13. Extremely stable output offset voltage.
14. Nearly zero magnetic hysteresis.
15. Ratio metric output from supply voltage.
CURRENT SENSOR WITH ARDUINO CIRCUIT:
CURRENT SENSOR WITH ARDUINO SKETCH:
Copy and paste the below given code and download bottom given link:
//Circuito.io is an automatic generator of schematics and code
//Copyright (C) 2016 Roboplan Technologies Ltd.
// Include Libraries
#include “Arduino.h”
#include “ACS712.h”
#include “Buzzer.h”
#include “LiquidCrystal.h”
#include “Relay.h”
// Pin Definitions
#define ACS712_PIN_VO A3
#define BUZZER_PIN_SIG 2
#define LCD_PIN_RS 8
#define LCD_PIN_E 7
#define LCD_PIN_DB4 3
#define LCD_PIN_DB5 4
#define LCD_PIN_DB6 5
#define LCD_PIN_DB7 6
#define RELAYMODULE_PIN_SIGNAL 9
// Global variables and defines
const int acs712calFactor = 513;
// object initialization
ACS712 acs712(ACS712_PIN_VO);
Buzzer buzzer(BUZZER_PIN_SIG);
LiquidCrystal lcd(LCD_PIN_RS,LCD_PIN_E,LCD_PIN_DB4,LCD_PIN_DB5,LCD_PIN_DB6,LCD_PIN_DB7);
Relay relayModule(RELAYMODULE_PIN_SIGNAL);
// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;
void setup()
{
// Setup Serial which is useful for debugging
// Use the Serial Monitor to view printed messages
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for native USB
Serial.println(“start”);
//Manually calibarte the ACS712 current sensor.
//Connet the ACS to your board, but do not connect the current sensing side.
//Follow serial monitor instructions. This needs be done one time only.
acs712.calibrate(acs712calFactor);
// set up the LCD’s number of columns and rows
lcd.begin(16, 2);
menuOption = menu();
}
void loop()
{
if(menuOption == ‘1’) {
// Current Sensor Module ACS712 – Test Code
//Get averaged current measurment.
float acs712Currrent = acs712.getCurrent();
Serial.print(acs712Currrent); Serial.println(F(” [mA]”));
}
else if(menuOption == ‘2’) {
// Piezo Buzzer – Test Code
// The buzzer will turn on and off for 500ms (0.5 sec)
buzzer.on(); // 1. turns on
delay(500); // 2. waits 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer or shorter delay in milliseconds.
buzzer.off(); // 3. turns off.
delay(500); // 4. waits 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer or shorter delay in milliseconds.
}
else if(menuOption == ‘3’)
{
// LCD 16×2 – Test Code
// Print a message to the LCD.
lcd.setCursor(0, 0);
lcd.print(“Circuito Rocks !”);
// Turn off the display:
lcd.noDisplay();
delay(500);
// Turn on the display:
lcd.display();
delay(500);
}
else if(menuOption == ‘4’) {
// Relay Module – Test Code
// The relay will turn on and off for 500ms (0.5 sec)
relayModule.on(); // 1. turns on
delay(500); // 2. waits 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer or shorter delay in milliseconds.
relayModule.off(); // 3. turns off.
delay(500); // 4. waits 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer or shorter delay in milliseconds.
}
if (millis() – time0 > timeout)
{
menuOption = menu();
}
}
char menu()
{
Serial.println(F(“\nWhich component would you like to test?”));
Serial.println(F(“(1) Current Sensor Module ACS712”));
Serial.println(F(“(2) Piezo Buzzer”));
Serial.println(F(“(3) LCD 16×2”));
Serial.println(F(“(4) Relay Module”));
Serial.println(F(“(menu) send anything else or press on board reset button\n”));
while (!Serial.available());
// Read data from serial monitor if received
while (Serial.available())
{
char c = Serial.read();
if (isAlphaNumeric(c))
{
if(c == ‘1’)
Serial.println(F(“Now Testing Current Sensor Module ACS712”));
else if(c == ‘2’)
Serial.println(F(“Now Testing Piezo Buzzer”));
else if(c == ‘3’)
Serial.println(F(“Now Testing LCD 16×2”));
else if(c == ‘4’)
Serial.println(F(“Now Testing Relay Module”));
else
{
Serial.println(F(“illegal input!”));
return 0;
}
time0 = millis();
return c;
}
}
}
Download full Arduino sketch here.CURRENT SENSOR WITH LCD