4-20 mA Current Receiver: Some questions (gain, scaling, ...)


I have attached a 4…20 mA waterlevel sensor (0 - 0.4 bar, operates from 10 - 30 V) to a 4-20 mA Current Receiver and am logging the values with python script running on a Raspberry Pi via one of your I2C-Interfaces for Raspberry Pi.

This is how I attached the sensor:

   [  +] --------------- [+]
I2C                         Sensor
   [GND] --------------- [-]

Some questions remain:

gain factor
Which gain factor should I use? I am currently running with the gain factor 1 but I think this does not use the full resolution of the ADC. Is there a formula to calculate the gain factor?

single ended vs differential
I only get reasonable readings if I use “single ended” altough I would have expected that the circuit above is a differential measurement

calculate min/max values
How do I calculate the correct values from the ADC for the equivalents of 0, 4 and 20 mA to correctly scale to the physical value?
At the moment I get the following measurements:
96 : sensor is not attached
3250: Sensor value 0
6350: 0.1 bar (1/4 of the sensors max)

I can’t currently measure the sensors maximum value but estimate the ADC reading to be about 15664

use external voltage
Currently the sensor is running of the 16 V provided by the Current Receiver. Is it possible to use an external voltage? This would enable me to run the sensor with 12 V from a battery.

Thank you in advance


  1. You can use this code
    Gain settings needs to be 2
  2. You will need to use the ADC in single ended mode
  3. You cna checkout this blog on how to convert adc value in to real world values
  4. This board is designed to work with on board power.
    let me know if you have any questions.


Hello Bhaskar,
thanks for the fast reply, everything is working now.

I had used the code you linked to as a starting point and was unsure about the gain. A comment says to use a gain factor of 2 but actually a gain factor of 1 is used later in the program. I will from now on use the gain factor of 2.

On board power is ok for now but I may at some time come back to this point as external power would probably help to save some power (At the moment: 12 V battery -> 5 V Raspberry Pi -> 16 V voltage for the sensor).


this is the one which is designed to work wit external power


@Bhaskar I would like to use the 2-Channel 4-20 mA Current Loop Receiver 16-Bit ADS1115 I2C Mini Module with a Pycom Lopy device, I do not know which library should I use (lopy is a micropython device), or what i2c registers in the module should I read, do you could help me to indicate the correct direction?

You can look into python lib which can be found here

sample code


Thanks for the information, but it does not work for me because they are different devices, this only has 2 4-20mA channels, and the micropython commands from the Lopy are different. Even connecting it to Lopy and scan for it on the bus I could not find it.
this are my initial code, but don’t find the device

from machine import I2C
# configure the I2C bus
i2c = I2C(0, I2C.MASTER, baudrate=100000)
i2c.scan() # returns list of slave addresses

this is what returns:

>>> Running e:\Pycom\projects\ReadI2C4-20mA\main.py

Pycom MicroPython 1.18.1.r1 [v1.8.6-849-b0520f1] on 2018-08-29; LoPy with ESP32
Type "help()" for more information.

Any suggestions? The lack of documentation makes this more complicated.

unfortunately I dont have much exp working with lopy. I will recommend checking with pycom community.

@johncaipa any luck with your set up?