Tip:
Highlight text to annotate it
X
Hi everyone! In today's video I'll explain how to connect a temperature sensor to our Raspberry Pi.
The video will be divided in 2 parts; in the first part we'll see which hardware will we use
and how to connect it to the raspberry, while in the second part we'll analyze the code written in python
used to read the temperature from the sensor.
Bit first, let's move to the necessary hardware; for this tutorial
we'll use, other than the Raspberry Pi, other components that are easy to find
and that could be useful in the future
Let's start with the temperature sensor:
It's a very simple sensor, model DS18B20, that's used to check the room temperature.
To use this sensor we need a resistance of 1.5Kohm
and a breadboard, which is useful to avoid soldering thanks to the jumper cables
that let us work easily and try our things without doing complicated things
But to connect our RPi to the breadboard we need and adapter
which is composed by these 2 parts and that will make our job way easier
Let's do a recap: other than the Raspberry we will need:
A temperature sensor (Model 18B20) with it's relative 1.5Kohm resistor,
a breadboard of the dimension that you prefer and some jumper cables,
and the RPi-to-breadboard adapter
First of all we connect the adaptor to the raspberry... in a really simple way.
after that we connect the adapter to the breadboard.
After that's done we take the sensor, put it in a confortable place, like this
and then we connect the resistor between the AC pin and the pin that we'll use (in this case pin 4)
When that is done, we take the longest cable
and connect the AC of the sensor to the AC pin of our adapter (pin 1).
okay!
Then, we move on to the ground pin (pin 13 on our adapter and the opposite to the AC on our sensor)
And at the end, the middle one that gives us the data to the data pin on our adapter (in our case pin 4)
Good, we've successfully connected the sensor to our RPI!
Now that we completed the hardware part, we can move to the software.
but firstly, we have to install several packages, needed to control the GPIO ports and to execute Python code
So, we start by updating the list of packages already present on our Raspberry
This is done with the command sudo apt-get update
After doing that (it will take some time, don't worry about it), we can move on and start installing the packages
We begin with the package called python-dev
then we install the packages python-rpi.gpio, python-smbus and i2c-tools (useful to check which sensors are connected to our raspberry)
Good! Now that it's done we can start!
YOU CAN FIND THE FILE IN THE DESCRIPTION!
Well, this tutorial has come to an end. In the next video we will see how to expand this project
by adding an LED that will blink when the temperature surpasses a certain limit.
Thanks for following me, goodbye and have fun!