Arduino and Arduino sketches

Firmware architecture for network-connected temperature probes using Arduino boards and humidity sensors.

Top view of a blue Arduino Uno microcontroller board on a white background
Arduino-compatible boards run the sketch that polls probes and publishes JSON. Photo: Wikimedia Commons contributor. CC0

The probe hardware runs on Arduino-compatible microcontrollers. Firmware: commonly called a sketch: reads sensors on a timer, formats the results as JSON, and serves them over the network so the website and other clients can fetch live data without serial cables.

Sketch responsibilities

  1. Initialize sensor buses and the local 16×2 LCD for on-site readouts.
  2. Read each DHT22 probe with retry logic for transient bus errors.
  3. Compute an average across healthy probes for a quick summary value in JSON.
  4. Respond to HTTP requests with a compact JSON document via the Ethernet shield.
  5. Optionally log errors to serial for on-site debugging.

Typical JSON shape

Consumers expect a top-level temp object with numeric keys for each probe plus avg. Humidity appears alongside temperature per probe. Keeping keys stable matters more than pretty printing: dashboard mappings reference those keys directly.

{
  "temp": {
    "0": { "f": 38.2, "c": 3.4, "h": 41.0 },
    "1": { "f": 36.8, "c": 2.7, "h": 43.5 },
    "avg": { "f": 37.5, "c": 3.1, "h": 42.2 }
  }
}

For push ingest, the same probe object can be posted to /api/ingest/<key>. Optional top-level battery (or battery_pct) and rssi fields update device health on the Devices page without requiring extra sensor keys.

{
  "temp": {
    "0": { "f": 38.2, "c": 3.4, "h": 41.0 }
  },
  "battery": 87,
  "rssi": -62
}

Push ingest from the Ethernet shield

The W5100 stack on an Uno cannot TLS, so it cannot POST directly to https://probeharbor.dev. Use ethernet_dht22_ingest to POST the classic temp JSON over HTTP (DHT22 on A4/A5, optional JSON on port 80 for LAN pull). Run push_https_forward.py on a Pi, NAS, or laptop so those POSTs reach ProbeHarbor over HTTPS. ESP32 Wi‑Fi samples that speak TLS live in sketches/.

Hardware wiring guides

The physical build uses an Arduino Uno, W5100 Ethernet shield, breadboard, contrast potentiometer, 16×2 LCD, and two DHT22 sensors. Three companion pages document the schematics and pin map in detail:

Network stack choices

This revision uses an Ethernet shield on SPI. The sketch handles DHCP, reconnect loops, and JSON serving while the LCD continues to show live probe values. When TLS is too heavy for the MCU, a Python relay can terminate HTTPS: see Python scripts and feeds. For push ingest from the same shield, see ethernet_dht22_ingest.

Arduino Uno wired to a DHT temperature-humidity sensor with three jumper wires
A minimal MCU-plus-sensor bring-up before Ethernet, LCD, and dual-probe wiring. Photo: Wikimedia Commons contributor. CC BY-SA 4.0
ProbeHarbor revision-two probe board with Ethernet shield, LCD, and DHT22 sensors
ProbeHarbor revision two: Ethernet, LCD readout, and dual DHT22 inputs in one stack.

Development workflow

Sketches are edited in the Arduino IDE or PlatformIO, flashed over USB, then verified with serial logging before the board is mounted in the monitored space. Confirm JSON shape with curl before adding the feed URL to the website dashboard.

Ready-to-adapt samples for DS18B20, MAX31855, MAX6675, and Uno + Ethernet live in this repo under sketches/. Raspberry Pi Pico W / Pico 2 W uses the same ingest JSON with CircuitPython or MicroPython. Full Ethernet + DHT + LCD firmware: arduino-network-json-temperature-sever.

Reliability tips

  • Watchdog resets recover from rare network hangs without climbing a ladder.
  • Separate sensor power noise from MCU power where long cable runs exist.
  • Version your JSON schema in documentation when adding fields.
  • Document which GPIO pins map to which physical probe labels, see the pin wiring guide.

FAQ

Where are sample Arduino sketches?
In the probeharbor GitHub repo under sketches/, plus the Arduino guides in About. ESP32 samples POST HTTPS directly. Uno + W5100 Ethernet uses ethernet_dht22_ingest (classic temp JSON on A4/A5) plus a LAN HTTP→HTTPS relay: the shield cannot TLS to probeharbor.dev.