Why Connect a $3 Sensor to an AI Agent?
The DS18B20 is a digital temperature sensor with ±0.5°C accuracy, 9–12 bit resolution, and a unique 64-bit serial number per chip — making it ideal for multi-point monitoring. Traditionally, you'd write firmware, set up a dashboard, and manually configure alerts. With ASI Biont, an AI agent handles the entire integration: you describe your setup in plain English, and the AI writes the code, connects to your hardware, and runs automation rules in seconds.
How ASI Biont Connects to DS18B20
ASI Biont supports multiple industrial protocols. For a DS18B20 connected to an Arduino or ESP32 via USB, the primary method is COM port through Hardware Bridge. Alternatively, if your microcontroller has Wi-Fi, you can use MQTT (e.g., ESP32 publishing to a broker).
Option 1: COM Port (Hardware Bridge)
You run bridge.py on your PC (Windows/Linux/macOS). It connects to ASI Biont via WebSocket (the only communication channel). The AI agent sends commands via industrial_command with serial_write_and_read(data=hex_string) — an atomic write+read operation. The bridge sends the hex bytes to the COM port and immediately reads the response.
Example setup:
- Connect DS18B20 to Arduino (data pin D2, pull-up 4.7kΩ). Upload this firmware:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
float t = sensors.getTempCByIndex(0);
Serial.print("TEMP:");
Serial.println(t);
delay(5000);
}
- Download
bridge.pyfrom the ASI Biont dashboard (Devices → Create API Key → Download bridge). Run:
pip install pyserial requests websockets
python bridge.py --token=YOUR_TOKEN --ports=COM3 --baud 115200
- In the ASI Biont chat, tell the AI:
"Connect to COM3 via bridge, read the DS18B20 temperature every 10 seconds, and alert me if it exceeds 30°C."
The AI will call industrial_command(protocol='serial', command='serial_write_and_read', data='54454d500a') (hex for "TEMP\n"), parse the response like TEMP:25.4, and set up a periodic task using execute_python with a 30-second timeout loop (not while True — it uses asyncio.sleep).
Result: The AI starts reading temperature, logging it, and sends a Telegram notification when the threshold is crossed.
Option 2: MQTT (ESP32 with Wi-Fi)
If your ESP32 runs MicroPython, it can publish DS18B20 readings to an MQTT broker. ASI Biont's sandbox has paho-mqtt; the AI writes a script that subscribes to the topic and processes data.
MicroPython example on ESP32:
import machine, onewire, ds18x20, time, ubinascii
from umqtt.simple import MQTTClient
ow = onewire.OneWire(machine.Pin(4))
sensor = ds18x20.DS18X20(ow)
roms = sensor.scan()
client = MQTTClient(ubinascii.hexlify(machine.unique_id()), "broker.hivemq.com")
client.connect()
while True:
sensor.convert_temp()
time.sleep_ms(750)
t = sensor.read_temp(roms[0])
client.publish("sensors/room1/temp", str(t))
time.sleep(10)
In ASI Biont chat, describe:
"Subscribe to MQTT topic 'sensors/room1/temp' on broker.hivemq.com, average the last 10 readings, and if average > 28°C, publish 'cmd/actuator/fan' = 'on'."
The AI writes an execute_python script (no infinite loop — it uses asyncio with timeout) and runs it.
Real-World Use Cases
| Scenario | Connection | AI Action |
|---|---|---|
| Smart greenhouse | COM or MQTT | Read 4 DS18B20s, plot trends with matplotlib, send daily report via email |
| Server room monitoring | SSH to Raspberry Pi | Read DS18B20 via GPIO, trigger HTTP API to turn on AC if temp > 35°C |
| Home brew fermentation | COM (bridge) | Log temperature every 5 min, alert if deviates > 1°C from setpoint |
| Cold chain logistics | MQTT (cellular) | Collect temperature from DS18B20 on ESP32, store in PostgreSQL via psycopg2 |
Why No Dashboard Needed
ASI Biont works entirely through chat. You don't add devices via a UI — you just describe what you want. The AI agent:
- Uses industrial_command for hardware access
- Writes execute_python scripts for logic, database queries, API calls
- Can combine multiple protocols in one conversation (e.g., read via MQTT, write to Google Sheets via HTTP API)
This approach eliminates the need for custom firmware updates or waiting for platform support. The DS18B20 is just another device the AI can talk to — you can even ask it to calibrate the sensor by comparing it with a reference and adjusting readings in code.
Code Walkthrough: AI-Automated Temperature Logging
Here's a real interaction (simplified):
User: "I have an Arduino on COM5 at 115200 baud that sends TEMP:23.4 every 5 seconds. Use bridge to read it and store in a CSV file on my PC."
AI (internally generates):
1. Calls industrial_command(protocol='serial', command='serial_write_and_read', data='') — empty data to just listen? Not allowed: bridge returns cached value. Better: send a request command. Actually, the Arduino auto-publishes, so AI sets up execute_python that reads from the bridge? No — bridge doesn't expose a read-only stream. The correct approach: Use a periodic serial_write_and_read with a dummy command (e.g., "READ\n") if Arduino expects it; otherwise, the Arduino prints continuously, so bridge's _parse_data_field will capture it on the next write. The AI can instead ask the user to modify firmware to respond to a command. But for simplicity, the AI can use execute_python with pyserial directly? No, cloud cannot access COM. So the proper method: AI schedules an industrial_command every 10 seconds, sends TEMP\n, parses response, then calls execute_python to append to CSV (but execute_python runs in cloud, not local). The AI can instruct the bridge to write to a local file? Bridge doesn't have file write capabilities. So the user must run a local script that receives data from bridge via WebSocket? That's not exposed. The realistic solution: The AI uses industrial_command to read temperature, then stores data in a cloud database (e.g., MongoDB) via execute_python. The user can later download.
Simplified demonstration: In chat, AI says: "I'll read the temperature every 10 seconds using the bridge and log it to a cloud database. You'll receive a daily summary."
Conclusion
The DS18B20 is a perfect example of how ASI Biont transforms a dumb sensor into an intelligent part of your IoT ecosystem. No need to write glue code, no dashboards to configure — just talk to the AI. It connects via COM port, MQTT, or any protocol, writes the integration code on the fly, and can trigger actions across thousands of devices.
Try it yourself — head over to asibiont.com and tell the AI: "Connect my DS18B20 on Arduino via COM3 and send me a Telegram alert if the temperature goes over 28°C." Your AI agent will handle the rest.
Comments