I bought this sensor after seeing it used in a commercial marine power monitor, YHDC has a model called HSTS016L has models able to measure current values ranges from 10A up to 200A I have the 10amp model. The output voltage of this sensor is 2.5V +/- 0.625V
https://pdf1.alldatasheet.com/datasheet ... L-10A.html
The sensor has 4 output pins: RED (5V input), BLACK (0V Gnd), YELLOW (Analog Output), and WHITE (Analog for Calibration).
and used this doc to test it on a UNO board https://solarduino.com/how-to-measure-d ... ansformer/ which seemed to work pretty good. Then I saw this sensor from adafruit ADS1115 with more accuracy and a I2C interface which I think will be a better fit with a ESP32.
Right now I am using an UNO with the ADS1115 and the following code but I am getting odd readings from A0 and A1 on the ADS1115, attached is the code and a pic of the wiring. I am in way over my head on this one :( any help would be greatly appreciated. The output values never change, regardless if I have a load on the sensor (I am testing with 2 different LED bulbs, one draws around .12 amp, the other around 1 amp.
this is the serial output:
setup
Getting single-ended readings from AIN0..3
ADC Range: +/- 6.144V (1 bit = 3mV)
Scanning I2C devices...
I2C device found at address 0x48
I2C devices found: 1
AIN0: 2047
AIN1: 2047
- Code: Select all | TOGGLE FULL SIZE
// https://www.adafruit.com/product/1085 ADS1115 16-Bit ADC - 4 Channel with Programmable Gain Amplifier Product ID: 1085
// 0x48 (1001000) ADR -> GND
// How to measure DC and AC current using HSTS016L Hall Effect Current Transformer 10amp model
// The sensor has 4 output pins:
// RED (5V input),
// BLACK (0V Gnd),
// YELLOW (Analog Output), pin A1
// WHITE (Analog for Calibration) pin A2
#include <Wire.h>
#include <Adafruit_ADS1X15.h> // ver 2.3.0 installed on 12/11/21
Adafruit_ADS1015 ads1015;
int decimalPrecision = 2; // decimal places for all values shown in LED Display & Serial Monitor
/* 1- AC Current Measurement */
//int currentAnalogInputPin = A1; // Which pin to measure Current Value (A0 is reserved for LCD Display Shield Button function)
//int calibrationPin = A2; // Which pin to calibrate offset middle value
float manualOffset = 0.0; //0.00; // Key in value to manually offset the initial value
// If using "Hall-Effect" Current Transformer, key in value using this formula: mVperAmp = maximum voltage range (in milli volt) / current rating of CT
// For example, a 10A Hall-Effect Current Transformer rated at 10A, 2.5V +/- 0.625V, mVperAmp will be 625 mV / 10A = 62.5mV/A
// For example, a 20A Hall-Effect Current Transformer rated at 20A, 2.5V +/- 0.625V, mVperAmp will be 625 mV / 20A = 31.25mV/A
// For example, a 50A Hall-Effect Current Transformer rated at 50A, 2.5V +/- 0.625V, mVperAmp will be 625 mV / 50A = 12.5 mV/A
float mVperAmpValue = 62.5; // 10amp sensor
float supplyVoltage = 5000; // Analog input pin maximum supply voltage, Arduino Uno or Mega is 5000mV while Arduino Nano or Node MCU is 3300mV
float offsetSampleRead = 0; /* to read the value of a sample for offset purpose later */
float currentSampleRead = 0; /* to read the value of a sample including currentOffset1 value*/
float currentLastSample = 0; /* to count time for each sample. Technically 1 milli second 1 sample is taken */
float currentSampleSum = 0; /* accumulation of sample readings */
float currentSampleCount = 0; /* to count number of sample. */
float currentMean ; /* to calculate the average value from all samples, in analog values*/
float RMSCurrentMean ; /* square roof of currentMean, in analog values */
float FinalRMSCurrent ; /* the final RMS current reading*/
void setup(void)
{
Serial.begin(115200);
Serial.println("setup");
Serial.println("Getting single-ended readings from AIN0..3");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV)");
ads1015.begin();
// ads1015.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV
ads1015.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV
// ads1015.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV
// ads1015.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV
// ads1015.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV
scanI2C();
}
void loop(void)
{
int16_t adc0, adc1, adc2, adc3;
adc0 = ads1015.readADC_SingleEnded(0);
adc1 = ads1015.readADC_SingleEnded(1);
//adc2 = ads1015.readADC_SingleEnded(2);
// adc3 = ads1015.readADC_SingleEnded(3);
Serial.print("AIN0: "); Serial.println(adc0);
Serial.print("AIN1: "); Serial.println(adc1);
// Serial.print("AIN2: "); Serial.println(adc2);
// Serial.print("AIN3: "); Serial.println(adc3);
// Serial.println(" ");
delay(250);
}
void scanI2C()
{
byte error, address;
int nDevices;
Serial.println("Scanning I2C devices...");
nDevices = 0;
for (address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print(F("I2C device found at address 0x"));
Serial.println(address, HEX);
nDevices++;
delay(250);
}
else if (error == 4)
{
Serial.print("Unknown error at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address, HEX);
}
}
Serial.print("I2C devices found: ");Serial.println(nDevices);
}