Back to Guides
Advanced • ~20 min read

Adding Arduino Nodes

Expand your MudPi system by integrating Arduino-based sensor nodes.

Why Use Arduino?

Arduino boards excel as dedicated sensor nodes. They provide native analog-to-digital conversion, are extremely low power, and can run independently while reporting data to your main Raspberry Pi controller.

6+

Analog Inputs

<50mA

Power Draw

~$5

Per Node

Communication Options

Choose Your Protocol

Serial (USB)

Direct USB connection. Simple, reliable, and no additional hardware needed. Best for single-node setups where the Arduino is near the Pi.

I2C

Wire protocol for short-distance communication. Supports multiple devices on a single bus. Good for nodes within a few meters of the Pi.

WiFi (ESP8266/ESP32)

Wireless via MQTT or HTTP. Best for remote nodes. ESP32 boards are Arduino-compatible and include built-in WiFi.

Arduino Sketch

Upload a sketch to your Arduino that reads sensors and sends data over serial. MudPi's Arduino worker parses the incoming data and publishes it to Redis.

Arduino (C++)
#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT22
#define MOISTURE_PIN A0

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  dht.begin();
}

void loop() {
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();
  int moisture = analogRead(MOISTURE_PIN);

  Serial.print("t:");
  Serial.print(temperature);
  Serial.print(",h:");
  Serial.print(humidity);
  Serial.print(",m:");
  Serial.println(moisture);

  delay(30000);
}
Click to expand code…

Data Format

The serial output uses a simple key:value format that MudPi's Arduino worker can parse. You can customize the format by modifying the worker's parser configuration.

MudPi Configuration

Add an Arduino node to your MudPi configuration. MudPi will automatically detect the serial port:

mudpi.config.json
{
  "nodes": [
    {
      "type": "arduino",
      "name": "Garden Node 1",
      "port": "/dev/ttyUSB0",
      "baud_rate": 9600,
      "sensors": [
        { "key": "t", "name": "Node 1 Temperature", "type": "temperature" },
        { "key": "h", "name": "Node 1 Humidity", "type": "humidity" },
        { "key": "m", "name": "Node 1 Moisture", "type": "soil_moisture" }
      ]
    }
  ]
}
Click to expand code…

Finding the Serial Port

Connect the Arduino via USB and find its port:

Shell
ls /dev/ttyUSB* /dev/ttyACM*

The Arduino typically shows up as /dev/ttyUSB0 or /dev/ttyACM0.

Tip

For persistent port names, create a udev rule that assigns a consistent name based on the Arduino's serial number. This prevents port changes when multiple USB devices are connected.