-
Notifications
You must be signed in to change notification settings - Fork 5
/
spem.ino
66 lines (55 loc) · 2.05 KB
/
spem.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//----------------------------------------------
//--- Author : Ahmet Ozlu
//--- Mail : [email protected]
//--- Date : 26th October 2017
//----------------------------------------------
/*declaration of variables*/
int sensorValue;
int sensorValue2;
float voltage;
float voltage2;
float p1;
float p2;
float p3;
float p4;
float meanPower;
void setup() {
Serial.begin(9600);
}
void loop() {
/*FIRST MEASUREMENT*/
sensorValue = analogRead(A0); /* Voltage difference of A0 */
voltage = ((float)5/1023)*sensorValue;
sensorValue2 = analogRead(A1); /* Voltage difference of A1 */
voltage2 = ((float)5/1023)*sensorValue2;
/*5 volt = 1023 and sensorValue2 was multiplied with this fraction to get voltage value*/
p1=((voltage-voltage2)*15)*voltage2;
delay(25);
/*SECOND MEASUREMENT*/
sensorValue = analogRead(A0); /* Voltage difference of A0 */
voltage = ((float)5/1023)*sensorValue;
sensorValue2 = analogRead(A1); /* Voltage difference of A1 */
voltage2 = ((float)5/1023)*sensorValue2;
/*5 volt = 1023 and sensorValue2 was multiplied with this fraction to get voltage value*/
p2=((voltage-voltage2)*15)*voltage2;
delay(25);
/*THIRD MEASUREMENT*/
sensorValue = analogRead(A0); /* Voltage difference of A0 */
voltage = ((float)5/1023)*sensorValue;
sensorValue2 = analogRead(A1); /* Voltage difference of A1 */
voltage2 = ((float)5/1023)*sensorValue2;
/*5 volt = 1023 and sensorValue2 was multiplied with this fraction to get voltage value*/
delay(25);
/*FOURTH MEASUREMENT*/
sensorValue = analogRead(A0); /* Voltage difference of A0 */
voltage = ((float)5/1023)*sensorValue;
sensorValue2 = analogRead(A1); /* Voltage difference of A1 */
voltage2 = ((float)5/1023)*sensorValue2;
/*5 volt = 1023 and sensorValue2 was multiplied with this fraction to get voltage value*/
p4=((voltage-voltage2)*15)*voltage2;
delay(25);
/*AVERAGE MEASUREMENT*/
meanPower=(p1+p2+p3+p4)/4;
Serial.print(meanPower);/* Sent voltage value to the computer via serial communication */
Serial.println("");
}