In compliance with high industry standards

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

Odoo image and text block

INTRODUCTION


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.

RELATED LINKS

How to program Raspberry PLC

interrupt inputs with Python



Read >>

Raspberry PLC

family products



Read >>

TouchBerry Pi

family products



Read >>

How to program Raspberry PLC

interrupt inputs with Python



Read >>

Raspberry PLC

family products



Read >>

TouchBerry Pi

family products



Read >>

INTRODUCTION

DALLAS SENSOR

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:

 dtoverlay=w1-gpio,gpiopin=25



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:    

cd /sys/bus/w1/devices


6. List the files:

ls


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:

cd 28-0000072b7724



8.  Read the file w1-slave where you will see the temperature:

cat w1_slave




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 >>




Looking for your ideal PLC?

Take a look at this product comparison with other industrial controllers Arduino.

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC controller comparison >>

Do you want more information?

Just fill the form!

Tell me more!