Skip to content

Commit 1288094

Browse files
authored
update readme.md (#52)
- update readme.md, ESPHome #51, kudos to uTZFu - add debug example.
1 parent a9e3fe6 commit 1288094

File tree

7 files changed

+135
-33
lines changed

7 files changed

+135
-33
lines changed

ACS712.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: ACS712.cpp
33
// AUTHOR: Rob Tillaart, Pete Thompson
4-
// VERSION: 0.3.9
4+
// VERSION: 0.3.10
55
// DATE: 2020-08-02
66
// PURPOSE: ACS712 library - current measurement
77
// URL: https://github.com/RobTillaart/ACS712
@@ -18,10 +18,10 @@ ACS712::ACS712(uint8_t analogPin, float volts, uint16_t maxADC, float mVperAmper
1818
_formFactor = ACS712_FF_SINUS;
1919
_noisemV = ACS712_DEFAULT_NOISE; // 21mV according to datasheet
2020

21-
// set in setADC()
21+
// set in setADC()
2222
// keep it here until after experimental.
2323
_maxADC = maxADC;
24-
_mVperStep = 1000.0 * volts / maxADC; // 1x 1000 for V -> mV
24+
_mVperStep = 1000.0 * volts / maxADC; // 1x 1000.0 for V -> mV
2525
_mAPerStep = 1000.0 * _mVperStep / _mVperAmpere;
2626
_midPoint = maxADC / 2;
2727

ACS712.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: ACS712.h
44
// AUTHOR: Rob Tillaart, Pete Thompson
5-
// VERSION: 0.3.9
5+
// VERSION: 0.3.10
66
// DATE: 2020-08-02
77
// PURPOSE: ACS712 library - current measurement
88
// URL: https://github.com/RobTillaart/ACS712
@@ -14,18 +14,18 @@
1414
#include "Arduino.h"
1515

1616

17-
#define ACS712_LIB_VERSION (F("0.3.9"))
17+
#define ACS712_LIB_VERSION (F("0.3.10"))
1818

1919

2020
// ACS712_FF_SINUS == 1.0/sqrt(2) == 0.5 * sqrt(2)
2121
// should be smaller in practice 0.5 ?
22-
#define ACS712_FF_SINUS (1.0/sqrt(2))
23-
#define ACS712_FF_SQUARE (1.0)
24-
#define ACS712_FF_TRIANGLE (1.0/sqrt(3))
25-
#define ACS712_FF_SAWTOOTH (1.0/sqrt(3))
22+
#define ACS712_FF_SINUS (1.0/sqrt(2))
23+
#define ACS712_FF_SQUARE (1.0)
24+
#define ACS712_FF_TRIANGLE (1.0/sqrt(3))
25+
#define ACS712_FF_SAWTOOTH (1.0/sqrt(3))
2626

27-
#define ACS712_DEFAULT_FREQ 50
28-
#define ACS712_DEFAULT_NOISE 21
27+
#define ACS712_DEFAULT_FREQ 50
28+
#define ACS712_DEFAULT_NOISE 21
2929

3030

3131
class ACS712
@@ -138,7 +138,7 @@ class ACS712
138138
// supports up to 16 bits ADC.
139139
uint16_t (* _readADC)(uint8_t);
140140
uint16_t _analogRead(uint8_t pin);
141-
141+
142142
};
143143

144144

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.3.10] - 2024-10-20
10+
- update readme.md, ESPHome #51, kudos to uTZFu
11+
- add debug example.
12+
913
## [0.3.9] - 2024-01-11
1014
- add yield() to improve the behaviour under RTOS
1115
- update readme.md (add compatibility table).
1216
- minor edits
1317

14-
1518
## [0.3.8] - 2023-09-19
1619
- add badges to readme.md
1720
- minor edits

README.md

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ the processor should be as stable as possible.
5252
That improves the stability of the midpoint and minimizes the noise.
5353

5454

55-
#### Resolution
55+
### Resolution
5656

