How to fix common iot mistakes

The sensor reads zero and the code has not changed since yesterday. That sentence covers most of the failures in a first IoT build, and almost none of them are in the code. Fixing them gets faster when you stop reading the sketch first and start sorting the fault into one of four layers: power, signal, network, code.

Three checks before you change a line of code

Do these in order, because each one rules out a whole layer.

  • Measure the supply voltage at the board, not at the adapter.
  • Confirm the serial port still appears when you unplug and replug the cable.
  • Re-flash the untouched blink example; if that fails, the toolchain or cable is the problem, not your sketch.

The board reboots or the display flickers when a relay clicks

That is a power event, not a logic bug. A relay, a motor, or a bright LED strip pulls a surge the supply cannot cover, and the voltage sags enough to reset the microcontroller. Move the load onto its own supply with a shared ground, add a capacitor near the load, and never drive an inductive load straight from a board pin — use a transistor or a driver module.

If the resets happen without any load switching, suspect the cable and the adapter in that order. A thin USB cable can drop enough voltage that the radio browns out only when it transmits, which looks like a software crash every few minutes.

Readings jump, drift, or sit at zero

Zero usually means the signal never arrives: a missing ground, a pin that is not the one in the sketch, or a sensor that needs a pull-up. Jumping values usually mean the reading is fine and the environment is noisy — long unshielded wires next to a power cable, or a breadboard with a half-seated jumper.

Drift over days is different again. Analog sensors can be affected by supply voltage, temperature, and, in soil or outdoor builds, corrosion of the probe. Compare a reading against a known reference and log the raw number rather than the converted one, so the drift is visible.

The device connects, then disappears for hours

Wi-Fi that works at the bench and fails in the corner of the house is a signal problem. Check the reported signal strength at the final location, not where you built it. Then check your reconnect logic: many first sketches connect once at boot and never try again, so a single router hiccup leaves the device silent until you power-cycle it. Add a retry with a delay, and log each attempt so the dropouts are visible.

The serial monitor stays silent

Match the baud rate in the sketch to the monitor, confirm you selected the right port when two boards are plugged in, and check that the sketch is not stuck in a loop before the first print. If a board with native USB is involved, the port can disappear during a reset; opening the monitor after the board settles often fixes it.

Sort the fault into a layer before you touch the code, and most sessions end in twenty minutes instead of two hours. When a fault points at a damaged component or a mains-powered circuit, stop and get help rather than experimenting.