JB's Electronics Club - Project #2

Mission: Run a program that receives a reading from a temperature sensor circuit and displays the temperature in degrees Celsius

How

  1. Build the temperature sensor circuit
  2. Enable the 1-Wire Interface on the Raspberry Pi
  3. Connect the circuit to the Raspberry Pi
  4. Download the W1Thermsensor Package
  5. Construct a temperature sensor program in Python
  6. Run the program and receive a temperature reading

What you will need

  • 3x Male to Female Jumper Cables (Red, Black & Yellow)
  • 1x DS18S20+ Temperature Sensor
  • 1x 4.7K Ohm (4k7) 0.25W Resistor

Part 1: Build the temperature sensor circuit

1. Place the three pins of Sensor DS18S20+, into Columns 1, 2 & 4 of Row G (Make sure the flat part is facing away from the center of the breadboard)

2. Connect the 3.3k Ohm resistor to Columns 2 & 4 of Row L

3. Place the male end of the yellow jumper into Column 2, Row K

4. Place the male end of the red jumper, into Column 4, Row K

5. Place the male end of the black jumper into Column 1, Row L

Part 2: Enable the 1-Wire interface on the Raspberry Pi

1. Open the "Raspberry Pi Configuration" panel

2. Select the "Interfaces" tab and "Enable" the 1-Wire interface

3. Restart the Raspberry Pi

Part 3: Connecting the circuit to the Pi

1. Connect the female end of the black jumper, into the ground pin between GPIO 17 & GPIO 23 (7th pin in from the left)

2. Connect the female end of the red jumper, into the 3.3V Power pin (1st Pin on left)

3. Connect the female end of the yellow jumper into GPIO 4 (4th pin in, two-pin gap from 3.3V Power)

Part 4: Download the W1Thermsensor programming library by Timo Furrer

1. Open the Terminal

2. Enter the following command and then press Enter – sudo pip3 install w1thermsensor

3. After the package has successfully installed, you may close the terminal

Part 5: Construct a temperature sensor program in Python

1. Open the Thonny Python IDE program

2. Type the below code into your code editor and save the program

import time
from w1thermsensor import W1ThermSensor
sensor = W1ThermSensor()

while True:
    temperature = sensor.get_temperature()
    print("The temperature is %s celcius" % temperature)
    time.sleep(1)

3. Click "Run", you should see temperature readings below!

4. Try blowing on the sensor and seeing if the temperature changes!