Termometro digitale con Arduino
In questi primi tempi di caldo ho realizzato questo progetto: Misuratore di temperatura digitale con LM35. La connessione รจ abbastanza semplice seppure ci sono molti cavetti da interconnettere. Si fornisce il codice in ingresso ai 2 decoder TTL 74LS48 e si inviano sui display a 7 segmenti. Di seguito il codice pronto all’uso
Componenti:
– LM35C o LM35D – sensore di temperatura
– 2 decoder 74LS48
– 2 display a sette segmenti
si pone il sensore all’ingresso A0 di Arduino
Dovete connettere le uscite di arduino digitali da 1 a 4 al primo decoder e da 8 a 11 per l’altro
int A=1;
int B=2;
int C=3;
int D=4;
int E=8;
int F=9;
int G=10;
int H=11;
void zero(int aa, int bb, int cc, int dd) {
digitalWrite(aa, LOW);
digitalWrite(bb, LOW);
digitalWrite(cc, LOW);
digitalWrite(dd, LOW);
}
void uno(int aa, int bb, int cc, int dd) {
digitalWrite(aa, HIGH);
digitalWrite(bb, LOW);
digitalWrite(cc, LOW);
digitalWrite(dd, LOW);
}
void due(int aa, int bb, int cc, int dd) {
digitalWrite(aa, LOW);
digitalWrite(bb, HIGH);
digitalWrite(cc, LOW);
digitalWrite(dd, LOW);
}
void tre(int aa, int bb, int cc, int dd) {
digitalWrite(aa, HIGH);
digitalWrite(bb, HIGH);
digitalWrite(cc, LOW);
digitalWrite(dd, LOW);
}
void quattro(int aa, int bb, int cc, int dd) {
digitalWrite(aa, LOW);
digitalWrite(bb, LOW);
digitalWrite(cc, HIGH);
digitalWrite(dd, LOW);
}
void cinque(int aa, int bb, int cc, int dd) {
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
}
void seii(int aa, int bb, int cc, int dd) {
digitalWrite(aa, LOW);
digitalWrite(bb, HIGH);
digitalWrite(cc, HIGH);
digitalWrite(dd, LOW);
}
void sette(int aa, int bb, int cc, int dd) {
digitalWrite(aa, HIGH);
digitalWrite(bb, HIGH);
digitalWrite(cc, HIGH);
digitalWrite(dd, LOW);
}
void otto(int aa, int bb, int cc, int dd) {
digitalWrite(aa, LOW);
digitalWrite(bb, LOW);
digitalWrite(cc, LOW);
digitalWrite(dd, HIGH);
}
void nove(int aa, int bb, int cc, int dd) {
digitalWrite(aa, HIGH);
digitalWrite(bb, LOW);
digitalWrite(cc, LOW);
digitalWrite(dd, HIGH);
}
int PIN_ST = A0;
float valst;
float v;
float T;
int Tu;
String STu;
//String sval1;
//String sval2;
char sval1;
char sval2;
int val1;
int val2;
void setup() {
// put your setup code here, to run once:
pinMode(PIN_ST, INPUT);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
pinMode(H, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
valst = analogRead(PIN_ST);
v = (valst*5)/1024;
T = v/0.01;
Tu = (int) T;
String STu = String(Tu);
sval1 = STu.charAt(0);
sval2 = STu.charAt(1);
switch(sval1){
case ‘0’:
zero(A, B, C, D);
break;
case ‘1’:
uno(A, B, C, D);
break;
case ‘2’:
due(A, B, C, D);
break;
case ‘3’:
tre(A, B, C, D);
break;
case ‘4’:
quattro(A, B, C, D);
break;
case ‘5’:
cinque(A, B, C, D);
break;
case ‘6’:
seii(A, B, C, D);
break;
case ‘7’:
sette(A, B, C, D);
break;
case ‘8’:
otto(A, B, C, D);
break;
case ‘9’:
nove(A, B, C, D);
break;
}
switch(sval2){
case ‘0’:
zero(E, F, G, H);
break;
case ‘1’:
uno(E, F, G, H);
break;
case ‘2’:
due(E, F, G, H);
break;
case ‘3’:
tre(E, F, G, H);
break;
case ‘4’:
quattro(E, F, G, H);
break;
case ‘5’:
cinque(E, F, G, H);
break;
case ‘6’:
seii(E, F, G, H);
break;
case ‘7’:
sette(E, F, G, H);
break;
case ‘8’:
otto(E, F, G, H);
break;
case ‘9’:
nove(E, F, G, H);
break;
}
delay(1000);
}