AI Meets Microcontroller: How to Integrate Arduino Due with ASI Biont for Lab Automation

Introduction

The Arduino Due is a powerful 32-bit ARM Cortex-M3 microcontroller, boasting a 84 MHz clock speed, 96 KB SRAM, and 512 KB flash memory. Unlike its 8-bit cousins (Uno, Mega), the Due offers native USB host, two DAC channels, and 54 digital I/O pins — making it ideal for complex sensor arrays, motor control, and real-time data acquisition in laboratory and light industrial settings. But without an intelligent orchestrator, even the most capable microcontroller operates in isolation, reacting only to pre-programmed logic. That’s where ASI Biont comes in: an AI agent that connects to any device via chat, writes integration code on the fly, and enables natural language control of your hardware. This guide walks through a real-world integration of Arduino Due with ASI Biont using the Hardware Bridge (COM port) method, complete with wiring diagrams, Python code examples, and two automation scenarios.

Why Connect Arduino Due to an AI Agent?

Microcontrollers excel at deterministic, low-latency tasks — reading a temperature sensor every second, controlling a servo, or logging analog values. However, they lack the contextual intelligence to make nuanced decisions: “Should I increase the pump speed because the pressure trend suggests a blockage in 10 minutes?” or “Notify the team if three consecutive pH readings exceed 7.5.” By bridging Arduino Due with ASI Biont, you offload high-level reasoning to the AI while the Due handles real-time I/O. The AI can analyze historical data, trigger alerts, adjust setpoints via chat, and even generate new firmware sketches — all without manual coding of a dashboard.

Connection Method: Hardware Bridge via COM Port

ASI Biont connects to Arduino Due through the Hardware Bridge — a lightweight Python application (bridge.py) that runs on your local PC (Windows, Linux, macOS) and communicates with the cloud-based AI agent via a secure WebSocket. The bridge opens a serial connection (RS-232 over USB) to the Due and relays commands from the AI. The user simply describes the connection parameters in the chat: port name (e.g., COM3 on Windows, /dev/ttyACM0 on Linux) and baud rate (115200 for Due). The AI then uses the industrial_command tool with the serial_write_and_read operation to send hex-encoded data and receive responses. This atomic write+read cycle ensures reliable communication without polling loops.

Why COM Port and Not MQTT or HTTP?

Arduino Due lacks built-in Ethernet or Wi-Fi. While you could add an Ethernet shield, the simplest and most universal method is USB serial. The Hardware Bridge works with any microcontroller that presents a virtual COM port — no extra hardware required. For wireless scenarios, an ESP32 would be better suited for MQTT; here, we focus on the Due’s native strengths: deterministic timing and rich analog/digital I/O.

Step-by-Step Integration Guide

1. Hardware Setup

Component Purpose
Arduino Due Main controller
DHT22 temperature/humidity sensor Data acquisition
10 kΩ potentiometer Analog voltage divider (0–3.3 V)
Servo motor (SG90) Actuator demonstration
470 Ω resistor + LED Digital output indicator
Breadboard and jumper wires Prototyping

2. Wiring Diagram

  • DHT22: VCC → 3.3V, GND → GND, DATA → pin 7 (with 10kΩ pull-up to 3.3V)
  • Potentiometer: middle pin → A0, outer pins → 3.3V and GND
  • Servo: red → 5V, brown → GND, orange → pin 9
  • LED: anode (long leg) → pin 8 via 470 Ω resistor, cathode → GND

3. Arduino Due Firmware (Arduino IDE)

The Due must run a sketch that listens for commands over Serial (USB) and executes actions. Below is a minimal command parser:

// Due_Firmware.ino
#include <DHT.h>
#include <Servo.h>

#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
Servo myservo;

void setup() {
  Serial.begin(115200);
  dht.begin();
  myservo.attach(9);
  pinMode(8, OUTPUT);
  digitalWrite(8, LOW);
  Serial.println("HELP: TEMP,HUMID,ANALOG,SERVO <0-180>,LED_ON,LED_OFF");
}

void loop() {
  if (Serial.available()) {
    String cmd = Serial.readStringUntil('\n');
    cmd.trim();
    if (cmd == "TEMP") {
      float t = dht.readTemperature();
      Serial.println(String("TEMP:") + t);
    } else if (cmd == "HUMID") {
      float h = dht.readHumidity();
      Serial.println(String("HUMID:") + h);
    } else if (cmd == "ANALOG") {
      int val = analogRead(A0);
      Serial.println(String("ANALOG:") + val);
    } else if (cmd.startsWith("SERVO ")) {
      int angle = cmd.substring(6).toInt();
      myservo.write(angle);
      Serial.println("SERVO_OK");
    } else if (cmd == "LED_ON") {
      digitalWrite(8, HIGH);
      Serial.println("LED_OK");
    } else if (cmd == "LED_OFF") {
      digitalWrite(8, LOW);
      Serial.println("LED_OK");
    } else {
      Serial.println("UNKNOWN");
    }
  }
}

