OneWire with Arduino and ESP32 based PLCs

Learn how to read the temperature from a Dallas Temperature sensor using OneWire and Arduino / ESP32 based PLCs
June 17, 2025 by
OneWire with Arduino and ESP32 based PLCs
Boot & Work Corp. S.L., Bernat Brunet Pedra

Introduction

If you're diving into the world of industrial PLCs and temperature measurement, you'll inevitably come across the OneWire protocol and DallasTemperature sensors like the DS18B20. These tools are widely celebrated for their simplicity, precision, and versatility, making them ideal for a variety of projects, from monitoring room temperature to industrial applications.

In this post, we'll explore the fundamentals of the OneWire protocol, how it enables communication with devices like the DS18B20, and why the DallasTemperature sensor family has become a go-to choice for makers and engineers alike. Whether you're just starting out or looking to optimize your temperature sensing projects, understanding how these components work together is essential.


Hardware

Software

Implementation

Hardware setup

Firstly, power the PLC between 12 and 24V. Then, connect the 3 wires from the Dallas Temperature sensor as shown:

Dallas Temperature sensor connection

Vcc is connected to 5V. This way, the DS1820 Dallas Temperature sensor is powered (pins 1 and 3), with the data pin (pin 2) in pull-up mode. Finally, the data pin is connected to a direct pin from the PLC. Depending on the model acquired, the possible options are the following:

  • M-Duino PLC:
    • SCL: GPIO 21
    • SDA: GPIO 20
    • MISO: GPIO 50
    • MOSI: GPIO 51
    • SCK: GPIO 52
    • Pin 3: GPIO 3
    • Pin 2: GPIO 2
  • Ardbox PLC:
    • SCL – Pin 3: GPIO 3
    • SDA – Pin 2: GPIO 2
    • MISO: GPIO 14
    • SCK: GPIO 15
    • MOSI: GPIO 16 
  • ESP32 based PLCs: 
    • SDA: GPIO 21
    • SCL: GPIO 22

Some GPIOs from the Arduino based PLCs need to be enabled using the DIP Switches, consider checking out the user Guider for more information about how to enable those pins.

Software implementation

In order to program the PLC follow this steps:

1. Navigate to File > Examples > DallasTemperature and select the Simple example.

2. Change the ONE_WIRE_BUS pin to the corresponding GPIO from the list above.

3. Select your Board and Model according to your PLC:

  • For M-Duino PLC Family: Tools > Board > Industrial Shields AVR Boards > M-Duino [Extension] family and Tools > Model > M-Duino [Module]
  • For Ardbox PLC Family: Tools > Board > Industrial Shields AVR Boards > Ardbox [Extension] family and Tools > Model > Ardbox [Module] HF+ w/HW RS-485
  • For ESP32 PLC Family: Tools > Board > Industrial Shields ESP32 Boards > ESP32 PLC Family and Tools > Model > ESP32 PLC [Module]
  • For ESP32 PLC 14: Tools > Board > Industrial Shields ESP32 Boards > 14 IOS PLC Family

4. Finally, upload the sketch at Sketch > Upload

​Search in our Blog

OneWire with Arduino and ESP32 based PLCs
Boot & Work Corp. S.L., Bernat Brunet Pedra June 17, 2025
Share this post
Tags

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.

PLC Comparison