Arduino receiving interrupts when DC motor attached

Hi all,

I’m here to ask for help
I’ve prepared a project to automate the opening and closing of my garage doors.
I’ve got 2 Servo Motors that runs at 12V so I bought a transformer ( 220V to 12V ) to power them,
between the transformer and the servos there is an inverter ( done with 3 relays ) to invert the current flow
This transformer power also an external board with an antenna to give my board the signals from the remote-controller.
While the 2 servo motors are unattached everything works properly, when I attach even only one servo the board receive signals from the antenna even if I don’t use the remote

Any suggestion on how to solve?

Many thanks

Is there an Arduino involved in this anywhere? A circuit diagram/schematic would help and details of the components (I’ve never seen servos that run on 12V AC from a transformer).

And I guess you must have some code. It would be good to see that too.

Steve

1 Like

Hi Steve,

here the picture of the circuit ( sorry for the old school drawing )

Here is the code running on the board

#include <EEPROM.h>

int pin_12_state = 0;
int last_pin_7_8_state = 0;
unsigned long stop_time = 0;
unsigned long start_time = 0;
unsigned long time_remaining = 0;

unsigned long time_necessary = 9000;

int addr = 0;

bool last_int = false;
bool overlaps = false;
bool run_int = false;

float perc_opening = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(12,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(2,INPUT);
  pinMode(11,OUTPUT);

 
  
  Serial.begin(9600);
  EEPROM.write(512,0); //1 completamente chiuso - 0 completamente aperto
  EEPROM.write(addr, 100);// 0 completamente chiuso - 100 completamente aperto
  last_pin_7_8_state = EEPROM.read(512);
  if (last_pin_7_8_state == 0){
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    }
  else{
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
    }
 attachInterrupt(digitalPinToInterrupt(2), received_signal , FALLING);
}



void loop() {
  
  if (millis() > stop_time -25 && millis() < stop_time +25 && pin_12_state == 1){
    Serial.println("TIME STOPPED");
    digitalWrite(12, LOW);
    pin_12_state=0;
  }

  
 if(pin_12_state==1){
  
  if (overlaps == false)
    time_remaining = stop_time - millis();
  else
    if(millis() < 4294967296)
      time_remaining = 4294967296-millis()+stop_time ;
    else
      time_remaining = stop_time - millis();
    
  if (last_pin_7_8_state == 0)
    
    perc_opening = (time_remaining*100)/time_necessary;
  else
    perc_opening = 100-(time_remaining*100)/time_necessary;
  EEPROM.write(addr, perc_opening);
  
 }


 if (run_int == true){
   Serial.println("SIGNAL RECEIVED");
  perc_opening = EEPROM.read(addr);
  
  if (pin_12_state == 1){
    Serial.println("STOPPED FROM REMOTE CONTROL");
    digitalWrite(12, LOW);
    pin_12_state=0;
  }
  else{
    Serial.println("STARTED");
    if(last_pin_7_8_state == 1){
      
      last_pin_7_8_state = 0;
      EEPROM.write(512,last_pin_7_8_state );
      digitalWrite(7, LOW);
      digitalWrite(8, LOW);

      if(perc_opening == 0 || perc_opening == 100)
        time_remaining = time_necessary;
      else
        time_remaining = time_necessary - (perc_opening*time_necessary)/100;
      
      
      if (millis()+time_remaining > 4294967296){
        start_time = millis();
        stop_time = time_remaining-(4294967296-millis());
        overlaps = true;
      }
      else{
        stop_time = millis()+time_remaining;
        overlaps = false;
      }
      
      
      digitalWrite(12, HIGH);
      pin_12_state=1;
    }
    else{
      //Serial.println("SENS 2");
      last_pin_7_8_state = 1;
      EEPROM.write(512,last_pin_7_8_state );
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      
      if(perc_opening == 0 || perc_opening == 100)
        time_remaining = time_necessary;
      else
        time_remaining = time_necessary - (perc_opening*time_necessary)/100;
      
      if (millis()+time_remaining > 4294967296){
        start_time = millis();
        stop_time = time_remaining-(4294967296-millis());
        overlaps = true;
      }
      else{
        stop_time = millis()+time_remaining;
        overlaps = false;
      }

      digitalWrite(12, HIGH);
      pin_12_state=1;
    }
  }

  run_int=false;
  
 }
  
  if(digitalRead(2) == 0 && last_int == true){
    delay(1000);
    interrupts();
    last_int=false;}
 
}

void received_signal(){
  noInterrupts();
  delay(1000);
  last_int = true;
  //Serial.println("RECEIVED");
  run_int=true;
  
}

I’d also add that the servo is 12V DC

Hi, @pupiii
Welcome to the forum.
Your circuit right way up.

What are your “servos”, are they just DC motors?
Can you post a link to specs/data please?

Can you please post a picture of your project so we can see your component layout?
What size is your 12V power supply?
How are you powering your controller?
What model Arduino are you using?

Are your relays modules with relay drivers on board?

Thanks… Tom… :grinning: :+1: :coffee: :australia:

Hi Tom,

Probably my “servo” should be see more as a DC Motor than a servo. Is nothing more than a gate opener, it’s a FAAC Swing 204800 12VDC

