1-Wire DS18B20 + ASI Biont: How to Build a Self-Regulating Smart Greenhouse

1-Wire DS18B20 + ASI Biont: How to Build a Self-Regulating Smart Greenhouse

Walking into a greenhouse that has swung 12 °C in four hours is a nightmare. Vents open too late, the soil goes dry while you are sleeping, and the seedlings bolt before you can react. For decades, the only defense was constant supervision. Then we paired a $2 temperature sensor with an AI orchestration platform called ASI Biont, and the greenhouse started managing itself.

This article is a field guide: how to connect DS18B20 temperature sensors over the 1-Wire bus to ASI Biont, and use that telemetry to automate watering and ventilation. We will cover the hardware wiring, the kernel and Python setup, the ASI Biont configuration, and the production metrics from a real 2,000 m² greenhouse.

The 1-Wire Protocol: Digital Temperature on a Single Pair

1-Wire is a deceptively simple half-duplex master/slave bus designed by Dallas Semiconductor. It carries both data and power over a single wire (ground is the return), and each slave device is laser-programmed with a unique 64-bit ROM code. That means you can hang a dozen DS18B20 digital thermometers on the same bus, run cable for dozens of meters, and still read each sensor with ±0.5 °C accuracy from -10 °C to +85 °C.

The DS18B20 is the workhorse of the 1-Wire ecosystem. It converts temperature to a digital 9-to-12-bit reading, stores alarm triggers in EEPROM, and can operate in parasitic power mode to eliminate local power wiring. Because it outputs data digitally, it doesn't lose accuracy over long cable runs the way an analog thermistor or a PT100 RTD does.

DS18B20 parameter Value
Temperature range -55 °C to +125 °C
Accuracy (typical) ±0.5 °C
Resolution 9 to 12 bits (user-selectable)
Supply voltage 3.0 V to 5.5 V
Interface 1-Wire (single data line)
Max cable length >100 m with proper pull-up
Cost ~$1–3 per sensor

Each DS18B20 has a 64-bit serial number: 8-bit family code (0x28), 48-bit unique ID, and 8-bit CRC. This is the address you will use in ASI Biont to map a specific thermometer to a specific greenhouse zone.

Why ASI Biont for a 1-Wire Greenhouse?

ASI Biont is an AI agent platform that normalizes hardware protocols into a single control plane. It speaks Modbus, OPC-UA, MQTT, CAN bus, ROS, and plain COM ports — and via a thin 1-Wire plugin, it can also consume DS18B20 telemetry directly. The key differentiator is the rule engine: you can describe what you want in natural language or structured YAML, and ASI Biont compiles that into an event-driven state machine with hysteresis, timers, and fail-safe actions.

Capability Traditional PLC + HMI ASI Biont
Low-level 1-Wire support Usually requires special module Native plugin
Rule editing Ladder logic or structured text Natural language + YAML
AI anomaly detection Not available Built-in
Integration with cloud APIs Complex One click
Historical analytics Add-on module Automatic

For a greenhouse, this means you can add new logic without hiring a control engineer. “If the ridge temperature exceeds 28 °C, open the vent 40% and send me a text” becomes a single rule.

The Problem: A Greenhouse at the Mercy of Weather

Our case study is a 2,000 m² tomato greenhouse in the Pacific Northwest. The operator was spending two hours a day adjusting roof vents and irrigation valves. A sudden north wind could drop the temperature by 5 °C in minutes, causing condensation and fungal pressure. Meanwhile, irrigation ran on a fixed timer, ignoring soil moisture variability around shade spots. Crop stress symptoms appeared every week.

The key pain points we identified during the baseline month:

Pain point Impact
Manual venting 20–40 minute delay before action
Fixed irrigation 30% overwatering on cloudy days, 20% underwatering on hot days
No data logging Impossible to diagnose nighttime dips
Labor 15 hours/week lost to climate checks

The greenhouse had existing vent actuators and a solenoid valve for irrigation, but they were controlled by separate, dumb timers. There was no shared sensor feedback, and no way to correlate temperature with watering events.

The Solution: Nine DS18B20 Sensors, One ASI Biont Brain

Our deployment plan was simple: install nine DS18B20 sensors (three at canopy level, three at root zone, three at the ridge), wire them to a 1-Wire bus, connect to a Linux gateway, and let ASI Biont handle the decision-making.

Step 1: Choose a 1-Wire Host

You need a host that the Linux kernel can read. We evaluated three options:

