{"id":13893949,"url":"https://github.com/RobTillaart/ACS712","last_synced_at":"2025-07-17T08:31:40.430Z","repository":{"id":43808812,"uuid":"249050570","full_name":"RobTillaart/ACS712","owner":"RobTillaart","description":"Arduino library for ACS Current Sensor - 5A, 20A, 30A","archived":false,"fork":false,"pushed_at":"2024-10-20T09:03:51.000Z","size":93,"stargazers_count":129,"open_issues_count":0,"forks_count":35,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-11-19T06:33:46.971Z","etag":null,"topics":["arduino","current","sensor"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2020-03-21T19:57:12.000Z","updated_at":"2024-11-14T19:45:44.000Z","dependencies_parsed_at":"2024-01-25T14:27:03.724Z","dependency_job_id":"472ba0b1-1a19-460e-99e5-a6cd655d52bb","html_url":"https://github.com/RobTillaart/ACS712","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FACS712","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FACS712/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FACS712/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FACS712/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/ACS712/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226243893,"owners_count":17594452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","current","sensor"],"created_at":"2024-08-06T18:01:20.553Z","updated_at":"2024-11-24T22:31:00.120Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":["C++"],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/ACS712/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/ACS712/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ACS712/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/ACS712/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ACS712/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/ACS712.svg)](https://github.com/RobTillaart/ACS712/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ACS712/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/ACS712.svg?maxAge=3600)](https://github.com/RobTillaart/ACS712/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/ACS712.svg)](https://registry.platformio.org/libraries/robtillaart/ACS712)\n\n\n# ACS712\n\nLibrary for the ACS712 Current Sensor - 5A, 20A, 30A and compatibles.\n\n\n## Description\n\nThe ACS712 is a chip to measure current, both AC or DC. The chip has an\nanalogue output that provides a voltage that is linear with the current.\nThe ACS712 library supports only a built in ADC by means of **analogRead()**.\n\nHowever since 0.3.4 there is an experimental **setADC()**.\n\nThe library has 4 core functions:\n\n- **float mA_peak2peak(frequency = 50, cycles = 1)**\n- **float mA_DC(cycles = 1)**\n- **float mA_AC(frequency = 50, cycles = 1)**\n- **float mA_AC_sampling(frequency = 50, cycles = 1)**\n\nThe parameter cycles is used to measure multiple cycles and average them.\n\nTo measure DC current a single **analogRead()** with conversion math is\nsufficient to get a value.\nTo stabilize the signal **analogRead()** is called at least twice.\n\nTo measure AC current **a blocking loop for 20 milliseconds** (50 Hz, 1 cycle)\nis run to determine the peak to peak value which is converted to the RMS value.\nTo convert the peak2peak value to RMS one need the so called crest or form factor.\nThis factor depends heavily on the signal form, hence its name.\nFor a perfect sinus the value is sqrt(2)/2 == 1/sqrt(2).\nSee **Form factor** below.\n\nFor a 60 Hz environment the blocking is ~16.7 milliseconds, still pretty long.\n\nThe **mA_AC_sampling()** calculates the average of the sumSquared of many measurements.\nThis function should be used when the form factor is not known.\n\nNote to make precise measurements, the power supply of both the ACS712 and the ADC of\nthe processor should be as stable as possible.\nThat improves the stability of the midpoint and minimizes the noise.\n\n\n### Resolution\n\n|  Sensor  |  mVperA  |  LSB 10bit  |  LSB 12bit  |  LSB 16bit  |\n|:---------|:--------:|:-----------:|:-----------:|:-----------:|\n|    5 A   |    185   |   26.4 mA   |    6.6 mA   |   0.41 mA   |\n|   20 A   |    100   |   48.9 mA   |   12.2 mA   |   0.76 mA   |\n|   30 A   |     66   |   74.1 mA   |   18.5 mA   |   1.16 mA   |\n\n```cpp\ngetmAPerStep();\nmA LSB = (5000 mV / maxADC) / mVperA * 1000.0;\nmA LSB = (1000 * 5000 mV) / (maxADC * mVperA);\n```\n\nAlthough no 16 bit ADC built in are known, it indicates what resolution\ncould be obtained with such an ADC. It triggered the experimental supporting\nof external ADC's with this library.\n\n\n### Calibration and accuracy\n\nThe library has no means to calibrate the output or use an offset.\nHowever sort of calibrating can relatively easy be done by using \nthe MultiMap library.\nMultiMap approaches a non-linear mapping by multiple linear mappings.\n\nSee https://github.com/RobTillaart/MultiMap.\n\n\n### Tests\n\nThe library is at least confirmed to work with the following boards:\n\n| Device       | Voltage | ADC steps |  Notes  |\n|:-------------|:-------:|:---------:|:--------|\n| Arduino UNO  |  5.0V   |   1024    | tested with RobotDyn ACS712 20 A breakout.\n| Arduino UNO  |  5.0V   |   1024    | tested with Open-Smart ACS712 5 A breakout.\n| Arduino NANO |  5.0V   |   1024    | #18\n| ESP32        |  3.3V   |   4096    | #15\n| Promicro     |  5.0V   |   1024    | #15\n\nPlease let me know of other working platforms / processors (and failing ones!).\n\n\n## Compatibles\n\nRobodyn has a breakout for the ACS758 - 50 A. - See resolution below.\nThis sensor has versions up to 200 Amps, so use with care!\n\nAllegroMicro offers a lot of different current sensors that might be compatible.\nThese include bidirectional and unidirectional ones.\nThe unidirectional seem to be for DC only.\n\nhttps://www.allegromicro.com/en/products/sense/current-sensor-ics/current-sensors-innovations\n\n\nDevices that could be compatible:\n\n|        | ACS720 | ACS724 | ACS725 | ACS732 | ACS733|  ACS758 | ACS772 | ACS773 | ACS780 | ACS781 |\n|:------:|:------:|:------:|:------:|:------:|:------:|:------:|:------:|:------:|:------:|:------:|\n| tested |        |        |   #44  |        |        |        |        |        |        |        |\n\n\n|        | ACS37002 | ACS37003 | ACS71240 | ACS3761X | ACS37800 | ACS72981 |\n|:------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|\n| tested |          |          |          |          |          |          |\n\n\nIf you have tested a compatible sensor, please share your experiences.\n(can be done by opening an issue to update documentation)\n\n\n### Resolution ACS758\n\nNot tested, but looks compatible - same formula as above\n\n|  Sensor  |  mVperA  |  LSB 10bit  |  LSB 12bit  |  LSB 16bit  |  directional  |\n|:---------|:--------:|:-----------:|:-----------:|:-----------:|:-------------:|\n|   50 A   |     40   |  122.2 mA   |   30.5 mA   |   1.91 mA   |     bi        |\n|   50 A   |     60   |   81.5 mA   |   20.3 mA   |   1.27 mA   |     uni       |\n|  100 A   |     20   |  244.4 mA   |   61.0 mA   |   3.81 mA   |     bi        |\n|  100 A   |     40   |  122.2 mA   |   30.5 mA   |   1.91 mA   |     uni       |\n|  150 A   |   13.3   |  367.5 mA   |   91.8 mA   |   5.74 mA   |     bi        |\n|  150 A   |   26.7   |  183.1 mA   |   45.7 mA   |   2.86 mA   |     uni       |\n|  200 A   |     10   |  488.8 mA   |  122.1 mA   |   7.63 mA   |     bi        |\n|  200 A   |     20   |  244.4 mA   |   61.0 mA   |   3.81 mA   |     uni       |\n\n\n## Interface\n\n```cpp\n#include ACS712.h\n```\n\n\n### Base\n\n- **ACS712(uint8_t analogPin, float volts = 5.0, uint16_t maxADC = 1023, float mVperAmpere = 100)** constructor.\nIt defaults a 20 A type sensor, which is defined by the default value of mVperAmpere. See table below.\nVolts is the voltage used by the (Arduino) internal ADC. maxADC is the maximum output of the internal ADC.\nThe defaults are based upon an Arduino UNO, 10 bits ADC.\nThese two ADC parameters are needed to calculate the voltage output of the ACS712 sensor.\n- **float mA_peak2peak(float frequency = 50, uint16_t cycles = 1)** blocks ~21 ms to sample a whole 50 or 60 Hz period.\nReturns the peak to peak current, can be used to determine form factor.\nThe **mA_peak2peak()** can also be used to measure on a zero current line\nto get an indication of the lowest detectable current.\nFinally this function is used internally to detect the noiseLevel in mV on a zero current line.\n- **float mA_AC(float frequency = 50, uint16_t cycles = 1)** blocks ~21 ms to sample a whole 50 or 60 Hz period.\nNote that a lower frequency, or more cycles, will increase the blocking period.\nThe function returns the AC current in mA.\nIts working is based upon multiplying the peak2peak value by the FormFactor which must be known and set.\n  - 0.2.2 frequencies other integer values than 50 and 60 are supported.\n  - 0.2.3 floating point frequencies are supported to tune even better.\n  - 0.2.8 the parameter cycles allow to average over a number of cycles.\n- **float mA_AC_sampling(float frequency = 50, uint16_t cycles = 1)** blocks ~21 ms to sample a whole period.\nThe function returns the AC current in mA. (Note it returns a float).\nIts working is based upon sampling a full period and take the square root of the average sumSquared.\nThis function is intended for signals with unknown Form Factor.\n  - 0.2.8 the parameter cycles allow to average over a number of cycles.\n- **float mA_DC(uint16_t samples = 1)** blocks \u003c 1 ms (Arduino UNO) as it calls **analogRead()** twice.\nA negative value indicates the current flows in the opposite direction.\n  - 0.2.8 the parameter samples allow to average over a number of samples.\n  - 0.3.9 calls yield() every 2nd iteration to improve behaviour under RTOS.\n\n\n### mA_AC_sampling performance trick.\n\nA trick to sample faster is to set the frequency to 2 times the actual frequency so to 100 or 120 Hz.\nThis results in sampling only half a period and the same current will be measured.\nAdvantage is that the function only blocks for ~10 ms @ 50Hz (8.5 @ 60Hz).\nThe drawback is about 4x as many variation.\nSo only use if the performance (or less blocking) is needed.\n\nIn a similar way one can increase the accuracy (reducing the variation) \nby setting the frequency a factor 2 lower (25 and 30 Hz).\nDrawback is a far longer blocking time.\n\nUse with care!\n\nSee - https://github.com/RobTillaart/ACS712/issues/38\n\n\n### Midpoint\n\nThe midpoint is the (raw) zero-reference for all current measurements.\nIt is defined in steps of the ADC and is typical around half the **maxADC** value defined\nin the constructor. So for a 10 bit ADC a number between 500..525 is most likely.\n\nSince 0.3.0 all midpoint functions return the actual midPoint.\n\n- **uint16_t setMidPoint(uint16_t midPoint)** sets midpoint for the ADC conversion.\nParameter must be between 0 and maxADC/2, otherwise midpoint is not changed.\n- **uint16_t getMidPoint()** read the value set / determined.\n- **uint16_t incMidPoint()** manual increase midpoint, e.g. useful in an interactive application.\nWill not increase if midpoint equals maxADC.\n- **uint16_t decMidPoint()** manual decrease midpoint.\nWill not decrease if midpoint equals 0.\n- **uint16_t resetMidPoint()** resets the midpoint to the initial value of maxADC / 2 as in the constructor.\n- **uint16_t autoMidPointDC(uint16_t cycles = 1)** Auto midPoint for DC only.\nAssuming zero DC current. To reduce the noise cycles must be increased even up to 100.\nThis method is typically much faster for DC than the **autoMidPoint(freq, cycles)** \nfor the same number of cycles. (See issue #35)\n- **uint16_t autoMidPoint(float frequency = 50, uint16_t cycles = 1)** Auto midPoint, for any AC current or zero DC current.  \nFor DC one can use a high frequency e.g. 1000 Hz to reduce the time blocking.\nThe function takes the average of many measurements during one or more full cycles.\nNote the function therefore blocks for at least 2 periods which is about \n40 ms for 50 Hz.\nBy increasing the number of cycles the function averages even more measurements,\npossibly resulting in a better midPoint. Idea is that noise will average out.\nThis function is mandatory for measuring AC.\n  - 0.2.2 frequencies other than 50 and 60 are supported.\n  - 0.2.8 the parameter cycles allow to average over a number of cycles.\n\n\nSince version 0.3.0 there is another way to determine the midPoint.\nOne can use the two debug functions.\n(milliseconds \u003e 20 to get at least a full cycle)\n- **uint16_t getMinimum(uint16_t milliSeconds = 20)**\n- **uint16_t getMaximum(uint16_t milliSeconds = 20)**\n\nand take the average of these two values. In code:\n\n```cpp\nuint16_t midpoint = ACS.setMidPoint(ACS.getMinimum(20)/2 + ACS.getMaximum(20)/ 2);\n```\nSee - ACS712_20_AC_midPoint_compare.ino\n\nThe ACS712 has a midPoint level that is specified as  0.5 \\* VCC.\nSo **autoMidPoint()** can help to detect voltage deviations for the ACS712.\nThe library does not support this yet.\n\n\n### Form factor\n\nThe form factor is also known as the **crest factor**.\nIt is only used for signals measured with **mA_AC()**.\n\n- **void setFormFactor(float formFactor = ACS712_FF_SINUS)** manually sets the form factor.\nMust typical be between 0.0 and 1.0, see constants below.\n- **float getFormFactor()** returns current form factor.\n\nThe library has a number of predefined form factors:\n\n|  definition          |  value          |  approx  |  notes    |\n|:---------------------|:----------------|:--------:|:----------|\n|  ACS712_FF_SQUARE    |  1.0            |  1.000   |\n|  ACS712_FF_SINUS     |  1.0 / sqrt(2)  |  0.707   |  default  |\n|  ACS712_FF_TRIANGLE  |  1.0 / sqrt(3)  |  0.577   |\n|  ACS712_FF_SAWTOOTH  |  1.0 / sqrt(3)  |  0.577   |\n\nIt is important to measure the current with a calibrated multimeter\nand determine / verify the form factor of the signal.\nThis can help to improve the quality of your measurements.\n\nPlease let me know if other crest factors need to be added.\n\nSince version 0.3.0 the form factor can be determined by\n\n```cpp\nfloat formFactor = 2.0 * mA_AC_sampling() / ACS.mA_peak2peak();\n```\n\nSee - ACS712_20_determine_form_factor.ino\n\n\n### Noise\n\nDefault = 21 mV (datasheet)\n\n- **void setNoisemV(uint8_t noisemV = 21)** sets the noise level,\nis used to determine zero level e.g. in the AC measurements with **mA_AC()**.\n- **uint8_t getNoisemV()** returns the set value.\n- **float mVNoiseLevel(float frequency, uint16_t cycles)** determines the mV of noise.\nMeasurement should be taken when there is no AC/DC current or a constant DC current.\nThe level will give a (not quantified yet) indication of the accuracy of the measurements.\nA first order indication can be made by comparing it to voltage / 2 of the constructor.\n\nNoise on the signal can be reduced by using a low pass (RC) filter.\nVersion 0.3.1 includes experimental code to take two sample and average them.\nThe idea is that ```((3 + 5)/2)^2   \u003c  (3^2 + 5^2)/2```\n\nIn theory this should suppress noise levels however more investigation in\nsoftware noise detection and suppression is needed.\n\n- **void suppressNoise(bool flag)** experimental noise suppression.\n\n\n### mV per Ampere\n\nUsed for both for AC and DC measurements.\nIts value is defined in the constructor and depends on type sensor used.\nThese functions allow to adjust this setting run-time.\n\n- **void setmVperAmp(float mVperAmpere)** sets the milliVolt per Ampere measured.\n- **float getmVperAmp()** returns the set value.\n\nTypical values see \"Resolution\" section above, and the \"voltage divider\" section below.\n\n\n### Frequency detection\n\nExperimental functionality for AC signal only!\n\n- **float detectFrequency(float minimalFrequency = 40)** Detect the frequency of the AC signal.\n- **void setMicrosAdjust(float factor = 1.0)** adjusts the timing of micros in **detectFrequency()**.\nValues are typical around 1.0 ± 1%\n- **float getMicrosAdjust()** returns the set factor.\n\nThe minimum frequency of 40 Hz is used to sample for enough time to find the minimum and maximum\nfor 50 and 60 Hz signals.\nThereafter the signal is sampled 10 cycles to minimize the variation of the frequency.\n\nThe **microsAdjust()** is to adjust the timing of **micros()**.\nThis function is only useful if one has a good reference source like a calibrated function generator\nto find the factor to adjust.\nTesting with my UNO I got a factor 0.9986.\n\nCurrent version is experimental and not performance optimized.\n\n\n### setADC (experimental 0.3.4)\n\n- **void setADC(uint16_t (\\*)(uint8_t), float volts, uint16_t maxADC)** sets the ADC function and the parameters of the used ADC.\nThe library uses the internal **analogRead()** as default.\nBe sure to set the parameters of the ADC correctly.\n\nThe easiest way to implement an external ADC is to make a wrapper function as casting for\nfunction pointer is a no go area.\n\n\n```cpp\n//  set to external ADC - 5 volts 12 bits\nACS.setADC(myAnalogRead, 5.0, 4096);\n\n...\n\nuint16_t myAnalogRead(uint8_t pin)\n{\n  return MCP.read(pin);  //  assuming MCP is ADC object.\n}\n```\n\n\nTo reset to the internal ADC use **NULL** as function pointer.\nBe sure to set the parameters of the ADC correctly.\n\n```cpp\n//  reset to internal ADC - 5 volts 10 bits\nACS.setADC(NULL, 5.0, 1023);\n```\n\n- example ACS712_20_DC_external_ADC.ino\n- https://github.com/RobTillaart/ACS712/issues/31\n\n- example ACS712_ESP32_external_ADC.ino\n- https://github.com/RobTillaart/ACS712/issues/46\n\n\nNote that the use of an external ADC should meet certain performance requirements,\nespecially for measuring **ma-AC()**.\n\nTo 'catch' the peaks well enough one needs at least 2 samples per millisecond (2000 sps)\nfor a 60 Hz signal. That gives 34 samples for 360 degrees =\u003e 10.6 degrees, which \nresults in a max deviation of 5.3 degrees from peak =\u003e max 0.5% off.\n\nAs a 50 Hz signal is a bit slower, 2000 sps would give 40 samples for =\u003e 9 degrees,\nwhich results in a max deviation of 4.5 degrees from peak =\u003e max 0.4% off.\n\n\nThe 16 bit I2C **ADS1115** in continuous mode gives max 0.8 samples per millisecond.\nThis will work perfect for high resolution **mA-DC()** but is not fast enough for\ndoing **mA-AC()**. It will get an accuracy around ~2%.\n\nThe SPI based **MCP3202** ao can do up to 100 samples per millisecond at 12 bit.\nThese ADC's are perfect both **mA-DC()** and **mA-AC()**.\n\n- https://github.com/RobTillaart/ADS1X15\n- https://github.com/RobTillaart/MCP_ADC\n\n\n## Voltage divider\n\nAs per issue #15 in which an ACS712 was connected via a voltage divider to the ADC of an ESP32.\nIdem issue #43 with an ACS712 (5A) to a bare ESP8266 (1V ADC!).\n\nSchema\n```\nACS712 ----[ R1 ]----o----[ R2 ]---- GND\n                     |\n                     |\n                ADC of processor\n```\n\nThe voltage divider gave an error of about a factor 2 as all voltages were divided,\nincluding the \"offset\" from the **midPoint** zero current level.\n\nBy adjusting the mV per Ampere with **setmVperAmp(float mva)** the readings can be corrected\nfor this \"voltage divider effect\".\n\n\n### Examples:\n\n\nFor a 5 A type sensor, 185 mV/A would be the normal value.\nAfter using a voltage divider one need to adjust the mVperAmp.\n\n| R1 (ACS) | R2 (GND)  | voltage factor                  |  mVperAmp corrected     |  notes  |\n|---------:|----------:|--------------------------------:|:-----------------------:|:--------|\n|  10200   |  4745     |  4745 / (10200 + 4745) = 0.3175 | 185 \\* 0.3175 =  31.75  |\n|  4745    |  10200    | 10200 / (10200 + 4745) = 0.6825 | 185 \\* 0.6825 =  68.25  |\n|  10200   |  9800     |  9800 / (10200 + 9800) = 0.4900 | 185 \\* 0.4900 =  49.00  |\n|  1000    |  2200     |  2200 / (1000 + 2200)  = 0.6875 | 185 \\* 0.6875 = 127.19  | 5V -\u003e 3V3 ADC\n|  300     |  75       |  75   / (300 + 75)     = 0.2000 | 185 \\* 0.2000 =  37.00  |  5V -\u003e 1V ADC\n\n\nFor a 20 A type sensor, 100 mV/A would be the normal value.\nAfter using a voltage divider one need to adjust the mVperAmp.\n\n| R1 (ACS) | R2 (GND)  | voltage factor                  |  mVperAmp corrected     |  notes  |\n|---------:|----------:|--------------------------------:|:-----------------------:|:--------|\n|  10200   |  4745     |  4745 / (10200 + 4745) = 0.3175 | 100 \\* 0.3175 =  31.75  |\n|  4745    |  10200    | 10200 / (10200 + 4745) = 0.6825 | 100 \\* 0.6825 =  68.25  |\n|  10200   |  9800     |  9800 / (10200 + 9800) = 0.4900 | 100 \\* 0.4900 =  49.00  |\n|  1000    |  2200     |  2200 / (1000 + 2200)  = 0.6875 | 100 \\* 0.6875 =  68.75  |  5V -\u003e 3V3 ADC\n|  300     |  75       |  75   / (300 + 75)     = 0.2000 | 100 \\* 0.2000 =  20.00  |  5V -\u003e 1V ADC\n\n\nFor a 30 A type sensor, 66 mV/A would be the normal value.\nAfter using a voltage divider one need to adjust the mVperAmp.\n\n| R1 (ACS) | R2 (GND)  | voltage factor                  |  mVperAmp corrected     |  notes  |\n|---------:|----------:|--------------------------------:|:-----------------------:|:--------|\n|  10200   |  4745     |  4745 / (10200 + 4745) = 0.3175 |  66 \\* 0.3175 =  31.75  |\n|  4745    |  10200    | 10200 / (10200 + 4745) = 0.6825 |  66 \\* 0.6825 =  68.25  |\n|  10200   |  9800     |  9800 / (10200 + 9800) = 0.4900 |  66 \\* 0.4900 =  49.00  |\n|  1000    |  2200     |  2200 / (1000 + 2200)  = 0.6875 |  66 \\* 0.6875 =  45.38  |  5V -\u003e 3V3 ADC\n|  300     |  75       |  75   / (300 + 75)     = 0.2000 |  66 \\* 0.2000 =  13.20  |  5V -\u003e 1V ADC\n\n**Note:** setting the midPoint correctly is also needed when using a voltage divider.\n\n\n## Disconnect detection\n\n(to be tested)\n\nTo detect that the ACS712 is disconnected from the ADC one could connect the\nanalog pin via a pull-down to GND. A pull-up to VCC is also possible.\nChoose the solution that fits your project best. (Think safety).\n\n**mA_DC()** and **mA_AC_sampling()** will report HIGH values (Out of range) when\nthe ACS712 is disconnected.\nThe other - peak2peak based functions - will see this as zero current (min == max).\n\nSchema with PULL-UP.\n```\n                 ACS712 OUT\n                     |\n                     |\n   VCC ----[ R1 ]----o       R1 = 1 M ohm.\n                     |\n                     |\n                ADC of processor\n```\n\nThe library does not support this \"extreme values\" detection.\n\n\n## RTOS\n\nThe library can be used in an RTOS environment, however a few functions of this\nlibrary are blocking for relative long times.\n\nIn version 0.3.9 the **mA_DC()** calls **yield()** between every three calls of analogRead.\nThis is done both for the external and intern ADC to prevent blocking of other threads.\n\nFor the **mA_AC()** and **mA_peak2peak()** a call to yield() is not desirable \nas the samples are all needed to make a decent measurement.\nFor the applications that need proper scheduling one should put the sampling of the \nINA226 at least for **AC** in a separate thread.  \n\nThere is no RTOS example. If you have and willing to share you are welcome.\n\n\n## ESPhome\n\nFor people who want to use this library for ESPhome, there exists a wrapper \nclass for this ACS712 library.\n\n- https://github.com/marianomd/acs712-esphome\n\nAs I do not have ESPhome know how, please share your experiences.\nThis can be done by an issue.\n\n- https://github.com/RobTillaart/ACS712/issues/51\n\n\n## Operation\n\nThe examples show the basic working of the functions.\n\n\n## Future\n\n#### Must\n\n- test more\n  - other than the 20A module\n  - 5, 10, 30, 50 ...\n  - need to buy extra hardware\n\n\n#### Should - 0.3.x\n\n- investigate **estimateMidPoint(confidence)** See issue #35\n  - is less blocking by spreading the sampling over many calls.\n    returning a confidence level.\n- investigate noise suppression  #21 (0.3.1 and later)\n- investigate blocking calls:\n  - **mA_AC()** blocks for about 20 ms at 50 Hz.\n  This might affect task scheduling on a ESP32. Needs to be investigated.\n  Probably need a separate thread that wakes up when new analogRead is available?\n  - RTOS specific class?\n- investigate **detectFrequency(float)** blocks pretty long.\n\n\n#### Could\n\n- merge **mA_AC()** and **mA_AC_sampling()** into one. (0.4.0)\n  - or remove - depreciate - the worst one\n- add range check to (all) set functions?\n- add unit test for **autoMidPointDC()** (needed?)\n- **setMidPoint()**\n  - Q: could midpoint be set beyond maxADC? is there any use case?\n\n\n#### Won't (unless requested)\n\n- investigate support for micro-Amperes. **ACS.uA_DC()**\n  - need a very stable voltage\n  - needs a 24 bit ADC\n  - default noise is already ~21mV...\n  - =\u003e not feasible in normal setup.\n- Should the FormFactor not be just a parameter of **mA_AC()**\n  it is the only function using it. ==\u003e No unnecessary breaking API\n- should cycles be an uint8_t ?\n  - No, uint16 allows averaging in minutes range uint8_t just ~5 seconds\n- midPoint can be a float so it can be set more exact.\n  - extra precision is max half bit = smaller than noise?\n  - math will be slower during sampling (UNO)\n- split the readme.md in multiple documents?\n  - which?\n- setADC() to support \u003e 16 bit?\n  - uint32_t performance penalty?\n\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobTillaart%2FACS712","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRobTillaart%2FACS712","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobTillaart%2FACS712/lists"}