-
Notifications
You must be signed in to change notification settings - Fork 3
/
ACS712XX.h
50 lines (43 loc) · 1.52 KB
/
ACS712XX.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* FILE NAME: ACS712XX.h
* AUTHOR : Rafi
* VERSION : 1.0
* DATE : 01-June-2021
* PURPOSE : Measure current easier, using this ACS712 current sensor library.
* SOURCE : https://www.allegromicro.com/en/products/sense/current-sensor-ics/zero-to-fifty-amp-integrated-conductor-sensor-ics/acs712
*/
#ifndef ACS712XX_h
#define ACS712XX_h
#include <Arduino.h>
#define ACS712_05B_SENSITIVITY 185 // mV/A
#define ACS712_20A_SENSITIVITY 100 // mV/A
#define ACS712_30A_SENSITIVITY 66 // mV/A
enum ACS712XXType{
ACS712_05B = 0,
ACS712_20A = 1,
ACS712_30A = 2,
ACS712XX_N = 3
};
class ACS712XX{
public:
ACS712XX(ACS712XXType _type, uint8_t _pin, uint8_t _adc_ref = 5 ,int _adc_fs = 1023);
float autoCalibrate();
float getAC(float _freq = 50.0,float _n_total_period = 1.0);
float getDC(int _count = 10);
float getOffset() { return offset; }
float getSensitivity() { return 1000.0/inv_sensitivity; }
void setOffset(float _offset) { offset = _offset; }
void setSensitivity(float _sen);
void reset();
private:
uint8_t sensor_sen[ACS712XX_N] = {ACS712_05B_SENSITIVITY,
ACS712_20A_SENSITIVITY,
ACS712_30A_SENSITIVITY};
float inv_sensitivity;
float results_adjuster;
float offset;
int adc_fs;
uint8_t ACS712XX_pin;
ACS712XXType type;
};
#endif /*ACS712XX_h*/