UART, PWM, RS485, 4 to 20 mA: choosing a sensor output
, 4 min read
Use UART or I²C for a sensor on the same board as a microcontroller, PWM when you only have a timer input, RS485 with Modbus for several sensors on a long cable, 4 to 20 mA for PLCs and noisy industrial sites, and LIN or CAN inside vehicles.
Comparison
| Output | Signal | Typical cable | Use it for |
|---|---|---|---|
| UART (TTL) | Digital serial frames | Under 1 to 2 m | Microcontrollers, single sensor |
| I²C | Digital, addressed bus | Under 1 m | Several sensors on one board |
| PWM | Pulse width encodes value | A few metres | Simple timer input |
| RS485 Modbus RTU | Differential digital bus | Up to about 1,200 m | Many sensors, long runs, diagnostics |
| 4 to 20 mA | Analogue current loop | Hundreds of metres | PLCs, noisy sites, loop power |
| 0 to 10 V | Analogue voltage | Short runs | OEM controllers |
| LIN / CAN | Vehicle buses | In-vehicle | Automotive ECUs |
Why 4 to 20 mA lasts
A current loop is immune to voltage drop along the cable, and 4 mA as zero means a broken wire reads 0 mA and can be detected. Two-wire transmitters draw their power from the same loop.
Why RS485 for many sensors
Differential signalling rejects noise over long cables, and Modbus addresses let up to 32 standard loads share one pair. The sensor can also report diagnostics and accept configuration.