5757
| Sensor | mVperA | LSB 10bit | LSB 12bit | LSB 16bit |
5858
|:---------|:--------:|:-----------:|:-----------:|:-----------:|
@@ -71,7 +71,7 @@ could be obtained with such an ADC. It triggered the experimental supporting
7171
of external ADC's with this library.
7272

7373

74-
#### Calibration and accuracy
74+
### Calibration and accuracy
7575

7676
The library has no means to calibrate the output or use an offset.
7777
However sort of calibrating can relatively easy be done by using
@@ -81,7 +81,7 @@ MultiMap approaches a non-linear mapping by multiple linear mappings.
8181
See https://github.com/RobTillaart/MultiMap.
8282

8383

84-
#### Tests
84+
### Tests
8585

8686
The library is at least confirmed to work with the following boards:
8787

@@ -124,7 +124,7 @@ If you have tested a compatible sensor, please share your experiences.
124124
(can be done by opening an issue to update documentation)
125125

126126

127-
#### Resolution ACS758
127+
### Resolution ACS758
128128

129129
Not tested, but looks compatible - same formula as above
130130

@@ -147,7 +147,7 @@ Not tested, but looks compatible - same formula as above
147147
```
148148

149149

150-
#### Base
150+
### Base
151151

152152
- **ACS712(uint8_t analogPin, float volts = 5.0, uint16_t maxADC = 1023, float mVperAmpere = 100)** constructor.
153153
It defaults a 20 A type sensor, which is defined by the default value of mVperAmpere. See table below.
@@ -177,7 +177,7 @@ A negative value indicates the current flows in the opposite direction.
177177
- 0.3.9 calls yield() every 2nd iteration to improve behaviour under RTOS.
178178

179179

180-
#### mA_AC_sampling performance trick.
180+
### mA_AC_sampling performance trick.
181181

182182
A trick to sample faster is to set the frequency to 2 times the actual frequency so to 100 or 120 Hz.
183183
This results in sampling only half a period and the same current will be measured.
@@ -194,7 +194,7 @@ Use with care!
194194
See - https://github.com/RobTillaart/ACS712/issues/38
195195

196196

197-
#### Midpoint
197+
### Midpoint
198198

199199
The midpoint is the (raw) zero-reference for all current measurements.
200200
It is defined in steps of the ADC and is typical around half the **maxADC** value defined
@@ -244,7 +244,7 @@ So **autoMidPoint()** can help to detect voltage deviations for the ACS712.
244244
The library does not support this yet.
245245

246246

247-
#### Form factor
247+
### Form factor
248248

249249
The form factor is also known as the **crest factor**.
250250
It is only used for signals measured with **mA_AC()**.
@@ -277,7 +277,7 @@ float formFactor = 2.0 * mA_AC_sampling() / ACS.mA_peak2peak();
277277
See - ACS712_20_determine_form_factor.ino
278278

279279

280-
#### Noise
280+
### Noise
281281

282282
Default = 21 mV (datasheet)
283283

@@ -299,7 +299,7 @@ software noise detection and suppression is needed.
299299
- **void suppressNoise(bool flag)** experimental noise suppression.
300300

301301

302-
#### mV per Ampere
302+
### mV per Ampere
303303

304304
Used for both for AC and DC measurements.
305305
Its value is defined in the constructor and depends on type sensor used.
@@ -311,7 +311,7 @@ These functions allow to adjust this setting run-time.
311311
Typical values see "Resolution" section above, and the "voltage divider" section below.
312312

313313

314-
#### Frequency detection
314+
### Frequency detection
315315

316316
Experimental functionality for AC signal only!
317317

@@ -332,7 +332,7 @@ Testing with my UNO I got a factor 0.9986.
332332
Current version is experimental and not performance optimized.
333333

334334

335-
#### setADC (experimental 0.3.4)
335+
### setADC (experimental 0.3.4)
336336

337337
- **void setADC(uint16_t (\*)(uint8_t), float volts, uint16_t maxADC)** sets the ADC function and the parameters of the used ADC.
338338
The library uses the internal **analogRead()** as default.
@@ -395,6 +395,7 @@ These ADC's are perfect both **mA-DC()** and **mA-AC()**.
395395
## Voltage divider
396396

397397
As per issue #15 in which an ACS712 was connected via a voltage divider to the ADC of an ESP32.
398+
Idem issue #43 with an ACS712 (5A) to a bare ESP8266 (1V ADC!).
398399

399400
Schema
400401
```
@@ -411,18 +412,44 @@ By adjusting the mV per Ampere with **setmVperAmp(float mva)** the readings can
411412
for this "voltage divider effect".
412413

