I'm using ESP8266 interfaced with ACS712 current sensor to measure current and voltage.
However it displays some values without any load being applied, and after applying the load, the changes are not that much (about 0.06).
Below is the code:
//Measuring Current Using ACS712
//#include <Filters.h> //This library does a huge work check its .cpp file
#include <Adafruit_GFX.h> //OLED libraries
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int sensorIn = A0;
int sensitivity = 66; // 66 for 30A Module
int adcvalue= 0;
int offsetvoltage = 2500;
double Voltage = 0; //voltage measuring
double current = 0;// Current measuring
void setup() {
Serial.begin(9600);//baud rate at which arduino communicates with Laptop/PC
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start the OLED display
display.clearDisplay();
display.display();
}
void loop()
{
adcvalue = analogRead(sensorIn);//reading the value from the analog pin
Voltage = (adcvalue / 1024.0) * 5000; // Gets you mV
current = ((Voltage - offsetvoltage) / sensitivity);
Serial.print(adcvalue); //prints the results on the serial monitor
delay(2500);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0, 20);
display.println("Voltage");
display.setCursor(50, 20);
display.println(Voltage);
//display.setCursor(75, 20);
display.setCursor(85, 20);
display.println("V");
display.setCursor(0, 30);
display.println("Current");
display.setCursor(50, 30);
display.println(current);
display.setCursor(75, 30);
display.println("mA");
display.display();
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t current = "); // shows the voltage measured
Serial.println(current,3);
}