
For my Industrial Embedded Automation project, I needed a way to test the 4-20 mA input functionality, however all my test sensors were simple 0 to 3.3 V voltage sources. To bridge the gap, I designed a custom voltage to current transmitter sub-board utilising an op-amp and transistor to push current through the loop.
Initially, I considered building this as a purely analogue circuit to keep things simple. However, the moisture sensor I was testing was a very basic “dumb” sensor that didn’t output linearly over the full 0 – 3.3 V range. Tuning an analogue circuit to scale that specific, narrow voltage band up to a full 4-20 mA swing would have required adding manual trimmer potentiometers and a lot of hardware tweaking.
Instead, I leaned into the “overkill” approach and added an ATMega328P microcontroller. There would have been many better options, but I only had STM32s on hand to prototype with that would have been 10x more overkill!
While even the 328P might seem excessive for a simple transmitter, it gave me two massive benefits. First, I can handle the sensor calibration entirely in software, mapping the exact sensor limits to the 4-20 mA output perfectly. Second, I can oversample the analogue voltage readings and average them out to drastically reduce random signal noise before converting it to a current output.
To make debugging and calibration easy, I included the ubiquitous CH340G USB to Serial IC – all too well known by its prominence on Chinese Arduino clones. It keeps the BOM cost incredibly low while allowing me to monitor the scaled values over a standard serial monitor.
I designed this board to take a 5V input directly to power the 328P, with a simple AMS1117 linear 3.3V regulator to power the sensor.
