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.
#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);
}
Data Format
MudPi Configuration
Add an Arduino node to your MudPi configuration. MudPi will automatically detect the serial port:
{
"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" }
]
}
]
}
Finding the Serial Port
Connect the Arduino via USB and find its port:
ls /dev/ttyUSB* /dev/ttyACM*
The Arduino typically shows up as /dev/ttyUSB0 or /dev/ttyACM0.
Tip