forked from OfferZen-Community/plant_tech_ams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransistor_test.ino
83 lines (60 loc) · 2.24 KB
/
transistor_test.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Quick Triode Model Transistor test for NodeMCU and TIP31C
//define new pin names
//NPN transistor pin connecctions
#define Base D0
#define Collector D1
#define Emitter D2
void setup() {
// initialize serial communication at 9600 baud:
Serial.begin(9600);
}
void trans_test_npn (){
// Transistor diode tests a la triode model
// Test diodes in forward bias
pinMode(Base, OUTPUT);
pinMode(Collector, INPUT);
pinMode(Emitter, INPUT);
digitalWrite(Base, HIGH);
bool collector_diode_forward = digitalRead(Collector);
bool emitter_diode_forward = digitalRead(Emitter);
digitalWrite(Base, LOW);
Serial.println("Both diodes should be high for the forward bias diode test (1)");
Serial.print("The collector diode is ");
Serial.println(collector_diode_forward);
Serial.print("The emitter diode is ");
Serial.println(emitter_diode_forward);
if (collector_diode_forward && emitter_diode_forward) {
Serial.println("Forward bias diode test successful");
} else {
Serial.println("Forward bias diode test failed - transistor is faulty");
}
// Test diodes in reverse bias
pinMode(Base, INPUT);
pinMode(Collector, OUTPUT);
pinMode(Emitter, OUTPUT);
digitalWrite(Collector, HIGH);
bool collector_diode_reverse = digitalRead(Base);
digitalWrite(Collector, LOW);
digitalWrite(Emitter, HIGH);
bool emitter_diode_reverse = digitalRead(Base);
Serial.println("Both diodes should be low for the reverse bias diode test (0)");
Serial.print("The collector diode is ");
Serial.println(collector_diode_reverse);
Serial.print("The emitter diode is ");
Serial.println(emitter_diode_reverse);
if (!collector_diode_reverse && !emitter_diode_reverse) {
Serial.println("Reverse bias diode test successful");
} else {
Serial.println("Reverse bias diode test failed - transistor is faulty");
}
if (collector_diode_forward && emitter_diode_forward && !collector_diode_reverse && !emitter_diode_reverse) {
Serial.println("The transistor appears to be working correctly");
} else {
Serial.println("The transistor appears to be faulty");
}
}
void loop(){
trans_test_npn();
Serial.println();
delay(2000);
}