Arduino and Arduino sketches

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

Arduino microcontroller board wired to temperature sensors and a network shield
Arduino microcontroller board wired to temperature sensors and a network shield

The garage 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
}

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.

First revision probe board showing sensor wiring headers
Revision one established the multi-probe layout later refined in revision two.

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 garage. Confirm JSON shape with curl before adding the feed URL to the website dashboard. Source 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.