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 is easy to explain. The
analogRead()
portion ensures that the voltage is repeatedly read at the
sensorPin
. The measurement reading is then output
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
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);
}
</>
THE PROGRAM
Now, write the following code and upload it to the controller:
◀
Board with temperature sensor
33
CodeGamer
PROJECT 8
CodeGamer manual inside english.indd 33
7/19/16 12:32 PM