Good day guys i hope someone can help me because i want to measure ac current using ads1115 but the problem is when i connect to ads its always 0.00 but on nodemcu its accurate..
i want to done my thesis i hope i can gradute this year
my thesis is making smart meter using
esp8266, adc1115 and the sensor is ac voltage(ZMPT101B) and ac current (acs712) please help me even only this to connect ac current to ads1115 because the output is always zero
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads1115;
int mVperAmp = 66; // use 185 for 5A, 100 for 20A Module and 66 for 30A Module
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
void setup(){
ads1115.begin();
pinMode(A0, INPUT);
Serial.begin(9600);
delay(10);
Serial.println(F("Init...."));
}
void loop(){
Voltage = getVPP();
VRMS = (Voltage/2.0) *0.707; // sq root
AmpsRMS = (VRMS * 1000)/mVperAmp;
float Wattage = (220*AmpsRMS)-20; //Observed 18-20 Watt when no load was connected, so substracting offset value to get real consumption.
Serial.print(AmpsRMS);
Serial.println(" Amps RMS ");
Serial.print(Wattage);
Serial.println(" Watt ");
Serial.println("");
}
float getVPP()
{
float result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here
uint32_t start_time = millis();
while((millis()-start_time) < 1000) //sample for 1 Sec
{
readValue = ads1115.analogRead(A0);
// see if you have a new maxValue
if (readValue > maxValue)
{
/*record the maximum sensor value*/
maxValue = readValue;
}
if (readValue < minValue)
{
/*record the maximum sensor value*/
minValue = readValue;
}
}
// Subtract min from max
result = ((maxValue - minValue) * 5)/1024.0;
return result;
}
#include <Wire.h>
#include <Adafruit_ADS1015.h>
int mVperAmp = 66; // use 185 for 5A, 100 for 20A Module and 66 for 30A Module
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
Adafruit_ADS1115 ads;(0x49)
void setup(void)
{
Serial.begin(9600);
ads.begin();
delay(10);
Serial.println(F("Init...."));
}
void loop(void)
{
int16_t adc0;
Voltage = getVPP();
VRMS = (Voltage/2.0) *0.707; // sq root
AmpsRMS = (VRMS * 1000)/mVperAmp;
float Wattage = (220*AmpsRMS)-20; //Observed 18-20 Watt when no load was connected, so substracting offset value to get real consumption.
Serial.print(AmpsRMS);
Serial.println(" Amps RMS ");
Serial.print(Wattage);
Serial.println(" Watt ");
Serial.println("");
}
float getVPP()
{
float result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here
uint32_t start_time = millis();
while((millis()-start_time) < 1000) //sample for 1 Sec
{
adc0 = ads.readADC_SingleEnded(0);
// see if you have a new maxValue
if (adc0 > maxValue)
{
/*record the maximum sensor value*/
maxValue = adc0;
}
if (adc0 < minValue)
{
/*record the maximum sensor value*/
minValue = adc0;
}
}
// Subtract min from max
result = ((maxValue - minValue) * 5)/1024.0;
return result;
}
Please do not post error messages using photos or screen captures. Copy the full error message from the error window and paste it into your post between code tags. There is a small button at the top-right of the error window to copy all the text.
The error is because this line
int16_t adc0;
is in a different function to the one that uses it.
Already compile but the problem is the reading is not accurate but when i dont use ads1115
and only use nodemcu the reading is accurate i hope you can help me
I hope I can help you too. But in order to do that you must post the code you are using, your schematic, links to the parts you are using, maybe some clear, bright photos showing all connections clearly. I am not there with you and cannot see what you have done.
What, exactly, is that line supposed to accomplish? Where do the "5" and "1024.0" come from? Is this supposed to be some kind of conversion from ADC "counts" to voltage? If so, it is not even close to right.
The ADS1115 is a 16-bit DAC, which means the output ranges from 0 to 65535. The input range, assuming a gain setting of 1.0, is 0V to 4.096V. maxValue and minValue are both ints, which, assuming you're using an AVR processor, are 16-bits signed ints, with a range of -32768 to +32767. So, not only will ANY A/D reading over 32767 be converted to a negative number when the value is assigned to adco, which is a signed int, the subtraction will not yield the result you expect, and when you multiply the result of the subtraction by 5, it WILL overflow.
Basically, the entire getVPP function is doing nonsense. So what is it SUPPOSED to be doing?
Also, if you are reading an AC signal, how are you ensuring you do not go outside the allowable analog input voltage range of the ADS1115, which is from GND-0.3V to VCC+0.3V. A symmetrical AC input signal WILL damage the ADS1115 if it is not level-shifted into input range of the ADS1115.
thank you @RayLivingston i really appreciated it sorry i still newbie on this i hope yun can give me some advice how to get ac current i search it online and
i see it was little accurate to the amps
If your current sense input is a zero-centered AC signal, you will need to add an op-amp to level-shift and scale it into the allowable range on the ADS1115. This means shifting it up by 2.048V, and scaling it so it never goes below 0V, or above 5.0V.
Next, you need to properly scale the readings from the ADS1115. Setup as above, it will give a reading of 32768 for an input of 0V, 65535 for an input of +2.048V, and 0 for an input of -2.048V. So you need to scale and shift the readings
uint32_t readValue = ads1115.analogRead(A0);
float current = (readValue * 4.096) / 65535; // Convert ADC count to volts
current -= 2.024; // Shift down by 1/2 full-scale to zero-center
current *= currentScale; // Scale volts to amps
And this is assuming you are setting the ADS1115 gain to 1. It all changes with different gains. Without knowing WHAT you are measuring or how, that is all the explanation I can give. I have no idea what the value of currentScale is for whatever hardware you're using to measure current.