Here is the ambient temperature sensor component on the air quality sensor board included with the Raspberry Pi Weather Station. The component is circled in red.
This sensor detects both the ambient temperature and the relative humidity of the air surrounding it. We will explore the humidity part of the sensor further in the lesson on relative humidity.
These types of sensor detect changes in temperature and humidity in two possible ways, depending on how they are built.
Capacitive sensing - The sensor uses a material which absorbs water from the air. The sensor's capacitance (ability to store an electric charge) changes depending on how much water vapour the air contains, and this can be measured and converted into meaningful units.
Resistive sensing - The sensor uses a material which has the property that its resistance (how easy it is for a current to pass through it) changes depending on the humidity of the surrounding air, and this value is measured and converted into meaningful units.
Relative humidity is directly related to the ambient temperature; it's for this reason that we can access both temperature and relative humidity data from the same sensor. Relative humidity is defined as the amount of water vapour present in the air, as a percentage of the amount of water vapour needed for saturation at that temperature.
For example, at 20 degrees C, the saturated vapour density is 17.3g/m3.
This web page has details on relative humidity which may be interesting further reading, as well as the data sheet for the ambient temperature sensor.
- First, set up your main Raspberry Pi Weather Station box.
- The ambient temperature and relative humidity sensor is a component on the air quality sensor board. Connect this board to the main Weather Station with the cable to the port labelled "Air Sensor".
- Power on your Weather Station and log in.
The following program initialises a HTU21D object to interact with the sensor and takes a single reading of the current ambient temperature. It's important that this code is saved inside the weather_station
folder on the Raspberry Pi Weather Station, as it requires access to the HTU21D library code which is saved within this folder.
import HTU21D as temp_humid
ambient_temp = temp_humid.HTU21D()
current_temp = ambient_temp.read_temperature()
print( str(current_temp) + " degrees Celsius")