Here’s a photo about my layout

May I ask what do you mean by size? What’s the output?

Thanks

Hi,

“Gate Opener”???

What are the specs of the power supply and what are the specs of the “motor”?
What is written on them about there working parameters?

Using the DuPont type jumpers is also not a good idea for this situation.
They are good for experimenting and POC, but in the real world they are not suitable for reliable long term connectivity.

Your remote receiver and antenna needs to be kept away for many power AC or DC cables.

What do you mean, what happens, does the relay on the Receiver chatter or click, or does the UNO behave as though the relay is activated, even though its not?

You have the receiver relay switching between gnd and 3V3, the UNO is a 5V logic controller, you should be switching between gnd and 5V.

Tom… :grinning: :+1: :coffee: :australia:
PS, I’m off to bed… :sleeping: :sleeping: :sleeping: :sleeping:

I would not use a piece of breadboard as a distribution strip.  Long term unreliable.

A screwshield would be preferable.

Something like this Installer friendly 402 230V swing gate operator | FAAC™ UK

The power supply provides 12V DC, 10A and up to 150W of output
The “motor” needs 12V DC and uses up to 48W

I’ll try to move the antenna far from other cables and let you know if anything change

The UNO behave as though it receive the signal even though the receiver relay is not activated

I’ll also try this

I’ll update you as soon as possible

Many thanks

Hi,
Also check the voltage you have on the input pin of the UNO from the Receiver Relay.

Tom… :grinning: :+1: :coffee: :australia:

Hi,

I’ve tried to move the antenna away from cable, no luck
I’ve tried to give the 5V instead of 3.3V, no luck

The voltage on the input pin from the receiver is 3.3V or 5V depending on where I attach the Com of the Receiver Relay

Any other suggestion?

Thanks

Hi,
Looking at your circuit diagram, if you have gnd connected to NC, Normally Closed, then the input pin should be at GND.
Have you got GND and 5V connected to the correct terminals?

Tom… :grinning: :+1: :coffee: :australia:

Hi,

yes the connections are correct, without the “motor” attached everything works fine
Is when I attach the “motor” that the issue comes up

There are a number of concerns with your construction.

A UNO is a poor choice for a practical project such as this, the “Dupont” jumpers are not really appropriate for long-term operation and vibration could be a concern. Using them in screw connectors is a bit odd but I suppose if that is all you have on hand it is understandable.

For such projects, we would prefer to have almost all soldered connections - a Nano is appropriate for this as you can obtain them without the pin headers mounted. A “screwshield” as mentioned is however a good alternative.

The major problem here is the scrambled wiring. To avoid interference between different parts, it is essential to keep all connections between one part and another tightly bundled either by using ribbon-type wire, or tying with cord (nylon fishing line is convenient) so that there are no open loops in the wiring between a power or signal line and its matching ground return as such open loops function as little coupling transformers. It is necessary to understand that these microcontrollers operate at “RF” - radio frequencies - and the principles of radio transmission apply.

And note this especially applies to the wiring to motors, solenoids etc.

Your title was slightly puzzling, referring to “interrupts”. “Newbies” frequently misunderstand the purpose of interrupts in computers, so this attracted my attention but fortunately you do not appears to have fallen into this trap. I am however puzzled by finding in your code:

and

which makes no sense. From where did you get this code?

Hi,

thanks for the various suggestions I’ll try to apply them

About the code

Due to the issue mentioned that even if I didn’t use the remote to fire the interrupt I’ve tried to add this piece of code to have a slight delay in the reenabling of them giving time to “excess current” on the pin to flow to ground. I hope this could solve my problem of missfiring but as said before it solved it only when the “motor” is not attached.

Here the delay is more no sense but without created a lot of missfiring, I use the run_int to execute a bunch of code in the loop only one time. When I receive the interrupt I set it to True, run the code in the loop and reset it to False
The last_int instead is used as a check to understand if I just run an interrupt or no, without it each loop entered the if statment previously mentioned and I had delay in each loop

About where i got the code… pretty much from my head :upside_down_face:

Thanks

:roll_eyes: OK, I have had another look at the code and found where you used

So that code is complete nonsense.

As you do not understand what interrupts are and why they are terribly inappropriate in this (as in most) situation, you really need to delete that line and all reference to interrupts. Start again with the problem and carefully discuss your proposals here.

So on further thought. maybe that is only one part of the problem :grin:


I also note a catastrophic error in the relay wiring! Simultaneously actuating relay 1 and relay 3 shorts out your 12 V supply. :astonished:

Hi,
I can’t believe I’m using this schematic again in 24hours.
Look at this two relay circuit to STOP,FWD and REV your ,motor.

RELAY1 OFF RELAY2 OFF MOTOR OFF
RELAY1 ON RELAY2 OFF MOTOR FWD
RELAY1 OFF RELAY2 ON MOTOR REV
RELAY1 ON RELAY2 ON MOTOR OFF

Tom… :grinning: :coffee: :coffee: :australia:

Hey, i have bookmarked it. If you do not use it repeatedly in future, I probably will. :sunglasses:

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.