Thermometer

### Start

Let's put together a thermometer to sense the temperature and hook that up to a display.

### Modules

Gather the following parts to complete this project.

All Parts
All Parts
Temperature
Button
LCD Display
Cable
PartQuantity
Temperature 1
Button 1
LCD Display 1
Cable 3

### Temperature

Take a cable and unwrap it. Plug one side into the temperature sensor socket and the other into Analog socket A0.

All the parts you'll need
All the parts you'll need
Take a cable...
... and unwrap it
Plug one side into the temperature sensor socket
... and the other into Analog socket A0

Upload the code below. This tutorial uses Analog socket A0. If you are using a different socket update the code after copying it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <math.h>

//Change here if you're using a different socket
#define tempSensorSocket A0

int temp;

const int B = 4275; // B value of the thermistor;
const int R0 = 100000; // R0 = 100k;

void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.println(temp);
}


#### Observe

Open up the Serial Monitor and check out the current temperature in Celsius.

#### Modify

Move the temperature sensor around and check out the different temperatures. Try putting it in a hot place and a cold place.

Body temperature will bring it up

#### Experiment

See if you can detect the small changes in temperature within a room. The higher you place the sensor in the room, usually the higher the temperature because heat rises.

### Button

Take a cable and unwrap it. Plug one side into the button and the other into Digital socket D4.

Take a cable...
Take a cable...
... and unwrap it
Plug one side into the button socket
... and the other into Digital socket D4

Upload the code shown below. This tutorial uses Digital socket 4. If you are using a different socket update the code after copying it.

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
#include <math.h>

//If you use different sockets change them below
#define buttonSocket 4
#define tempSensorSocket A0
int temp;
int tempC;

const int B = 4275; // B value of the thermistor;
const int R0 = 100000; // R0 = 100k;

void setup()
{
pinMode(buttonSocket, INPUT);
Serial.begin(9600);
}

void loop()
{
Serial.println((far(tempC)));
} else {
Serial.println(tempC);
}
}

int far(int temp) {
return temp * 1.8 + 32;
}


#### Observe

Open up the Serial Monitor and press the button. Watch the temperature reading change from Celsius to Fahrenheit. With higher temperatures the difference between the two units is larger.

### LCD Display

Take a cable and unwrap it. Plug one side into the LCD Display and the other into any I2C socket.

Take a cable...
Take a cable...
... and unwrap it
Plug one side into the LCD socket
... and the other into any I2C socket

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
#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

void setup()
{
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
}

void loop()
{
lcd.setRGB(colorR, colorG, colorB);
lcd.setCursor(0,0);
lcd.print("This is a");
lcd.setCursor(0,1);
lcd.print("message");
delay(1000);
clearScreen();
lcd.setRGB(colorR, colorG, colorB);
lcd.setCursor(0,0);
lcd.print("So is this");
lcd.setCursor(0,1);
lcd.print("");
delay(1000);
clearScreen();
}

void clearScreen(){
lcd.setCursor(0,0);
lcd.print("                ");
lcd.setCursor(0,1);
lcd.print("                ");
}


#### Observe

Take a look at the two messages.

One of the messages

#### Is The Screen Not Working?

Double check that the switches found on the Seeeduino and base shield are set to 5V and not 3V3.

#### Modify

Change the messages and the delays associated with them.

### All together

By combining all these modules we can achieve our goal of a digital display thermometer.

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
#include <math.h>
#include <Wire.h>
#include "rgb_lcd.h"

//If you use different sockets change them below
#define buttonSocket 4
#define tempSensorSocket A0

int temp;

int tempC;

int far(int temp) {
return temp * 1.8 + 32;
}

const int B = 4275; // B value of the thermistor;
const int R0 = 100000; // R0 = 100k;

rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

void setup()
{
pinMode(buttonSocket, INPUT);
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
}

void loop()
{
tempC = 1.0 / (log(1023.0 / analogRead(tempSensorSocket) - 1.0) / B + 1 / 298.15) - 273.15;
lcd.setRGB(colorR, colorG, colorB);
lcd.setCursor(0, 0);
lcd.print("Temp in C");
lcd.setCursor(0, 1);
lcd.print(tempC);
delay(100);
} else {
lcd.setRGB(colorR, colorG, colorB);
lcd.setCursor(0, 0);
lcd.print("Temp in F");
lcd.setCursor(0, 1);
lcd.print((far(tempC)));
delay(100);
}
}


#### Observe

With the display working you can unplug your thermometer from your computer and bring it anywhere on battery power. Pressing the button still switches the units.

Ambient Temperature in Fahrenheit
Ambient Temperature in Fahrenheit
Ambient Temperature in Celsius
Is it getting hot in here?