A sensor LM35 give a analog voltage to the AD converter. This information will be send to the COM for the Bluetooth Modul and to the PC for visualisation with profilab

Dependencies:   mbed

Desktop Smartphone with Keuwl Software:

/media/uploads/schlaumaier54/keuwltemp2.jpg

Profilab program area:

/media/uploads/schlaumaier54/profilabtemplm35schaltung.jpg

Profilab Visualisation:

/media/uploads/schlaumaier54/profilagtemplm35frontplatte.jpg

Neumaier Feb 2018

Committer:
schlaumaier54
Date:
Tue Feb 06 17:18:47 2018 +0000
Revision:
0:bc0b037a2781
Sensor LM35 give a analog voltage. This value goes via COM to a bluetooth modul HC06. Also we send the value to the PC for visualisation with Profilab

Who changed what in which revision?

UserRevisionLine numberNew contents of line
schlaumaier54 0:bc0b037a2781 1
schlaumaier54 0:bc0b037a2781 2 /*
schlaumaier54 0:bc0b037a2781 3 LM35 und Bluetooth
schlaumaier54 0:bc0b037a2781 4 Beispiel zur Temperaturmessung mit LM35 und Bluetooth
schlaumaier54 0:bc0b037a2781 5 Für die serielle Kommunikation mit Bluetooth werden die
schlaumaier54 0:bc0b037a2781 6 pins PC_10 und PC_11 benutzt. Dort das Bluetooth Modul HC06 einstecken
schlaumaier54 0:bc0b037a2781 7 TxD und RxD werden gedreht. Das Modul erhält +5V als VCC. RxD und TxD
schlaumaier54 0:bc0b037a2781 8 direkt anschliessen -> 3,3V bis 5V tolerant.
schlaumaier54 0:bc0b037a2781 9 Über die USB Verbindung wird eine virtuelle COM zum PC aufgebaut, 9600Baud
schlaumaier54 0:bc0b037a2781 10 Diese Verbindung wird für Profilab benutzt.
schlaumaier54 0:bc0b037a2781 11 G. Neumaier J.Schnaiter Gewerblich-Technische Schule Offenburg Jan2018
schlaumaier54 0:bc0b037a2781 12 ===========================================================
schlaumaier54 0:bc0b037a2781 13 */
schlaumaier54 0:bc0b037a2781 14 // 04u_ADC-Bluetooth
schlaumaier54 0:bc0b037a2781 15 #include "mbed.h"
schlaumaier54 0:bc0b037a2781 16 #define ANZAHL 10
schlaumaier54 0:bc0b037a2781 17
schlaumaier54 0:bc0b037a2781 18 Serial pc(SERIAL_TX, SERIAL_RX);
schlaumaier54 0:bc0b037a2781 19 Serial blue(PC_10, PC_11); // TX,RX
schlaumaier54 0:bc0b037a2781 20 AnalogIn lm35(A0);
schlaumaier54 0:bc0b037a2781 21
schlaumaier54 0:bc0b037a2781 22 int main()
schlaumaier54 0:bc0b037a2781 23 {
schlaumaier54 0:bc0b037a2781 24
schlaumaier54 0:bc0b037a2781 25 float tempC,a[ANZAHL],avg;
schlaumaier54 0:bc0b037a2781 26 int tempBlue;
schlaumaier54 0:bc0b037a2781 27 while(1) {
schlaumaier54 0:bc0b037a2781 28 for(int i=0; i<ANZAHL; i++) {
schlaumaier54 0:bc0b037a2781 29 // gemessen wird zwischen 0 und 1
schlaumaier54 0:bc0b037a2781 30 a[i]=lm35.read();
schlaumaier54 0:bc0b037a2781 31 wait(.02);
schlaumaier54 0:bc0b037a2781 32 }
schlaumaier54 0:bc0b037a2781 33 avg=0;
schlaumaier54 0:bc0b037a2781 34 for(int i=0; i<ANZAHL; i++) {
schlaumaier54 0:bc0b037a2781 35 avg=avg+a[i];
schlaumaier54 0:bc0b037a2781 36 }
schlaumaier54 0:bc0b037a2781 37 avg=avg/ANZAHL;
schlaumaier54 0:bc0b037a2781 38
schlaumaier54 0:bc0b037a2781 39 // lm35 liefert 10mV pro °C
schlaumaier54 0:bc0b037a2781 40 // 20mV -> 20°C
schlaumaier54 0:bc0b037a2781 41 tempC=(avg*3.3*100.0); // 3,3V sowie 10mV * 100
schlaumaier54 0:bc0b037a2781 42 //AD-Wandler liefert 0.000 ...1.000 (3,3V)
schlaumaier54 0:bc0b037a2781 43 //max Werte: 0,000 bis 333.000
schlaumaier54 0:bc0b037a2781 44 //pc.printf("%1.3f\n",tempC);
schlaumaier54 0:bc0b037a2781 45 tempBlue = (int) tempC;
schlaumaier54 0:bc0b037a2781 46
schlaumaier54 0:bc0b037a2781 47
schlaumaier54 0:bc0b037a2781 48 // Keuwl kann nur positive Werte 0 ...255 0=0Grad; 20=0Grad 80= 80Grad
schlaumaier54 0:bc0b037a2781 49 blue.printf("*T%d",tempBlue);
schlaumaier54 0:bc0b037a2781 50
schlaumaier54 0:bc0b037a2781 51 //An PC mit Profilab
schlaumaier54 0:bc0b037a2781 52 pc.printf("%1.3f",tempC); //%1.3f eine Stelle vor dem Komma 3 Stellen danach float Variable
schlaumaier54 0:bc0b037a2781 53 pc.putc(10); //10 =0x0A Steuerzeichen neue Zeile
schlaumaier54 0:bc0b037a2781 54 pc.printf("%u",150); //u ist unsigned integer Dummy könnte für Ausgabe 8 bit (z.B. 8pins) benutzt werden
schlaumaier54 0:bc0b037a2781 55 pc.putc(10); //10 =0x0A Steuerzeichen neue Zeile
schlaumaier54 0:bc0b037a2781 56 pc.putc(13);//13 =0x0D Steuerzeichen Wagenruecklauf (an Anfang der Zeile)
schlaumaier54 0:bc0b037a2781 57
schlaumaier54 0:bc0b037a2781 58 wait_ms(500); //500msec
schlaumaier54 0:bc0b037a2781 59 //wait(1); //1sec
schlaumaier54 0:bc0b037a2781 60 }
schlaumaier54 0:bc0b037a2781 61 }
schlaumaier54 0:bc0b037a2781 62
schlaumaier54 0:bc0b037a2781 63