Hanging issue

Hi there
I have made a circuit using atmega328p to control 4 3-phase motors.
The motors are controlled with electro-magnetic contactors.
The circuit i have made has 4 relays with which the contactors are controlled.
Now, when i am bench testing the circuit, it functions perfectly fine but the moment i connect contactors to the relays the controller freezes.
What could be the reason?

Can send the codes if needed.

Please post the code and a schematic together with details of the power supplies used

#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

byte plus = 2;
byte ls_1 = A1;
byte ls_2 = A2;
byte ls_3 = A3;
byte ls_4 = A0;
byte minus = 3; 
byte on_left = 6;
byte on_right = 7;
byte sen_sw = 8;
byte hyd = 5;
byte cut_mot = 10;
byte jb_1 = 11;
byte jb_2 = 12;
byte strt = 13;
byte hy_stop = 4;
byte btnPlus;
byte btnMinus;
byte count = 0;
byte target = 1;
byte in_st;
byte final_st;
byte reset1 = 9;
byte ls1;
byte ls2;
byte ls3;
byte ls4;
byte right;
byte left;
byte sen;
byte total;
uint8_t EEPROMaddress = 130;
uint8_t EEPROMaddress_1 = 120;
uint8_t EEPROMaddress_3 = 110;

byte button2_is_pressed = false;
float stored_time;

long buttonTimer = 0;
long longPressTime = 8000;

boolean buttonActive = false;
boolean buttonRes_is_pressed = true;

int senDebounceTime;
int senDebounceDelay = 50;

byte ledStateMin = LOW;
byte buttonStateMin = LOW;
byte lastButtonStateMin = LOW;
byte readingMin;

long lastDebounceTimeMin = 0;
long debounceDelayMin = 50;

void setup() {
  pinMode(strt, INPUT);
  pinMode(ls_1, INPUT);
  pinMode(ls_2, INPUT);
  pinMode(ls_3, INPUT);
  pinMode(ls_4, INPUT);
  pinMode(on_left, INPUT);
  pinMode(on_right, INPUT);
  pinMode(sen_sw, INPUT);
  pinMode(hyd, OUTPUT);
  pinMode(cut_mot, OUTPUT);
  pinMode(jb_1, OUTPUT);
  pinMode(jb_2, OUTPUT);
  pinMode(reset1, INPUT);
  pinMode(plus, INPUT);
  pinMode(minus, INPUT);
  pinMode(hy_stop, INPUT);

  
  lcd.backlight();
  lcd.begin(16, 2);
  lcd.clear();
  }
void loop() {
  // put your main code here, to run repeatedly:
  count = EEPROM.read(EEPROMaddress_1);
  target = EEPROM.read(EEPROMaddress);
  total = EEPROM.read(EEPROMaddress_3);
  
if(digitalRead(plus) == HIGH){
  delay(50);
  if(digitalRead(plus) == LOW){
        target++;
        count = 0;
        Serial.println(target);
        lcd.clear();
      }
    }
  EEPROM.write(EEPROMaddress, target);
  
  lcd.setCursor(0,1);
  lcd.print("Tar ");
  lcd.setCursor(4,1);
  lcd.print(target);
 
  if(digitalRead(minus) == HIGH){
    delay(50);
    if (digitalRead(minus) == LOW){
          target--;
          count = 0;
          if(target <= 0){
            target++;
          }
          Serial.println(target);
          lcd.clear();
          }
      }
      EEPROM.write(EEPROMaddress, target);
 
   lcd.setCursor(0,1);
  lcd.print("Tar ");
  lcd.setCursor(4,1);
  lcd.print(target);

    ls1 = digitalRead(ls_1);
  ls2 = digitalRead(ls_2);
  ls3 = digitalRead(ls_3);
  ls4 = digitalRead(ls_4);
  left = digitalRead(on_left);
  right = digitalRead(on_right);
 
  byte hy_strt = digitalRead(strt);
  byte hyd_stop = digitalRead(hy_stop);
  byte res = digitalRead(reset1);
if(hy_strt == HIGH){
    digitalWrite(hyd, HIGH);
  }
if(hyd_stop == HIGH){
  digitalWrite(hyd, LOW);
}
  byte srt = digitalRead(hyd);

  if(count != target){
    if((left == HIGH) && (ls2 == HIGH) && (ls4 == HIGH) && (srt == HIGH)){
      digitalWrite(cut_mot, HIGH);
      digitalWrite(jb_1, HIGH);
    }
    else if((right == HIGH) && (ls3 == HIGH) && (ls1 == HIGH) && (srt == HIGH)){
      digitalWrite(cut_mot, HIGH);
      digitalWrite(jb_2, HIGH);
    }
    else{
      digitalWrite(jb_2, LOW);
      digitalWrite(cut_mot, LOW);
      digitalWrite(jb_1, LOW);
    }
  }
  else{
    digitalWrite(cut_mot, LOW);
    digitalWrite(jb_1, LOW);
    digitalWrite(jb_2, LOW);
    }
  
  byte jb1 = digitalRead(jb_1);
  byte jb2 = digitalRead(jb_2);
  byte cut = digitalRead(cut_mot);
  byte sen = digitalRead (sen_sw);
 
   readingMin = digitalRead(sen_sw);
   if (readingMin != lastButtonStateMin) {
      lastDebounceTimeMin = millis();
      lastButtonStateMin = readingMin;
          } 
   
if ((millis() - lastDebounceTimeMin) > debounceDelayMin) {
      if (buttonStateMin != lastButtonStateMin) {
         buttonStateMin = lastButtonStateMin;
         if (buttonStateMin == HIGH) {
            ledStateMin = !ledStateMin;
            count++;
             lcd.clear();
         }
      }
}
      EEPROM.write(EEPROMaddress_1, count);  
    lcd.setCursor(7,1);
    lcd.print("Count ");
    lcd.setCursor(13,1);
    lcd.print(count);
 
  if((count == target) && (button2_is_pressed == false)){
    total++;
    button2_is_pressed =  true;
    lcd.clear();
    EEPROM.write(EEPROMaddress_3, total);
    }
 
   if (res == HIGH){
    buttonRes_is_pressed = true;
    senDebounceTime = millis();
    }
    if((millis() - senDebounceTime) > senDebounceDelay){
      if ((res == LOW)  && (buttonRes_is_pressed == true)){
        count = 0;
         buttonRes_is_pressed = false;
         button2_is_pressed = false;
         lcd.clear();
         }
       EEPROM.write(EEPROMaddress_1, count);
    }
  
if((res == HIGH) && (hy_strt == HIGH) && (digitalRead(plus) == HIGH) && (digitalRead(minus) == HIGH)){
      total = 0;  
      EEPROM.write(EEPROMaddress_3, total);
      lcd.clear(); 
}
  lcd.setCursor(0,0);
  lcd.print("Batch: ");
  lcd.setCursor(8,0);
  lcd.print(total);

 }