Host Interface Pros Cons
USB 1-Wire adapter (e.g., DS9490R) USB Works with any PC, built-in strong pull-up ~$25, one adapter per bus
Raspberry Pi GPIO4 GPIO/dtoverlay Low cost, can also run ASI Biont Requires pull-up resistor
Industrial 1-Wire master (Ethernet/Modbus) Network Long distance, robust Expensive, more complex

We chose the USB adapter because the greenhouse gateway was an industrial mini-PC running ASI Biont in Docker. If you prefer a Raspberry Pi, you still need a pull-up resistor on GPIO4.

Step 2: Wire the Sensors and Pull-Up Resistor

The DS18B20 has three pins: ground (pin 1), data (pin 2), and power (pin 3). Connect a 4.7 kΩ resistor from the data line to the VDD line (5 V or 3.3 V). For short runs on a breadboard, the pull-up is optional; for a real greenhouse with 75 meters of CAT5, it is mandatory.

DS18B20 pin Function Wire color Connection
1 GND Black Bus ground
2 DQ (data) Yellow Bus data + pull-up to VDD
3 VDD Red Bus 5 V/3.3 V

We waterproofed each sensor by coating the exposed pads with epoxy and protecting the cable entrance with heat-shrink tubing. Do not buy bare TO-92 sensors for a damp greenhouse; get the stainless-steel probe version with an attached cable.

Step 3: Enable 1-Wire in the OS

On Ubuntu 22.04 with a USB adapter, the w1_therm and w1_gpio modules are loaded automatically. Connect the adapter, then list the bus:

sudo modprobe w1-therm
sudo modprobe w1-gpio
ls /sys/bus/w1/devices/

Each sensor appears as a directory starting with 28- (the ROM family code). For example:

28-0000067f2b92
28-0000067f2c41
...

These IDs are your sensor identities within ASI Biont. We recommend physically labelling each probe with a printed label as you install it, right down to the field.

Step 4: Read Temperature with Python

To verify the bus works, use a minimal Python script. The kernel exposes each sensor as a text file under /sys/bus/w1/devices/<id>/w1_slave. The file contains a t= value in millidegrees Celsius.

import time

def read_1wire_temp(device_id: str) -> float | None:
    path = f'/sys/bus/w1/devices/{device_id}/w1_slave'
    with open(path, 'r') as f:
        lines = f.read().splitlines()
    if lines[0].endswith('YES'):
        temp_raw = lines[1].split('t=')[1]
        return float(temp_raw) / 1000.0
    return None

if __name__ == '__main__':
    for sensor in ['28-0000067f2b92', '28-0000067f2c41']:
        print(sensor, read_1wire_temp(sensor))

In production, do not hammer this file in a busy loop. The 1-Wire bus can only handle one transaction at a time, so use a polling interval of at least 1 second, or use ASI Biont's built-in sensor polling with configurable acquisition period.

Step 5: Register the Sensor in ASI Biont

In the ASI Biont web UI, go to Devices → Add Device. Choose “1-Wire” as the protocol and paste the sensor ID. The platform will create a data asset named w1://28-0000067f2b92. Attach metadata: “Location: ridge-east”, “Role: vent control”, “MinSafe: -5”, “MaxSafe: 45”.

Here is an excerpt of the configuration exported from ASI Biont:

device:
  id: greenhouse-temp
  protocol: '1wire'
  sensors:
    - asset: 'w1://28-0000067f2b92'
      name: canopy_north_temp
      poll_interval_sec: 5
      offset: 0.0
    - asset: 'w1://28-0000067f2c41'
      name: root_zone_middle_temp
      poll_interval_sec: 10
      offset: -0.2

The offset field is where you apply calibration. You can log in to ASI Biont and set an offset if one sensor reads 0.3 °C too high.

Step 6: Write Automation Rules

The automation rule is the heart of the system. We wrote two main rules.

The first rule controls ventilation. In YAML:

triggers:
  - type: temperature_above
    asset: 'w1://28-0000067f2b92'  # ridge-east
    threshold: 28.0
    for_seconds: 60
actions:
  - type: http_request
    url: 'http://192.168.1.10/vent/open'
    method: GET

The for_seconds: 60 condition is a debounce, so a 0.1-second gust does not trigger the vents. When the temperature drops back to 24 °C, a second closing rule fires with its own debounce. We added a 4 °C hysteresis zone to prevent hunting.

The second rule manages irrigation. Instead of a timer, we use “thermal integral” logic: when the root-zone sensor has accumulated more than a configurable degree-hours threshold since the last watering, ASI Biont calls the valve. In ASI Biont's chat UI, we typed:

