-
Notifications
You must be signed in to change notification settings - Fork 1
/
MIDTERM-PROJECT.ino
67 lines (67 loc) · 1.86 KB
/
MIDTERM-PROJECT.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
67
const int sensorPin1 = A0;
const int sensorPin2 = A1;
const int sensorPin3 = A2;
int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;
float Vin = 5;
float Vout1 = 0;
float Vout2 = 0;
float Vout3 = 0;
float Rref1 = 1000;
float Rref2 = 1000;
float Rref3 = 910;
float r1 = 0;
float r2 = 0;
float r3 = 0;
float ra=0,rb=0,rc=0;
void setup ()
{
Serial.begin(9600); // Initialize serial communications at 9600 bps
}
void getR1(){
sensorValue1 = analogRead(sensorPin1);
Vout1 = (Vin * sensorValue1) / 1024;
ra = Rref1 * (1 / ((Vin / Vout1) - 1));
Serial.print("Resistor 1: ");
Serial.println(ra);
delay(1000);
}
void getR2(){
sensorValue2 = analogRead(sensorPin2);
Vout2 = (Vin * sensorValue2) / 1023;
rb = Rref2 * (1 / ((Vin / Vout2) - 1));
Serial.print("Resistor 2: ");
Serial.println(rb); // Give calculated resistance in Serial Monitor
delay(1000);
}
void getR3(){
sensorValue3 = analogRead(sensorPin3);
Vout3 = (Vin * sensorValue3) / 1023;
rc = Rref3 * (1 / ((Vin / Vout3) - 1));
Serial.print("Resistor 3: ");
Serial.println(rc); // Give calculated resistance in Serial Monitor
delay(1000);
}
void loop ()
{
Serial.println("------------------------------------------");
Serial.println("Y to Delta");
Serial.println("Reading Resistors. . . . ");
getR1();
getR2();
getR3();
Serial.println("Computing.....");
delay(2000);
r1=((ra*rb)+(rb*rc)+(rc*ra))/ra;
r2=((ra*rb)+(rb*rc)+(rc*ra))/rb;
r3=((ra*rb)+(rb*rc)+(rc*ra))/rc;
Serial.print("Resistor A:");
Serial.println(r1);
Serial.print("Resistor B:");
Serial.println(r2);
Serial.print("Resistor C:");
Serial.println(r3);
Serial.println("------------------------------------------");
delay(2000);
}