413414

414-
#### Examples:
415+
### Examples:
416+
417+
418+
For a 5 A type sensor, 185 mV/A would be the normal value.
419+
After using a voltage divider one need to adjust the mVperAmp.
420+
421+
| R1 (ACS) | R2 (GND) | voltage factor | mVperAmp corrected | notes |
422+
|---------:|----------:|--------------------------------:|:-----------------------:|:--------|
423+
| 10200 | 4745 | 4745 / (10200 + 4745) = 0.3175 | 185 \* 0.3175 = 31.75 |
424+
| 4745 | 10200 | 10200 / (10200 + 4745) = 0.6825 | 185 \* 0.6825 = 68.25 |
425+
| 10200 | 9800 | 9800 / (10200 + 9800) = 0.4900 | 185 \* 0.4900 = 49.00 |
426+
| 1000 | 2200 | 2200 / (1000 + 2200) = 0.6875 | 185 \* 0.6875 = 127.19 | 5V -> 3V3 ADC
427+
| 300 | 75 | 75 / (300 + 75) = 0.2000 | 185 \* 0.2000 = 37.00 | 5V -> 1V ADC
428+
415429

416430
For a 20 A type sensor, 100 mV/A would be the normal value.
417431
After using a voltage divider one need to adjust the mVperAmp.
418432

419-
| R1 (ACS) | R2 (GND) | voltage factor | mVperAmp corrected |
420-
|:--------:|:---------:|:-------------------------------:|:-----------------------:|
421-
| 10200 | 4745 | 4745 / (10200 + 4745) = 0.3175 | 100 \* 0.3175 = 31.75 |
422-
| 4745 | 10200 | 10200 / (10200 + 4745) = 0.6825 | 100 \* 0.6825 = 68.25 |
423-
| 10200 | 9800 | 9800 / (10200 + 9800) = 0.4900 | 100 \* 0.4900 = 49.00 |
433+
| R1 (ACS) | R2 (GND) | voltage factor | mVperAmp corrected | notes |
434+
|---------:|----------:|--------------------------------:|:-----------------------:|:--------|
435+
| 10200 | 4745 | 4745 / (10200 + 4745) = 0.3175 | 100 \* 0.3175 = 31.75 |
436+
| 4745 | 10200 | 10200 / (10200 + 4745) = 0.6825 | 100 \* 0.6825 = 68.25 |
437+
| 10200 | 9800 | 9800 / (10200 + 9800) = 0.4900 | 100 \* 0.4900 = 49.00 |
438+
| 1000 | 2200 | 2200 / (1000 + 2200) = 0.6875 | 100 \* 0.6875 = 68.75 | 5V -> 3V3 ADC
439+
| 300 | 75 | 75 / (300 + 75) = 0.2000 | 100 \* 0.2000 = 20.00 | 5V -> 1V ADC
424440

425441

