Irayya Mathad
/
Temp36GZ_sensor
Testing Temperature sensors
main.cpp@0:1b2c834b3e7a, 2017-05-25 (annotated)
- Committer:
- irayya
- Date:
- Thu May 25 06:04:57 2017 +0000
- Revision:
- 0:1b2c834b3e7a
Temperature sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
irayya | 0:1b2c834b3e7a | 1 | #include "mbed.h" |
irayya | 0:1b2c834b3e7a | 2 | |
irayya | 0:1b2c834b3e7a | 3 | |
irayya | 0:1b2c834b3e7a | 4 | AnalogIn temp(A1); |
irayya | 0:1b2c834b3e7a | 5 | Serial pc(USBTX,USBRX); |
irayya | 0:1b2c834b3e7a | 6 | DigitalOut LED(D0); |
irayya | 0:1b2c834b3e7a | 7 | |
irayya | 0:1b2c834b3e7a | 8 | int main() |
irayya | 0:1b2c834b3e7a | 9 | { |
irayya | 0:1b2c834b3e7a | 10 | float tempC, tempF; |
irayya | 0:1b2c834b3e7a | 11 | |
irayya | 0:1b2c834b3e7a | 12 | while(1) { |
irayya | 0:1b2c834b3e7a | 13 | //conversion to degrees C - from sensor output voltage |
irayya | 0:1b2c834b3e7a | 14 | float tempout=temp.read(); |
irayya | 0:1b2c834b3e7a | 15 | pc.printf("analog value of temperature sensor is %f: ",tempout); |
irayya | 0:1b2c834b3e7a | 16 | |
irayya | 0:1b2c834b3e7a | 17 | tempC = ((tempout*3.3)-0.600)*100.0; |
irayya | 0:1b2c834b3e7a | 18 | //convert to degrees F |
irayya | 0:1b2c834b3e7a | 19 | tempF = (9.0*tempC)/5.0 + 32.0; |
irayya | 0:1b2c834b3e7a | 20 | //print the temp |
irayya | 0:1b2c834b3e7a | 21 | printf("%5.2F C %5.2F F \n\r", tempC, tempF); |
irayya | 0:1b2c834b3e7a | 22 | wait(0.5); |
irayya | 0:1b2c834b3e7a | 23 | |
irayya | 0:1b2c834b3e7a | 24 | if(tempC>35.30) |
irayya | 0:1b2c834b3e7a | 25 | { |
irayya | 0:1b2c834b3e7a | 26 | LED=1; |
irayya | 0:1b2c834b3e7a | 27 | wait(1); |
irayya | 0:1b2c834b3e7a | 28 | LED=0; |
irayya | 0:1b2c834b3e7a | 29 | } |
irayya | 0:1b2c834b3e7a | 30 | else |
irayya | 0:1b2c834b3e7a | 31 | LED=0; |
irayya | 0:1b2c834b3e7a | 32 | } |
irayya | 0:1b2c834b3e7a | 33 | } |