2. In this, I will cover a small raspberry project to read the room temperature using
Raspberry Pi 3 and DS18BB20 temperature sensor. This is the very basic
application for Raspberry and easy.
Just follow the instructions to build this project.
Have Fun !
12. 3 cables in the DS18B20 Digital Temperature
Sensor
• The black color is for ground
It will be connected to ground in raspberry
• The yellow color is the data input supply
it will be connected to GPIO4 in raspberry
• The red color is +5v signal
it will be connected to 3V3 in raspberry
13. 4.7k resistor
• 4.7k resistor, which is required as a pullup
from the DATA to VCC line when using the
sensor.
• Connect the 4.7K resistor between the
digital input pin and +5 volts (yellow and
red)
15. Red jumper wire
Red jumper wire
Connected to 3v3 pin in raspberry.
Connected to 4.7k resistor pin
Connected to 3 – 5.5v red color wire in DS18B20 temperature sensor.
16. Yellow jumper wire
Yellow jumper wire
Connected to GPIO4 pin in raspberry.
Connected to 4.7k resistor pin
Connected to data input yellow color wire in DS18B20 temperature sensor.
17. Black jumper wire
Yellow jumper wire
Connected to GND (Ground) pin in raspberry.
Connected to ground black color wire in DS18B20 temperature sensor.
18.
19.
20. Set up pi configuration to read sensor
This is the important step where you need to add configuration in the
raspberry pi so it will start reading your sensor after booting raspberry.
Follow the steps:
1. Login to your pi with user id and password.
2. Connect to terminal if you are not using putty to connect raspberry
console window.
3. Type the command – sudo nano /boot/config.txt
4. Go to end of the file, add the entry as:
dtoverlay = w1-gpio
22. Reboot your raspberry pi
Use your favourite option to reboot your raspberry pi.
• You can do it through the command: sudo reboot
• Or you can click on application menu > click on Shutdown > choose
the option reboot.
23. Find sensor in raspberry
Now this is the time you need to check your raspberry pi. To check,
Login to raspberry, go to terminal window, use below commands to
load the correct module:
sudo modprobe w1-gpio
sudo modprobe w1-therm
Change the directory using command: cd /sys/bus/w1/devices
See the files/directories under devices directory using command ls
Now you should be able to see a directory starting with 28- for example,
28-80000003c64d for my sensor.
24. Folder displayed for your sensor
Directory for the sensor
File, which captures the sensor.
use cat w1_slave and see the output
25. You don’t see the folder for your sensor?
Don’t panic. Mostly this is due to your incorrect wiring. Make sure you
follow the instructions of wiring correctly. If still not working, just
remove all wires, transistors from the breadboard and reconnect. Then
reboot.
Also make sure you have entered the configuration as shown before in
the configuration.txt file.
26. Write python code to print temperature
Now we are able to detect the sensor in raspberry. This is time to write
a program in python which will keep printing the room temperature in
every second.
Just follow the steps shown in subsequent slides.
29. Write the program
import time
try:
while True:
tempfile = open("/sys/bus/w1/devices/28-80000003c64d/w1_slave")
thetext = tempfile.read()
tempfile.close()
tempdata = thetext.split("n")[1].split(" ")[9]
temperature = float(tempdata[2:])
temperature = temperature / 1000
print (temperature)
time.sleep(1)
except KeyboardInterrupt:
pass