Browse our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteria
Dallas sensor & Raspberry PLC: How to get temperature
DS18B20 temperature sensor & Raspberry usage
In the communications area of the Raspberry PLC, there is a direct pin which is the GPIO 25 that goes to the GPIO 25 directly.
In this blog, we are going to learn how to get temperature from a Dallas DS18B20 temperature sensor to a Raspberry PLC through the 1-Wire protocol.
The DS18B20 sensor is digital sensor which can be used with Raspberry easily. Check out its datasheet for more information: Go >>
Once connected, the temperature reading is very simple, as it is done by reading a file.
See how to connect the Dallas DS18B20 temperature sensor and the Raspberry PLC. See how >>
Just follow the steps below to get your temperature from everywhere your sensor is placed:
1. Go and edit the /boot/config.txt file:
sudo nano /boot/config.txt
2. Add the following line to configure the 1-Wire:
Exit the nano editor by pressing CTRL-X and then S, and then ENTER to exit saving the file.
3. Reboot the system to apply changes:
sudo reboot now
4. Run the following commands to enable the one-wire interface on demand:
sudo modprobe w1-gpio
sudo modprobe w1-therm
5. Go to the /sys/bus/w1/devices directory:
6. List the files:
7. Several directories will appear, including one (or several, if we have several thermometers connected) with the name 28-XXXXXX, which is the serial number of the thermometer, different for each transistor. Go to yours, in our case:
8. Read the file w1-slave where you will see the temperature:
9. Extract only the temperature:
cat w1_slave | sed -e 's/.*t=//' | sed '1d'
10. The temperature from our sensor is expressed in ºC multiplied by 1000, and although there are many ways to parse that temperature, we are going to make it using Node-RED. Know how >>