Hallo,
ich wurde gerne mit einem SCT013 und einem ADS1115 den AC Strom messen.
Habe dazu auch schon einen Code dafür aber leider kann ich mit dem nicht
messen ob strom bezogen oder eingespeist wird nun ist die frage ob mann
das ändern kann.
1 | #include <Arduino.h>
|
2 | #include <Wire.h>
|
3 | #include <Adafruit_ADS1X15.h>
|
4 | #include <SPI.h>
|
5 |
|
6 | Adafruit_ADS1115 ads;
|
7 |
|
8 | const float FACTOR = 5; //5A/1V from teh CT
|
9 |
|
10 | const float multiplier = 0.00005;
|
11 |
|
12 | float getcurrent()
|
13 | {
|
14 | float voltage;
|
15 | float current;
|
16 | float sum = 0;
|
17 | long time_check = millis();
|
18 | int counter = 0;
|
19 |
|
20 | while (millis() - time_check < 1000)
|
21 | {
|
22 | voltage = ads.readADC_Differential_0_1() * multiplier;
|
23 | current = voltage * FACTOR;
|
24 | //current /= 1000.0;
|
25 |
|
26 | sum += sq(current);
|
27 | counter = counter + 1;
|
28 | }
|
29 |
|
30 | current = sqrt(sum / counter);
|
31 | return (current);
|
32 | }
|
33 |
|
34 | void setup() {
|
35 | Serial.begin(9600);
|
36 |
|
37 | ads.setGain(GAIN_FOUR); // +/- 1.024V 1bit = 0.5mV
|
38 | ads.begin();
|
39 |
|
40 | }
|
41 |
|
42 | void printMeasure(String prefix, float value, String postfix)
|
43 | {
|
44 | Serial.print(prefix);
|
45 | Serial.print(value, 3);
|
46 | Serial.println(postfix);
|
47 | }
|
48 |
|
49 | void loop() {
|
50 | float currentRMS = getcurrent();
|
51 | printMeasure("Irms: ", currentRMS, "A");
|
52 | delay(1000);
|
53 |
|
54 | }
|
Danke schon mal für die Hilfe
Grüße Johannes