2.2 Build your Sensor
On this page:
- Understand how a temperature sensor works
- Develop skills in assembling a temperature sensor
- Develop skills in troubleshooting simple circuits
Time required: 30 minutes
Prerequisite skills: Working with breadboards
Create a Digital Temperature Sensor:
The DS18B20 temperature sensor works by converting a measurement of resistance to a digital signal of temperature. Electricity passes through the sensor from the positive side (V+) to ground (GND). The voltage required to move electricity along this path changes with temperature because the resistance of the sensor also changes with temperature. This voltage is measured and used to calculate the resistance. The resistance is then converted to a temperature measurement. The DS18B20 temperature sensor is known as a “one-wire” sensor, because the temperature value is sent as a digital signal to the microcontroller through the one communication wire (DATA).
In this activity you will build a temperature sensor using the DS18B20. You can do this section without a computer and make a portable sensor, or with a computer which enables you to interact with the sensor more through the use of computer coding. Or you can try it both ways!
Note: For more information on the DS18B20 sensor, check out the sensor datasheet.
Building your DS18B20 digital temperature sensor
- Create a circuit to read a DS18B20 sensor from your microcontroller. Start by connecting the V+ pin (red wire) on the DS18B20 to Pin “9” of the microcontroller using the breadboard.
2. Connect the GND pin (black wire) on the DS18B20 to your microcontroller by first connecting the “GND” pin on the microcontroller to the “(-)” rail on the breadboard using a male-male jumper wire. Then connect the “GND” pin on the DS18B20 to anywhere on the same “(-)” rail on the breadboard.
3. Connect the DATA pin (yellow or green wire) on the DS18B20 to Pin 10 on the microcontroller.
4. Use the 4.7 KΩ resistor to also connect the DATA and V+ wires by connecting the resistor from Pin 9 to Pin 10 (see Figure 2.3 above).
Note: it helps to keep the colors of the jumper wires constant to keep track of your connections. For example, all ground wires should be a black or dark color.
Setting up the LCD Screen and Button
5. The LCD screen uses 4 pins that get connected to the microcontroller. Use male-female jumper wires to make these connections (See Figure 2.5 below):
a. Connect “VCC” on the LCD to the “(+)” rail on the breadboard.
b. Connect “GND” on the LCD to “GND” on the microcontroller
c. Connect “SDA” on the LCD to “SDA” on the microcontroller
d. Connect “SCL” on the LCD to “SCL” on the microcontroller
6. Connect “3.3V” on the microcontroller to the “(+)” rail on the breadboard using a male-male jumper wire. This will power the LCD.
7. Connect your button. Connect one side of the button to the “(+)” rail on the breadboard using a jumper. Connect the other side of the button to Pin “A4” on your microcontroller using a second jumper.
8. Before connecting the microcontroller to the battery, double check all of your connections to make sure it matches the diagram above (Figure 2.5).
9. Insert the battery into the battery holder so that the positive side, indicated by the “+” symbol, is on the side of the holder with the red wire, and the negative side of the battery is on the side of the holder with the black wire.
10. Connect the black wire from the battery holder to the “GND” pin on the microcontroller. You can also do this by connecting the black wire from the battery holder to the “(-)” rail that the microcontroller “GND” pin is also connected to.
11. Connect the red wire from the battery holder to the pin labeled “BAT” on the microcontroller (see Figure 2.6 below). Once the battery is connected, the LCD should light up and display “Hello!”. For instructions on charging the battery, see the Charging the Battery page.
10. You can start taking measurements once the LCD display changes and displays “Ready!” after 5-10 seconds. To take a single temperature measurement, press the button once. A temperature measurement in degrees Celsius will appear on the first line of the LCD screen.
11. To stop powering the instrument, remove the red battery wire from the “BAT” connection. To try using it with a computer, remove the battery connections and follow the directions below.