II. Temperature sensor & Raspberry PLC: How to get the temperature
DS18B20 Dallas Sensor & Raspberry Pi automation
14 June, 2021 by
II. Temperature sensor & Raspberry PLC: How to get the temperature
Boot & Work Corp. S.L., Fernandez Queralt Martinez

Introduction

In the communications area of the industrial Raspberry PLC, there is a direct pin which is the GPIO 25 that goes to the GPIO 25 directly.

In this post, we are going to learn how to get temperature from a Dallas DS18B20 temperature sensor to a Raspberry Pi based PLC through the One-Wire protocol.

Related Links

How to

Program Raspberry Pi industrial PLC Interrupt inputs with Python

Read 

Raspberry PLC

Family Products

See 

Basics about

Raspberry Pi Programmable Logic Controller Analog inputs

Read 

Touchberry Pi

Family products

See 

Dallas sensor and an industrial Raspberry Pi PLC for industrial automation

The DS18B20 sensor is a digital sensor that can be used with the open source PLC Raspberry Pi easily.  Check out its datasheet for more information: Go >>

Once connected, the temperature reading is very simple, as it is remote controlled by reading a file.

See how to connect the Dallas DS18B20 temperature sensor and the Raspberry Pi PLC controller for industrial control. 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

Step 2 - II. Temperature sensor & Raspberry PLC: How to get temperature

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

Step 7 - II. Temperature sensor & Raspberry PLC: How to get temperature

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

cat w1_slave

Step 8 - II. Temperature sensor & Raspberry PLC: How to get temperature


9. Extract only the temperature:

cat w1_slave | sed -e 's/.*t=//' | sed '1d'

Step 9 - II. Temperature sensor & Raspberry PLC: How to get temperature

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 (Part III) >>

How to connect a Dallas sensor and a Raspberry PLC (Part II)

II. Temperature sensor & Raspberry PLC: How to get the temperature
Boot & Work Corp. S.L., Fernandez Queralt Martinez
14 June, 2021
Share this post
Archive

Looking for your ideal Programmable Logic Controller?

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

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


Industrial PLC comparison >>>

Do you want more information?

Just fill the form!

Tell me more!