Upload this sketch to the Due. Open the Serial Monitor at 115200 baud to verify the HELP message appears.

4. Bridge Setup

  1. Go to the ASI Biont dashboard → Devices → Create API Key. Download bridge.py.
  2. Install dependencies: pip install pyserial requests websockets
  3. Run the bridge (replace TOKEN with your actual API key):
python bridge.py --token=YOUR_API_KEY --ports=COM3 --baud 115200

On Linux, the port might be /dev/ttyACM0. The bridge connects to the cloud and announces the available port.

5. Chat with AI Agent

Now, in the ASI Biont chat interface, describe what you want to do. For example:

“Connect to Arduino Due on COM3 at 115200 baud. Read temperature and humidity every 5 seconds. If temperature exceeds 30°C, turn on the LED and set servo to 90 degrees. Log all readings to a CSV file.”

The AI will generate and execute the following Python script in the sandbox (execute_python), which communicates with the bridge via the industrial_command tool:

import time
import csv
from datetime import datetime

# The AI uses industrial_command internally; here we simulate the logic
# In real chat, AI calls industrial_command(protocol='serial', command='serial_write_and_read', data='TEMP\n')
# For demonstration, we show the conceptual flow:

commands = ['TEMP', 'HUMID']
with open('sensor_log.csv', 'a', newline='') as f:
    writer = csv.writer(f)
    for _ in range(10):
        temp_resp = "TEMP:25.3"  # placeholder for actual bridge response
        humid_resp = "HUMID:58.2"
        temp_val = float(temp_resp.split(':')[1])
        humid_val = float(humid_resp.split(':')[1])
        writer.writerow([datetime.now(), temp_val, humid_val])
        if temp_val > 30:
            # AI sends: industrial_command(protocol='serial', command='serial_write_and_read', data='LED_ON\n')
            # and: industrial_command(protocol='serial', command='serial_write_and_read', data='SERVO 90\n')
            pass
        time.sleep(5)

In practice, the AI directly invokes industrial_command for each serial transaction. The bridge sends the ASCII command to the Due, reads the response, and returns it to the AI.

Real-World Scenario: Automated Laboratory Incubator

Imagine a biology lab using an Arduino Due to monitor and control a small incubator for cell cultures. The Due reads:
- DHT22 for temperature and humidity
- A pH probe (analog input via A0)
- A CO2 sensor (via I2C)

It controls:
- A heater (via a relay on pin 8)
- A servo that opens/closes a vent (pin 9)

Problem: The incubator must maintain 37°C ± 0.5°C, 95% humidity, and pH 7.4. Variations due to door openings or ambient changes require adaptive adjustments.

Solution with ASI Biont:
1. The AI connects via bridge and begins polling TEMP, HUMID, and ANALOG every 2 seconds.
2. It implements a simple PI controller in the chat script: if temperature < 36.5°C, turn heater ON; if > 37.5°C, turn heater OFF.
3. If pH drifts outside 7.2–7.6, the AI sends a Telegram alert: “pH critical at 7.8. Recommend media change.”
4. All data is logged to a Google Sheet via the AI’s HTTP API capabilities.

No manual coding of a web dashboard — the entire system is configured through natural language.

Why This Beats Traditional Approaches

Aspect Traditional IoT Platform ASI Biont + Arduino Due
Setup time Days (write firmware, build dashboard, configure alerts) Minutes (upload sketch, run bridge, chat with AI)
Flexibility Fixed logic; changes require recompilation Adaptive; AI rewrites control logic on-the-fly
Alerting Built-in only if supported Any channel: email, SMS, Telegram, Slack
Data analysis Limited to predefined charts AI interprets trends, predicts failures, suggests optimizations
Cost Often $50–200/month for cloud platform Free for small projects; pay-per-use for AI compute

Conclusion

Integrating Arduino Due with ASI Biont unlocks a new paradigm: hardware control through conversational AI. Whether you’re automating a lab incubator, monitoring an environmental chamber, or prototyping an industrial controller, the process is the same — upload a simple serial command parser, run the bridge, and describe your automation goals in chat. The AI handles the rest: data collection, decision-making, alerting, and logging. No dashboards to build, no endpoints to code. Ready to connect your Arduino Due to an AI agent? Start today at asibiont.com — download the bridge, plug in your Due, and tell the AI what you want to build.

← All posts

Comments