### Calculate Corrected mVperAmp for 5A Sensor with Voltage Divider Source: https://github.com/robtillaart/acs712/blob/master/README.md This example demonstrates how to calculate the corrected mVperAmp value for a 5A ACS712 sensor when using a voltage divider. Adjust R1 and R2 values based on your specific hardware setup. ```text | R1 (ACS) | R2 (GND) | voltage factor | mVperAmp corrected | notes | |---------:|----------:|--------------------------------:|:-----------------------:|:--------| | 10200 | 4745 | 4745 / (10200 + 4745) = 0.3175 | 185 * 0.3175 = 31.75 | | 4745 | 10200 | 10200 / (10200 + 4745) = 0.6825 | 185 * 0.6825 = 68.25 | | 10200 | 9800 | 9800 / (10200 + 9800) = 0.4900 | 185 * 0.4900 = 49.00 | | 1000 | 2200 | 2200 / (1000 + 2200) = 0.6875 | 185 * 0.6875 = 127.19 | 5V -> 3V3 ADC | 300 | 75 | 75 / (300 + 75) = 0.2000 | 185 * 0.2000 = 37.00 | 5V -> 1V ADC ``` -------------------------------- ### Calculate Corrected mVperAmp for 30A Sensor with Voltage Divider Source: https://github.com/robtillaart/acs712/blob/master/README.md This example details the calculation of corrected mVperAmp for a 30A ACS712 sensor using a voltage divider. Verify R1 and R2 values for accuracy. ```text | R1 (ACS) | R2 (GND) | voltage factor | mVperAmp corrected | notes | |---------:|----------:|--------------------------------:|:-----------------------:|:--------| | 10200 | 4745 | 4745 / (10200 + 4745) = 0.3175 | 66 * 0.3175 = 31.75 | | 4745 | 10200 | 10200 / (10200 + 4745) = 0.6825 | 66 * 0.6825 = 68.25 | | 10200 | 9800 | 9800 / (10200 + 9800) = 0.4900 | 66 * 0.4900 = 49.00 | | 1000 | 2200 | 2200 / (1000 + 2200) = 0.6875 | 66 * 0.6875 = 45.38 | 5V -> 3V3 ADC | 300 | 75 | 75 / (300 + 75) = 0.2000 | 66 * 0.2000 = 13.20 | 5V -> 1V ADC ``` -------------------------------- ### Calculate Corrected mVperAmp for 20A Sensor with Voltage Divider Source: https://github.com/robtillaart/acs712/blob/master/README.md This example shows how to calculate the corrected mVperAmp for a 20A ACS712 sensor with a voltage divider. Ensure R1 and R2 values match your circuit. ```text | R1 (ACS) | R2 (GND) | voltage factor | mVperAmp corrected | notes | |---------:|----------:|--------------------------------:|:-----------------------:|:--------| | 10200 | 4745 | 4745 / (10200 + 4745) = 0.3175 | 100 * 0.3175 = 31.75 | | 4745 | 10200 | 10200 / (10200 + 4745) = 0.6825 | 100 * 0.6825 = 68.25 | | 10200 | 9800 | 9800 / (10200 + 9800) = 0.4900 | 100 * 0.4900 = 49.00 | | 1000 | 2200 | 2200 / (1000 + 2200) = 0.6875 | 100 * 0.6875 = 68.75 | 5V -> 3V3 ADC | 300 | 75 | 75 / (300 + 75) = 0.2000 | 100 * 0.2000 = 20.00 | 5V -> 1V ADC ``` -------------------------------- ### Get Noise Level in Millivolts Source: https://github.com/robtillaart/acs712/blob/master/README.md Returns the currently set noise level in millivolts. ```cpp uint8_t noise = ACS.getNoisemV(); ``` -------------------------------- ### Get Current Form Factor Source: https://github.com/robtillaart/acs712/blob/master/README.md Returns the currently set form factor used for AC current measurements. ```cpp float ff = ACS.getFormFactor(); ``` -------------------------------- ### Get Minimum ADC Value Source: https://github.com/robtillaart/acs712/blob/master/README.md Retrieves the minimum ADC value over a specified duration in milliseconds. Useful for midpoint calculation. ```cpp uint16_t minVal = ACS.getMinimum(20); ``` -------------------------------- ### Get Midpoint Value Source: https://github.com/robtillaart/acs712/blob/master/README.md Reads the currently set or determined midpoint value for ADC conversion. ```cpp uint16_t midPoint = ACS.getMidPoint(); ``` -------------------------------- ### Get Maximum ADC Value Source: https://github.com/robtillaart/acs712/blob/master/README.md Retrieves the maximum ADC value over a specified duration in milliseconds. Useful for midpoint calculation. ```cpp uint16_t maxVal = ACS.getMaximum(20); ``` -------------------------------- ### Set External ADC Configuration Source: https://github.com/robtillaart/acs712/blob/master/README.md Configure the library to use an external ADC with specified voltage and bit resolution. The default is the internal analogRead. Ensure the parameters match your ADC's specifications. ```cpp // set to external ADC - 5 volts 12 bits ACS.setADC(myAnalogRead, 5.0, 4096); ... uint16_t myAnalogRead(uint8_t pin) { return MCP.read(pin); // assuming MCP is ADC object. } ``` -------------------------------- ### ACS712 Constructor Source: https://github.com/robtillaart/acs712/blob/master/README.md Initializes the ACS712 sensor object. It allows configuration of the analog pin, reference voltage, maximum ADC value, and the sensor's mV per Ampere sensitivity. ```APIDOC ## ACS712(uint8_t analogPin, float volts = 5.0, uint16_t maxADC = 1023, float mVperAmpere = 100) constructor ### Description Initializes the ACS712 sensor object. It allows configuration of the analog pin, reference voltage, maximum ADC value, and the sensor's mV per Ampere sensitivity. The defaults are based upon an Arduino UNO, 10 bits ADC. ### Parameters * **analogPin** (uint8_t) - The analog pin connected to the ACS712 sensor. * **volts** (float) - Optional. The reference voltage used by the internal ADC (defaults to 5.0V). * **maxADC** (uint16_t) - Optional. The maximum output value of the internal ADC (defaults to 1023 for a 10-bit ADC). * **mVperAmpere** (float) - Optional. The sensitivity of the ACS712 sensor in mV per Ampere (defaults to 100, typical for a 20A sensor). ``` -------------------------------- ### Determine Form Factor from Measurements Source: https://github.com/robtillaart/acs712/blob/master/README.md Calculates the form factor using AC current sampling and peak-to-peak measurements. ```cpp float formFactor = 2.0 * mA_AC_sampling() / ACS.mA_peak2peak(); ``` -------------------------------- ### Include ACS712 Library Source: https://github.com/robtillaart/acs712/blob/master/README.md Include the ACS712 library header file to use its functionalities. ```cpp #include ACS712.h ``` -------------------------------- ### ACS712 Constructor Source: https://github.com/robtillaart/acs712/blob/master/README.md Initialize the ACS712 sensor object. Defaults are set for a 20A sensor on an Arduino UNO with a 10-bit ADC. ```cpp ACS712(uint8_t analogPin, float volts = 5.0, uint16_t maxADC = 1023, float mVperAmpere = 100) ``` -------------------------------- ### Optimize mA_AC_sampling for Accuracy Source: https://github.com/robtillaart/acs712/blob/master/README.md To increase accuracy (reduce variation), set the frequency to half the actual frequency (e.g., 25 and 30 Hz). This results in a longer blocking time. ```cpp // Example of setting frequency for higher accuracy // float current = mA_AC_sampling(25, 1); // For 50Hz actual frequency ``` -------------------------------- ### Optimize mA_AC_sampling for Speed Source: https://github.com/robtillaart/acs712/blob/master/README.md A performance trick to sample faster by setting the frequency to double the actual frequency (e.g., 100 or 120 Hz). This reduces blocking time to ~10 ms but may increase variation. ```cpp // Example of setting frequency for faster sampling // float current = mA_AC_sampling(100, 1); // For 50Hz actual frequency ``` -------------------------------- ### Reset to Internal ADC Configuration Source: https://github.com/robtillaart/acs712/blob/master/README.md Reset the library to use the default internal ADC (analogRead). Ensure the parameters for voltage and bit resolution are set correctly for the internal ADC. ```cpp // reset to internal ADC - 5 volts 10 bits ACS.setADC(NULL, 5.0, 1023); ``` -------------------------------- ### Set Noise Level in Millivolts Source: https://github.com/robtillaart/acs712/blob/master/README.md Sets the noise level in millivolts, used for determining the zero level in AC measurements. ```cpp ACS.setNoisemV(15); ``` -------------------------------- ### Determine Noise Level in Millivolts Source: https://github.com/robtillaart/acs712/blob/master/README.md Determines the millivolt noise level based on frequency and cycles. Measurement should be taken with no or constant DC current. ```cpp float noiseLevel = ACS.mVNoiseLevel(50, 10); ``` -------------------------------- ### Measure AC Current (using Form Factor) Source: https://github.com/robtillaart/acs712/blob/master/README.md Calculates the AC current in mA by multiplying the peak-to-peak value by the known Form Factor. Blocks for approximately 21 ms for a 50/60 Hz period. Supports floating point frequencies and averaging over multiple cycles. ```cpp float mA_AC(float frequency = 50, uint16_t cycles = 1) ``` -------------------------------- ### Manually Increase Midpoint Source: https://github.com/robtillaart/acs712/blob/master/README.md Manually increases the midpoint value. The function will not increase if the midpoint equals maxADC. ```cpp ACS.incMidPoint(); ``` -------------------------------- ### Enable/Disable Experimental Noise Suppression Source: https://github.com/robtillaart/acs712/blob/master/README.md Enables or disables experimental noise suppression. This feature averages two samples. ```cpp ACS.suppressNoise(true); ``` -------------------------------- ### Reset Midpoint to Initial Value Source: https://github.com/robtillaart/acs712/blob/master/README.md Resets the midpoint to the initial value of maxADC / 2, as set in the constructor. ```cpp ACS.resetMidPoint(); ``` -------------------------------- ### Auto Midpoint for DC Current Source: https://github.com/robtillaart/acs712/blob/master/README.md Automatically determines the midpoint for DC current measurements. Increase cycles to reduce noise. ```cpp uint16_t midPoint = ACS.autoMidPointDC(100); ``` -------------------------------- ### Set Midpoint for ADC Conversion Source: https://github.com/robtillaart/acs712/blob/master/README.md Sets the midpoint for ADC conversion. The parameter must be between 0 and maxADC/2. ```cpp uint16_t midpoint = ACS.setMidPoint(ACS.getMinimum(20)/2 + ACS.getMaximum(20)/ 2); ``` -------------------------------- ### Disconnect Detection Schema (Pull-up) Source: https://github.com/robtillaart/acs712/blob/master/README.md This diagram illustrates a pull-up configuration for detecting ACS712 disconnection from the ADC. R1 is set to 1 M ohm. ```text ACS712 OUT | | VCC ----[ R1 ]----o R1 = 1 M ohm. | | ADC of processor ``` -------------------------------- ### Set Form Factor for AC Measurements Source: https://github.com/robtillaart/acs712/blob/master/README.md Manually sets the form factor for AC current measurements. Must typically be between 0.0 and 1.0. ```cpp ACS.setFormFactor(ACS712_FF_SQUARE); ``` -------------------------------- ### mA_peak2peak Source: https://github.com/robtillaart/acs712/blob/master/README.md Measures and returns the peak-to-peak AC current in milliamperes. This function can be used to determine the form factor of the current and to detect the lowest detectable current by measuring on a zero current line. ```APIDOC ## mA_peak2peak(float frequency = 50, uint16_t cycles = 1) ### Description Measures and returns the peak-to-peak AC current in milliamperes. This function blocks for approximately 21 ms to sample a whole 50 or 60 Hz period. It can be used to determine the form factor of the current and to get an indication of the lowest detectable current by measuring on a zero current line. This function is also used internally to detect the noise level in mV on a zero current line. ### Parameters * **frequency** (float) - Optional. The frequency of the AC signal in Hz (defaults to 50 Hz). * **cycles** (uint16_t) - Optional. The number of cycles to average over (defaults to 1). ``` -------------------------------- ### mA_DC Source: https://github.com/robtillaart/acs712/blob/master/README.md Measures and returns the DC current in milliamperes. This function blocks for less than 1 ms and can indicate current direction with a negative value. It supports averaging over a specified number of samples and includes yield() calls for RTOS compatibility. ```APIDOC ## mA_DC(uint16_t samples = 1) ### Description Measures and returns the DC current in milliamperes. This function blocks for less than 1 ms (on an Arduino UNO) as it calls `analogRead()` twice. A negative value indicates the current flows in the opposite direction. The parameter `samples` allows averaging over a number of samples. For RTOS compatibility, `yield()` is called every 2nd iteration. ### Parameters * **samples** (uint16_t) - Optional. The number of samples to average over (defaults to 1). ``` -------------------------------- ### Measure AC Current (Sampling Method) Source: https://github.com/robtillaart/acs712/blob/master/README.md Measures the AC current in mA by sampling a full period and calculating the RMS value. This function is suitable for signals with unknown Form Factors. Blocks for approximately 21 ms for a 50/60 Hz period. Supports averaging over multiple cycles. ```cpp float mA_AC_sampling(float frequency = 50, uint16_t cycles = 1) ``` -------------------------------- ### mA_AC_sampling Source: https://github.com/robtillaart/acs712/blob/master/README.md Measures the AC current in milliamperes by sampling a full period and calculating the square root of the average sum of squares. This is suitable for signals with unknown Form Factors and supports averaging over multiple cycles. ```APIDOC ## mA_AC_sampling(float frequency = 50, uint16_t cycles = 1) ### Description Measures the AC current in milliamperes by sampling a full period and calculating the square root of the average sum of squares. This function blocks for approximately 21 ms to sample a whole period. It is intended for signals with unknown Form Factors. The parameter `cycles` allows averaging over a number of cycles. ### Parameters * **frequency** (float) - Optional. The frequency of the AC signal in Hz (defaults to 50 Hz). * **cycles** (uint16_t) - Optional. The number of cycles to average over (defaults to 1). ``` -------------------------------- ### mA_AC Source: https://github.com/robtillaart/acs712/blob/master/README.md Calculates and returns the AC current in milliamperes. This function relies on the peak-to-peak value and a known Form Factor. It supports various frequencies and averaging over multiple cycles. ```APIDOC ## mA_AC(float frequency = 50, uint16_t cycles = 1) ### Description Calculates and returns the AC current in milliamperes. This function blocks for approximately 21 ms to sample a whole 50 or 60 Hz period. The function returns the AC current in mA. Its working is based upon multiplying the peak2peak value by the FormFactor which must be known and set. Frequencies other than 50 and 60 Hz are supported, as well as floating point frequencies for better tuning. The parameter `cycles` allows averaging over a number of cycles. ### Parameters * **frequency** (float) - Optional. The frequency of the AC signal in Hz (defaults to 50 Hz). * **cycles** (uint16_t) - Optional. The number of cycles to average over (defaults to 1). ``` -------------------------------- ### Measure DC Current Source: https://github.com/robtillaart/acs712/blob/master/README.md Measures the DC current in mA. A negative value indicates current flow in the opposite direction. This function blocks for less than 1 ms on an Arduino UNO. Supports averaging over multiple samples and yields periodically under RTOS. ```cpp float mA_DC(uint16_t samples = 1) ``` -------------------------------- ### Auto Midpoint for AC or DC Current Source: https://github.com/robtillaart/acs712/blob/master/README.md Automatically determines the midpoint for AC current or zero DC current. Blocks for at least 2 periods. ```cpp uint16_t midPoint = ACS.autoMidPoint(50, 5); ``` -------------------------------- ### Measure Peak-to-Peak AC Current Source: https://github.com/robtillaart/acs712/blob/master/README.md Measures the peak-to-peak AC current, which can be used to determine the form factor or the lowest detectable current by measuring on a zero current line. Blocks for approximately 21 ms for a 50/60 Hz period. ```cpp float mA_peak2peak(float frequency = 50, uint16_t cycles = 1) ``` -------------------------------- ### Calculate mA LSB Source: https://github.com/robtillaart/acs712/blob/master/README.md Calculates the milliampere Least Significant Bit (LSB) based on the sensor's mV per Ampere rating and the ADC's maximum value. This is useful for understanding the resolution of the sensor with a specific ADC. ```cpp getmAPerStep(); mA LSB = (5000 mV / maxADC) / mVperA * 1000.0; mA LSB = (1000 * 5000 mV) / (maxADC * mVperA); ``` -------------------------------- ### Manually Decrease Midpoint Source: https://github.com/robtillaart/acs712/blob/master/README.md Manually decreases the midpoint value. The function will not decrease if the midpoint equals 0. ```cpp ACS.decMidPoint(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.