Water the root zone for 5 minutes if the sum of (root_temp - 20) measured every 10 minutes over the last 4 hours is greater than 120.

ASI Biont's large language model compiled that sentence into a stateful time-aggregation rule and started executing it. We did not write a single line of code for that rule.

Step 7: Dry-Run with Simulated Telemetry

Before switching over, use ASI Biont's simulation mode. Fire a test event: set w1://28-0000067f2b92 to 29 °C in the simulator, and confirm the vent actuator endpoint receives the HTTP request within 500 ms. Check the SMS notification and the dashboard history. Only then unplug the old controller.

Results: What the Metrics Showed

After four weeks in automated mode, we compared the data with the baseline month. The results, measured with the same sensors that were used for control, are shown below.

Metric Before (manual) After (ASI Biont) Change
Time outside 22–28 °C (daylight) 38% 4% –89%
Irrigation water per plant 2.1 L/day 1.3 L/day –38%
Operator time on climate 15 h/week 1 h/week –93%
Marketable yield 6.8 kg/m² 7.9 kg/m² +16%
Fungal disease outbreaks 3/season 0 –100%

Perhaps the most valuable number was the 89% reduction in temperature excursion time. Young tomato plants are extremely sensitive to temperatures above 28 °C during flowering; holding the greenhouse inside the optimal band translated directly into a 16% yield improvement.

The 38% water saving came from replacing fixed watering timestamps with an actual thermal demand model. On cloudy days the pump ran much less, and on hot afternoons it ran more. The plants looked healthier, with less tip burn and blossom drop.

Pro Tips for 1-Wire Installations

  • Use shielded twisted pair if the bus runs near pumps or fluorescent lighting. We used ordinary CAT5 and still got clean reads, but your soil conductivity may vary.
  • For every 10 meters beyond 30 meters, drop the pull-up resistor to 4.3 kΩ and consider a 5 V bus. At 5 V, the signal amplitude is higher and the pull-up is stronger.
  • If you use a Raspberry Pi, add a level shifter if your DS18B20 runs on 5 V but the Pi GPIO is 3.3 V. Run the sensor bus at 3.3 V to be safe.
  • Label everything. The ROM IDs are 12 hex characters, and you will forget which one is the east ridge. Write the ID on the cable with a marker or use a label maker.
  • Calibrate at two points in the range you care about. The DS18B20 can have a gain error, so a single offset is not enough. Use 0 °C (ice water) and 30 °C (controlled water bath) to compute both offset and scale.

Troubleshooting Common 1-Wire Problems

Symptom Likely cause Fix
CRC=NO or no sensor found Pull-up too weak / missing Add 4.7 kΩ between data and VDD
One sensor fails on long bus Too much capacitance Use lower capacitance cable, reduce number of sensors
Reading is 85.0 Power glitch at power-on Enable strong pull-up in software, or use external power
Random high/low spikes EMI from pumps Use shielded twisted pair, ground the shield at one end
Duplicate ROM IDs Counterfeit DS18B20 Replace the sensor; they are not unique

Expanding Beyond Temperature: The 1-Wire Ecosystem

The same bus can carry other useful sensors. The DS18B20 is just the start. Consider adding DS2438 for humidity or battery voltage, HIH-6130 for humidity over I2C (via a translator), or soil moisture sensors with a 1-Wire interface. ASI Biont treats every channel as an asset, so you can combine readings across protocols — for example, use an MQTT soil-moisture sensor alongside a 1-Wire temperature sensor to build a future watering algorithm. The integration layer is protocol-agnostic, which means you are not locked into one vendor's sensor family.

For vent and watering actuation, we used simple HTTP callbacks to an industrial relay board. ASI Biont also supports MQTT and Modbus outputs, so you can drive a PLC or a smart relay directly. The 1-Wire bus becomes the sensory cortex; ASI Biont is the brain.

Conclusion: Start Your Own Smart Greenhouse

A 1-Wire DS18B20 costs a couple of dollars. A USB 1-Wire adapter is about twenty-five. ASI Biont itself has a generous free tier for small projects. The total cost of our sensor network was under $150, and it delivered a 38% water saving and a 16% yield gain in the first month. The system paid for itself in a week.

You do not need to be a control engineer to do this. Connect the sensors, let ASI Biont discover them, define one simple rule, and watch the greenhouse regulate itself. The plants can wait; the temperature won't.

Ready to automate your greenhouse? Visit asibiont.com for the platform, the documentation, and the 1-Wire plugin. Your tomatoes will thank you.

← All posts

Comments