ENGDUINO LIBRARIES: THE THERMISTOR
The thermistor is a very simple device that changes its resistance (think Physics lessons and Ohms
law) depending on how warm it is. This means we can use it to measure temperature.
- HEADER
At the top of your program you must have the following line.
#include <EngduinoThermistor.h>
- SETUP()
In the setup() function, you must have the following line.
EngduinoThermistor.begin();
- BASIC FUNCTIONS
There is only one function for the thermistor – to get the temperature, which comes back in degrees
Celsius by default. But let’s introduce another idea too – serial output, so you can read a numerical
the value on the screen.
void loop() {
float f;
f = EngduinoThermistor.temperature();
Serial.println(f);
delay(1000);
}
This program reads the temperature and then prints a value out that you can read on the screen. It
does this over the USB cable, so it isn’t going to do anything if that isn’t connected. Upload the
program and then click on the button in the top right hand corner of the screen that looks like:
It should say ‘Serial Monitor’ next to it when you move the mouse pointer over it.
This will bring up another window and you will see that a temperature value appears every second.
The thermistor is a tiny component at the top of the E with NTC written next to it in white (look up the Engduino diagram if still unsure). Rub one of your fingers, cover the thermistor and you should see the temperature rise.
- MORE ADVANCED FUNCTIONS
It is possible to specify the temperature scale you wish to use:
float fc = EngduinoThermistor.temperature(CELSIUS);
float fk = EngduinoThermistor.temperature(KELVIN);
float ff = EngduinoThermistor.temperature(FAHRENHEIT);
It is also worth saying a bit more about the printing to the screen.
void loop() {
Serial.println("Hello World");
delay(1000);
}
Will print “Hello World” all on one line, delay a second and print it again on a new line. But what if
we want to print several things on the same line? Try the following:
void loop() {
float f;
f = EngduinoThermistor.temperature();
Serial.print("Temperature is: ");
Serial.print(f);
Serial.println(" Celsius");
delay(1000);
}
This should print “Temperature is 25.71 Celsius” (or whatever your temperature is). Using
Serial.print doesn’t move the output on to the next line – so we’ve used this for the first two
parts of the line, and then we used Serial.println finally to end the line.
Note that you can only start the Serial Monitor after you have uploaded your program. So you might
miss some of what it prints.
Having learnt how to program the LEDs, see if you can make the LEDs change colour as temperature changes! Remember to add in the 'includes' for the LED part.