1

I've setup a MCP23017 16-bit I/O expander with a rPi model B via i2c, and I am able to control components like LEDs on the channels GPA0-GPA7 using code like this;

# set GPA pins to output
i2cset -y 1 0x20 0x00 0x00

# set GPA0 pin to on, (led on)
i2cset -y 1 0x20 0x14 0x1

However what I want to do is control a 12V electromagnetic lock from a relay, and though I am able to trigger the relay, its unreliable and setting a pin on the MCP23017 to LOW doesn't always trigger the relay.

The led on the relay board is dim, compared to when its manually triggered by putting IN2 to GND

The relay is triggered active-low, and the relay specs suggest 0-0.5V is required to trigger it.

# set GPA0 pin to on, (relay on)
i2cset -y 1 0x20 0x14 0x0

The circuit is currently setup like this with a relay instead of the led; enter image description here

The relay however is triggered active-low, and so is looking for a Voltage between 0-0.5 Volts compared to ground.

However low-output on the MCP23017 GPA0 pin is measured at about 0.7 - 0.9 volts, and this doesn't appear to be low enough to trigger the relay.

The data sheet for the MCP23017 says that output-low should be less than 0.6 V. So at the very least the MCP23017 is out of spec.

The schematic from a similar relay board; enter image description here

  • 5V 2-Channel Relay interface board, and each one needs 15-20mA Driver Current
  • Are you powering the electromagnet from 12V? Are you sure the 12V circuitry is isolated from the 5V Pi circuitry? I.e. with no Pi 5V connected can you measure any voltage between VCC and ground. Do you have/need a fly-back diode to prevent the back EMF from the collapsing electromagnet field getting back into the circuitry. Have you considered using a ULN280X series chip? – joan Dec 22 '14 at 9:42
  • For the purposes of isolation, I currently have 2 separate 5v supplies, and a 12V supply on different wal warts, so 3 wall sockets in all. Both the relay coil and the lock circuit should be isolated from back EMF. – Tom H Dec 24 '14 at 2:22
  • I put some capacitors across the MCP23017 and I've not seen teh MCP23017 reset since. So I am going to edit the question to focus on the over voltage of the MCP23017 output. – Tom H Dec 24 '14 at 2:36
  • When you leave the relay input at High-Z (such as when disconnected from the circuit), does it behave as triggered? – Marco Poli Dec 25 '14 at 13:01
  • If the input to the relay is disconnected, the relay is not triggered. – Tom H Dec 26 '14 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.