diff --git a/ohmpi.py b/ohmpi.py
index 53ec36eada91fdf8bba1b8270b1c0ad5020435c9..d7d5c3fe9e46a34f79a6232be0432174265aad48 100644
--- a/ohmpi.py
+++ b/ohmpi.py
@@ -1206,7 +1206,7 @@ class OhmPi(object):
             # find I2C address of the electrode and corresponding relay
             # considering that one MCP23017 can cover 16 electrodes
             i2c_address = 7 - (electrode_nr - 1) // 16  # quotient without rest of the division
-            relay_nr = electrode_nr - (electrode_nr // 16) * 16 + 1
+            relay_nr = (electrode_nr-1) - ((electrode_nr-1) // 16) * 16
 
             if i2c_address is not None:
                 # select the MCP23017 of the selected MUX board