Note:
crystal: 16 Mhz
c1 & c2: 20pF ceramic capacitor
c3: 470 micro Farad capacitor
pull-up resisters: 10 kohms
current limiting resisters: 220 ohms
voltage regulator: 5v (7805)
power supply: 12v 1amp (switchable) wall wart power supply

relays: coil voltage 5v (pic attached)

Hi, if i were you I'd

  1. use buck converter in place of LM 7805

  2. use transistor to switch on/off those relays instead of stressing that innocent IC2 ( is that a shift register ? what's it's maximum output sink/source current ? )

Afraid that LED circuit + relay coil 'may' stress the pin

  1. solder that freewheeling diode closest to relay coil

Hi,
OPs pics.


Tom... :slight_smile:

Hi,
Your schematic has no part numbers for any of the components, including your port expander.

Your physical layout will have a lot lot to do with the performance of your circuit, have you assembled a custom PCB?
If so can you post a jpg export of the PCB pattern please.
Can you please post a picture of your project so we can see your component layout.

Power wiring will also have an influence.

You have no bypassing of your power supply tracks which will help.

If you are controlling heavy contactors then the coils will be producing current spikes and surges when connecting and disconnecting.

Can you tell us your electronics, programming, arduino, hardware experience?

Tom... :slight_smile:

TomGeorge:
Power wiring will also have an influence.

Avoid running signal/low voltage wiring alongside power/large current-carrying wiring. Transients from switching inductive loads, like motor starters and contactor coils pulling in, will induce current into any wire nearby - think transformer action. If it must be done route the signal wires to cross the power wires at right angles.

thanks Tom for the reply.

please see the attached pics.

i am not very experienced with arduinos.

i forgot to mention that the PCB is placed within 2-3 inches from contactors (could this be the reason?)
All 4 contacts are placed next to each other.

original

What is the voltage of the contactor coils? AC or DC?

OPs image

The RESET, AGND, AREF and AVCC inputs on the chip are shown as floating in the schematic. Unwise.

JCA34F:
What is the voltage of the contactor coils? AC or DC?

Coil voltage is 220v AC

jremington:
The RESET, AGND, AREF and AVCC inputs on the chip are shown as floating in the schematic. Unwise.

Yes RESET AND AREF pins are floating.
Could this be the reason too?

Correct the obvious problem and see if it helps. Also add 100 nF decoupling caps across every IC power and ground terminal.

When switching large currents associated with motors, it is essential to take every conceivable step to isolate the control circuitry from the electrical interference.

That includes excellent power supply decoupling, and installing the control circuitry in a grounded metal box.