Measuring the temperature of liquids

Measuring the temperature of liquids

In this experiment we use an external sensor to measure the temperature of liquids

Easy

30 mins

from 8 years on

The Calliope mini is already equipped with a temperature sensor on the circuit board. To measure the temperature in an aquarium, however, we need an external sensor. For this an analog sensor of the type LM35 can be used.

1background knowledge

Temperature sensors with an analog output signal transmit the measured temperature in the form of a voltage level to the connected microcontroller. This voltage is normalized to a value between 0 and 1024 with relation to the supply voltage of the measuring system. This value can then be converted into a temperature by means of a type-dependent calculation. The temperature sensor LM35 shows an increase of the voltage signal of 10 mV per Kelvin for the temperature range from 0 to 150 °C (or 0 to 100 °C for the LM35DZ). The temperature value in °C is therefore calculated according to the following formula:

In this example, the sensor is supplied with power directly via the Calliope. Therefore the reference voltage is 3.3 V. The offset temperature is used to shift the measured temperatures. In our measuring range of a normal room temperature and a supply voltage of 3.3 V, the measured temperature should be corrected by 3 K downwards.

If higher supply voltages are used, it may be possible to achieve higher accuracy over a larger measuring range. In the data sheet for the LM35, the voltage range is specified as 4 V to 30 V. The LM35 can be supplied with a wide range of voltages. For a 5 V supply, the setup with an external voltage source can be used according to a tutorial on relay switching.

2Hardware

Only a few components are required for the example given. The power supply via the battery pack provides too little voltage for the LM35. Therefore a power supply via the USB port must be guaranteed. For this purpose, it is sufficient to connect the LM35 to a PC, laptop or a power bank which provides 5 V output voltage.

Required components:

  • Temperature sensor LM35 or LM35DZ
  • crocodile clips
  • Micro-USB cable for power supply
3circuit design

The LM35 is supplied in a waterproof version with a connection cable of at least 1 m. The three wires are divided into voltage (red), ground (blue) and signal (white). The colour coding may vary depending on the manufacturer. Voltage and ground are connected to the plus resp. minus contact and the signal is connected to pin 1. In this example, the power supply is provided by a power bank.

4program code

The code sample was created with the Open Roberta Lab popup: yes. However, it can also be implemented with other editors. The program has the task to read the analog value of pin 1 when pressing key A and display the calculated temperature via the LED matrix.

At the beginning, the variables are declared. The constants for the supply voltage, the proportionality factor (here in V/K) and the offset can be adjusted here. In an infinite loop, the value at pin 1 is read after pressing key A and written to the variable temperature after conversion. The value is then displayed via the LED matrix.

By measuring the temperature in liquids, some relationships in thermodynamics can be illustrated. By recording the time, the calculation of heat transfer rates and material properties can be carried out. Do you have further ideas for the use of temperature measurement in liquids? Have you been able to use other external sensors on the Calliope mini using the basic libraries?

This text as well as the images are published under a CC BY-SA 3.0 DE license popup: yes. It was originally published in German by Ingmar Reichert and translated into English by the Calliope team.

YOU CAN FIND THE FINISHED FILES BELOW.

The HEX-File can be used on your Calliope mini directly. The XML-File can be opened with the OpenRoberta editor.

hex xml