-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduinoUNO code
155 lines (129 loc) · 4.43 KB
/
ArduinoUNO code
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
double Voltage = 0;
double Current = 0;
double Voltage_2 = 0;
double Current_2 = 0;
double Voltage_3 = 0;
double Current_3 = 0;
String str;
int buzzer = 4;
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(buzzer, HIGH);
delay(500);
digitalWrite(buzzer, LOW);
delay(50);
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
delay(50);
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(10);
Serial.begin(9600); // initialize serial
}
void loop()
{ current_1 ();
current_2 ();
current_3 ();
Send_to_NodeMCU ();
}
void current_1 ()
{
// Voltage is Sensed 1000 Times for precision
for (int i = 0; i < 1000; i++) {
Voltage = (Voltage + (.0049 * analogRead(A1))); // (5 V / 1024 (Analog) = 0.0049) which converter Measured analog input voltage to 5 V Range
//delay(1);
}
Voltage = Voltage / 1000;
Current = (Voltage - 2.46) / 0.185; // Sensed voltage is converter to current
if (Current > 0)
{ // Serial.println("not Fault");
digitalWrite(5, LOW);
// Send_to_NodeMCU_1 ();
}
else if (Current < 0)
{ //Serial.println("Fault");
digitalWrite(5, HIGH);
}
// Serial.print("\n Voltage Sensed (V) = "); // shows the measured voltage
// Serial.print(Voltage, 2); // the '2' after voltage allows you to display 2 digits after decimal point
// Serial.print("\t Current (A) = "); // shows the voltage measured
// Serial.print(Current, 2); // the '2' after voltage allows you to display 2 digits after decimal point
}
void current_2 ()
{
// Voltage is Sensed 1000 Times for precision
for (int i = 0; i < 1000; i++) {
Voltage_2 = (Voltage_2 + (.0049 * analogRead(A2))); // (5 V / 1024 (Analog) = 0.0049) which converter Measured analog input voltage to 5 V Range
// delay(1);
}
Voltage_2 = Voltage_2 / 1000;
Current_2 = (Voltage_2 - 2.43) / 0.185; // Sensed voltage is converter to current
Current_2 = Current_2 + 0.2;
if (Current_2 > 0)
{ //Serial.println("not Fault_2");
digitalWrite(7, LOW);
// Send_to_NodeMCU_2 ();
}
else if (Current_2 < 0)
{ //Serial.println("Fault_2");
digitalWrite(7, HIGH);
}
// // Serial.print("\n Voltage Sensed_2 (V) = "); // shows the measured voltage
// // Serial.print(Voltage_2, 2); // the '2' after voltage allows you to display 2 digits after decimal point
// // Serial.print("\t Current_2 (A) = "); // shows the voltage measured
// // Serial.print(Current_2, 2); // the '2' after voltage allows you to display 2 digits after decimal point
// // delay(1000);
}
void current_3 () {
// Voltage is Sensed 1000 Times for precision
for (int i = 0; i < 1000; i++) {
Voltage_3 = (Voltage_3 + (.0049 * analogRead(A3))); // (5 V / 1024 (Analog) = 0.0049) which converter Measured analog input voltage to 5 V Range
// delay(1);
}
Voltage_3 = Voltage_3 / 1000;
Current_3 = (Voltage_3 - 2.48) / 0.185; // Sensed voltage is converter to current
Current_3 = Current_3 + 0.4;
if (Current_3 > 0)
{ //Serial.println("not Fault_3");
digitalWrite(6, LOW);
// Send_to_NodeMCU_3 ();
}
else if (Current_3 < 0)
{ //Serial.println("Fault_3");
digitalWrite(6, HIGH);
}
// // Serial.print("\n Voltage Sensed_3 (V) = "); // shows the measured voltage
// // Serial.print(Voltage_3, 2); // the '2' after voltage allows you to display 2 digits after decimal point
// // Serial.print("\t Current_3 (A) = "); // shows the voltage measured
// // Serial.print(Current_3, 2); // the '2' after voltage allows you to display 2 digits after decimal point
// // delay(1000);
}
void Send_to_NodeMCU ()
{ str = str + Current + "," + Current_2 + "," + Current_3 + ",";
Serial.println(str);
delay(1000);
str = "";
}
//void Send_to_NodeMCU_1 ()
//{ str = str + Current;
// Serial.println("");
// Serial.println(str);
// str = "";
//}
//void Send_to_NodeMCU_2 ()
//{ str = str + Current_2;
// Serial.println("");
// Serial.println(str);
// str = "";
//}
//void Send_to_NodeMCU_3 ()
//{ str = str + Current_3;
// Serial.println("");
// Serial.println(str);
// str = "";
//}