enter image description hereI am using an Arduino Uno to create a kinetic sculpture with magnets and electromagnets (EMs). I have a setup with two externally debounced buttons using resistors,capacitor and CMOS 4584 hex inverter. All non-used inputs of the 4584 are grounded. These buttons deliver a clean signal to the board and trigger the two interrupts which set flags to turn LEDs on or off and trigger one or both optoisolators (OIs). These connect to another board with a separate 12V supply. One of the OIs turns a BUZ71 power mosfet on and the other triggers a relay which can reverse the polarity of the power to a small 30 ohm EM coil. This can make the magnet suspended above like a pendulum fly away from the coil...

This works perfectly well with the buttons, the LEDs and the two inputs to the OIs But when I connect the relay/mosfet board to the output of the OIs it stops working properly. button 2 turns off button 1 as well as itself. Button one always turns off and on cleanly But button two triggers ISR2 about 10 times and ISR1 a couple of times, leaving both off. If I disconnect the EM coil the buttons work properly. It seems that switching the polarity is somehow interfering with the Uno maybe due to a fairly hefty inductive spike generated by switching the relay. I have tried using shielded coax to the coil. I have 47000 uF caps on both boards. I tried a crude faraday cage around the relay board - no luck. Could the spike be coming through the household power supply somehow even though the Uno board and the relay board have different power supplies and are fully seperated by the OIs? Here is the sketch I am using:

    //  Coding by Jeremy 070520
//  development for ricochet module

const int coilButton = 2;
const int directionButton = 3;
const int coilPin = 8; //coil driver
const int directionPin = 9; //direction driver
volatile bool coilFlag;
volatile bool directionFlag;
int coilLedState = LOW;
int directionLedState = LOW;

void setup() 
  pinMode(directionButton, INPUT);
  pinMode(coilPin, OUTPUT);
  pinMode(directionPin, OUTPUT);
  digitalWrite(directionPin, LOW);
  attachInterrupt(digitalPinToInterrupt(coilButton), ISR1, FALLING);
  attachInterrupt(digitalPinToInterrupt(directionButton), ISR2, FALLING);

void loop(){
    coilFlag = false;
    coilLedState = !coilLedState;
    digitalWrite(coilPin, coilLedState); 
    directionFlag = false;
    directionLedState = !directionLedState;
    digitalWrite(directionPin, directionLedState); 
delay(1);   //I'm desperate I will try anything ....
} //end loop 

void ISR1() 
  coilFlag = true;

void ISR2() 
  directionFlag = true;
  • 2
    Any chance to get schematic diagram here?
    – KIIV
    Commented May 11, 2020 at 12:37
  • You using freewheeling diodes for the EMs?
    – Sim Son
    Commented May 11, 2020 at 15:02
  • A human pressing a button isn’t really an appropriate place for an interrupt unless it’s to wake from a sleep state. This is a problem you shouldn’t ever even have. Just poll the buttons and things will work. You mention in a comment being desperate and will try anything, doing it the normal way might just be worth a try.
    – Delta_G
    Commented May 11, 2020 at 18:41

1 Answer 1


I'd suggest building a Faraday cage around the inductive coil. It's probably inducing enough current in all the wires around it to trigger logic level voltages in your signal wires, in the board, etc.

It sounds like the goal is for the coil to fling a magnet away, so you might have to settle for a "Faraday bowl" (an open-topped Faraday cage). Some magnetic field would leak out the top of the bowl, but if you place the control board below the bottom and several feet away it might be enough.

You might need to shield everything separately: Faraday cage around the Arduino. "Faraday Bowl" around the coil. Coax cables for everything, where the power to the coil is in a coax cable that's grounded separately, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.