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
- 1 x Arduino / ESP32 based PLC
- Power supply (12 - 24V)
- B or micro B type cable, to program the Arduino / ESP32 based PLC.
- Dallas Temperature sensor.
- 4k7 Ohm resistor.
Software
- Arduino IDE
- Industrial Shields Boards
- OneWire Arduino library
- DallasTemperature Arduino library
Implementation
Hardware setup
Firstly, power the PLC between 12 and 24V. Then, connect the 3 wires from the Dallas Temperature sensor as shown:
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
OneWire with Arduino and ESP32 based PLCs