Project 8: Thermometer - Thames & Kosmos Code Gamer Experiment Manual

Coding workshop ? game with kosmobits
Table of Contents

Advertisement

PROJECT 8
Thermometer
YOU WILL NEED
› KosmoDuino in the interaction board
› Temperature sensor
PREPARATION
Mount the temperature sensor on the interaction board.
THE PLAN
In this project, you will be turning your KosmoDuino into a
thermometer for measuring the temperature with the help
of the temperature sensor. The temperature is output via
the serial monitor.
THE PROGRAM
Now, write the following code and upload it to the controller:
The program is easy to explain. The
portion ensures that the voltage is repeatedly read at the
. The measurement reading is then output
sensorPin
through the serial monitor. You will be using this program
whenever you want to learn about a new sensor.
So open the serial monitor and take a look at the
measurement readings. Place your finger on the black dot
sticking up out of the sensor housing. You should see the
measurement readings change. It won't yet look like a
temperature reading, though. You still have to convert the
measurement readings into temperatures. The KosmoBits
library can help you with that. It includes a function for
that very task, called
thermistor_measurement_in_celsius()
To use this function, you will first have to link the
KosmoBits_Thermistor.h
CodeGamer manual inside english.indd 33
analogRead()
.
file.
#include <KosmoBits_Pins.h>
const int sensorPin = KOSMOBITS_SENSOR_PIN;
void setup() {
pinMode(sensorPin, INPUT);
Serial.begin(115200);
}
void loop() {
int value = analogRead(sensorPin);
Serial.print("measurementReading: ");
Serial.println(value);
delay(1000);
}
◀ Board with temperature sensor
CodeGamer
</>
33
7/19/16 12:32 PM

Advertisement

Table of Contents
loading

Table of Contents