442+
For a 30 A type sensor, 66 mV/A would be the normal value.
443+
After using a voltage divider one need to adjust the mVperAmp.
444+
445+
| R1 (ACS) | R2 (GND) | voltage factor | mVperAmp corrected | notes |
446+
|---------:|----------:|--------------------------------:|:-----------------------:|:--------|
447+
| 10200 | 4745 | 4745 / (10200 + 4745) = 0.3175 | 66 \* 0.3175 = 31.75 |
448+
| 4745 | 10200 | 10200 / (10200 + 4745) = 0.6825 | 66 \* 0.6825 = 68.25 |
449+
| 10200 | 9800 | 9800 / (10200 + 9800) = 0.4900 | 66 \* 0.4900 = 49.00 |
450+
| 1000 | 2200 | 2200 / (1000 + 2200) = 0.6875 | 66 \* 0.6875 = 45.38 | 5V -> 3V3 ADC
451+
| 300 | 75 | 75 / (300 + 75) = 0.2000 | 66 \* 0.2000 = 13.20 | 5V -> 1V ADC
452+
426453
**Note:** setting the midPoint correctly is also needed when using a voltage divider.
427454

428455

@@ -472,11 +499,14 @@ There is no RTOS example. If you have and willing to share you are welcome.
472499

473500
For people who want to use this library for ESPhome, there exists a wrapper
474501
class for this ACS712 library.
502+
475503
- https://github.com/marianomd/acs712-esphome
476504

477505
As I do not have ESPhome know how, please share your experiences.
478506
This can be done by an issue.
479507

508+
- https://github.com/RobTillaart/ACS712/issues/51
509+
480510

481511
## Operation
482512

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// FILE: ACS712_debug.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: analyse effects of settings e.g. voltage divider
5+
// URL: https://github.com/RobTillaart/ACS712
6+
7+
8+
#include "ACS712.h"
9+
10+
11+
// Arduino UNO has 5.0 volt with a max ADC value of 1023 steps
12+
// ACS712 5A uses 185 mV per A
13+
// ACS712 20A uses 100 mV per A
14+
// ACS712 30A uses 66 mV per A
15+
16+
17+
ACS712 ACS(A0, 3.3, 1023, 185);
18+
ACS712 ACS2(A0, 1, 1023, 32);
19+
ACS712 ACS3(A0, 3.3, 1023, 37);
20+
ACS712 ACS4(A0, 1, 1023, 92.5);
21+
// ESP 32 example (might requires resistors to step down the logic voltage)
22+
// ACS712 ACS(25, 3.3, 4095, 185);
23+
24+
25+
float voltageDividerFactor(float R_ACS, float R_GND)
26+
{
27+
return R_GND / (R_ACS + R_GND);
28+
}
29+
30+
31+
void dumpACS(ACS712 acs)
32+
{
33+
Serial.print("MIDPOINT: ");
34+
Serial.println(acs.getMidPoint());
35+
Serial.print("NOISE mV: ");
36+
Serial.println(acs.getNoisemV());
37+
Serial.print("mV / AMP: ");
38+
Serial.println(acs.getmVperAmp());
39+
Serial.print("mA/step : ");
40+
Serial.println(acs.getmAPerStep());
41+
Serial.println();
42+
}
43+
44+
45+
void setup()
46+
{
47+
Serial.begin(115200);
48+
while (!Serial);
49+
Serial.println(__FILE__);
50+
Serial.print("ACS712_LIB_VERSION: ");
51+
Serial.println(ACS712_LIB_VERSION);
52+
53+
dumpACS(ACS);
54+
dumpACS(ACS2);
55+
dumpACS(ACS3);
56+
dumpACS(ACS4);
57+
58+
// just examples
59+
Serial.println(voltageDividerFactor(300, 75), 4);
60+
Serial.println(voltageDividerFactor(315, 70), 4);
61+
}
62+
63+
64+
void loop()
65+
{
66+
}
67+
68+
69+
// -- END OF FILE --

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"type": "git",
2222
"url": "https://github.com/RobTillaart/ACS712.git"
2323
},
24-
"version": "0.3.9",
24+
"version": "0.3.10",
2525
"license": "MIT",
2626
"frameworks": "*",
2727
"platforms": "*",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ACS712
2-
version=0.3.9
2+
version=0.3.10
33
author=Rob Tillaart <rob.tillaart@gmail.com>, Pete Thompson <pete.thompson@yahoo.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=ACS712 library for Arduino.

0 commit comments

Comments
 (0)