Uses Arch-Pro with Grove base shield, Temperature Sensor and 4 digit LED display. Displays the temperature in Celsius on the Display.

Dependencies:   DigitDisplay mbed

Committer:
djbottrill
Date:
Sat Oct 04 14:04:34 2014 +0000
Revision:
0:e253fc5f8e16
Working Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
djbottrill 0:e253fc5f8e16 1 /* Grove - Temprature Sensor demo v1.0
djbottrill 0:e253fc5f8e16 2 * This sensor detects the enviroment temprature,
djbottrill 0:e253fc5f8e16 3 * Uses a Arch-Pro board with Grove Base Shield
djbottrill 0:e253fc5f8e16 4 * Connect the Grove Temperature sensor to A0 and
djbottrill 0:e253fc5f8e16 5 * connect a Grove 4 digit LED display to the UART connector
djbottrill 0:e253fc5f8e16 6 * The temperature will be displayed in Celcius
djbottrill 0:e253fc5f8e16 7 * Modified by David Bottrill from the original Arduino code
djbottrill 0:e253fc5f8e16 8 * By: http://www.seeedstudio.com
djbottrill 0:e253fc5f8e16 9 */
djbottrill 0:e253fc5f8e16 10
djbottrill 0:e253fc5f8e16 11 #include "mbed.h"
djbottrill 0:e253fc5f8e16 12 #include "DigitDisplay.h"
djbottrill 0:e253fc5f8e16 13
djbottrill 0:e253fc5f8e16 14 DigitalOut myled(LED1);
djbottrill 0:e253fc5f8e16 15
djbottrill 0:e253fc5f8e16 16 DigitDisplay display(P4_29, P4_28);
djbottrill 0:e253fc5f8e16 17 AnalogIn ain(P0_23);
djbottrill 0:e253fc5f8e16 18
djbottrill 0:e253fc5f8e16 19 int a;
djbottrill 0:e253fc5f8e16 20 float temperature;
djbottrill 0:e253fc5f8e16 21 int B=3975; //B value of the thermistor
djbottrill 0:e253fc5f8e16 22 float resistance;
djbottrill 0:e253fc5f8e16 23
djbottrill 0:e253fc5f8e16 24 int main()
djbottrill 0:e253fc5f8e16 25 {
djbottrill 0:e253fc5f8e16 26 while(1) {
djbottrill 0:e253fc5f8e16 27 // multiply ain by 675 if the Grove shield is set to 5V or 1023 if set to 3.3V
djbottrill 0:e253fc5f8e16 28 a=ain*675;
djbottrill 0:e253fc5f8e16 29 resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
djbottrill 0:e253fc5f8e16 30 temperature=1/(log(resistance/10000)/B+1/298.15)-273.15; //convert to temperature via datasheet ;
djbottrill 0:e253fc5f8e16 31 myled = 1;
djbottrill 0:e253fc5f8e16 32 wait(0.5);
djbottrill 0:e253fc5f8e16 33 myled = 0;
djbottrill 0:e253fc5f8e16 34 wait(0.5);
djbottrill 0:e253fc5f8e16 35 display.write(temperature);
djbottrill 0:e253fc5f8e16 36 }
djbottrill 0:e253fc5f8e16 37 }
djbottrill 0:e253fc5f8e16 38
djbottrill 0:e253fc5f8e16 39