Created
July 19, 2018 07:08
-
-
Save elktros/95b674d7247b29e23fccac87772ca65c to your computer and use it in GitHub Desktop.
Code for interfacing ACS712 Current Sensor with Arduino.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); | |
const int currentPin = A0; | |
int sensitivity = 66; | |
int adcValue= 0; | |
int offsetVoltage = 2500; | |
double adcVoltage = 0; | |
double currentValue = 0; | |
void setup() | |
{ | |
Serial.begin(9600); | |
lcd.begin(16, 2); | |
lcd.print(" Current Sensor "); | |
lcd.setCursor(0,1); | |
lcd.print(" with Arduino "); | |
delay(2000); | |
} | |
void loop() | |
{ | |
adcValue = analogRead(currentPin); | |
adcVoltage = (adcValue / 1024.0) * 5000; | |
currentValue = ((adcVoltage - offsetVoltage) / sensitivity); | |
Serial.print("Raw Sensor Value = " ); | |
Serial.print(adcValue); | |
lcd.clear(); | |
delay(1000); | |
//lcd.display(); | |
lcd.setCursor(0,0); | |
lcd.print("ADC Value = "); | |
lcd.setCursor(12,0); | |
lcd.print(adcValue); | |
delay(2000); | |
Serial.print("\t Voltage(mV) = "); | |
Serial.print(adcVoltage,3); | |
lcd.setCursor(0,0); | |
lcd.print("V in mV = "); | |
lcd.setCursor(10,0); | |
lcd.print(adcVoltage,1); | |
delay(2000); | |
Serial.print("\t Current = "); | |
Serial.println(currentValue,3); | |
lcd.setCursor(0,0); | |
lcd.print("Current = "); | |
lcd.setCursor(10,0); | |
lcd.print(currentValue,2); | |
lcd.setCursor(14,0); | |
lcd.print("A"); | |
delay(2500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using the above code and I used 20a module and have changed the sensitivity value to 100 but still the current value is displaying negative if I connect it to a load still it's displaying negative current