-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurrentsensor.ino
49 lines (40 loc) · 1.3 KB
/
Currentsensor.ino
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
#define CURRENT_PIN 34
#define SENSITIVITY 0.045
float setup_sensor(){
pinMode(CURRENT_PIN, INPUT);
analogReadResolution(12);
delay(1000);
zeroValue = 0;
// Read current sensor when there is no load
for(int i=0; i<500;i++){
sensorValue = analogRead(CURRENT_PIN);
Serial.print("Analog reading:");
Serial.println(sensorValue);
zeroValue = (sensorValue *(3.27/4095)) + (zeroValue);
delay(2);
}
zeroValue = zeroValue /500;
Serial.println("**************************************");
Serial.print("Zero Value when no Load condition =: ");
Serial.println(zeroValue);
return zeroValue;
}
float read_sensor(float zeroValue){
double sumValue = 0.0;
// capturing sensor voltage rms and current
for(int i=0; i<1000;i++){
sensorValue = analogRead(CURRENT_PIN);
outputValue = (sensorValue *(3.27/4095)) - ( zeroValue);
sumValue = (outputValue * outputValue) + (sumValue);
delay(2);
}
sumValue = (sumValue / 1000);
sumValue = sqrt(sumValue);
outputValue = sumValue /SENSITIVITY;
Serial.print("Processed Sensor Voltage Value in Volts =: ");
Serial.println(sumValue);
Serial.print("Current Value in Amp =: ");
Serial.println(outputValue);
Serial.println("____________________________________");
return outputValue;
}