Motorsetup is causing arduino to act weird

I am busy building a table with three electric drawers in it.

One drawer is connected like in this scematic

Pin 6 is connected to the negative lead of the optocoupler
Also the arduino is connected to a QT110 touch sensor(on pin 4) who is build so it acts like: Touch= -5v Not touching=+5v(for just one drawer,the other drawers are operated with a fysical switch,but this one needs to be able to be controlled by iphone over time(not yet))

the other drawers are not connected to the arduino,the relay's are switched on/off by a normal flip switch

the arduino program is this:

int i=0;
int a=0;

void setup()
{
  Serial.begin(9600);
  pinMode(4, INPUT);
  pinMode(6, OUTPUT);
}

void loop()
{
  if (i == 0){ digitalWrite(6, LOW);}  else{digitalWrite(6, HIGH);}

  if (i == 0 && digitalRead(4) == HIGH && a == 1){i = 1;} else{} // LED moet aan
  if (i == 1 && digitalRead(4) == HIGH && a == 0){i = 0;} else{} // LED moet uit
 
  if (i == 0 && digitalRead(4) == LOW){a = 1;} else{} // Test LED=uit en S4 is losgelaten
  if (i == 1 && digitalRead(4) == LOW){a = 0;} else{} // Test LED=aan en S4 is losgelaten
 
 
 Serial.print("a=");
 Serial.print(a);
 Serial.print(" i=");
 Serial.print(i);
 Serial.print(" I4=");
 Serial.println(digitalRead(4));
 
}

Now the problem is this,

When the switch is flipped on one of the two fysicaly switched drawers and it hits an end switch (S1 or S2 on the scheme), the drawer that is rigged with the arduino always opens or closes. It seems to me the reverse peak current when the motor switches of is somehow making the arduino switch pin 6 on or off OR making the QT110 switch,but i doubt that because when I leave the arduino out, the problem does not occur anymore.

How could i solve this problem and how could a 12v circuit interfere with an arduino?

The 12v for all three motors is a 14amp source
The 5v for the QT110 coming from a stabilised 7805 circuit who is fed by the 12v source
The Arduino is powered by a usb cable to my computer

Thanks in advance

Do you know the stall current of the motor? If its more than 14A then the supply voltage is probably dipping on reversal and this might be affecting the 5V regulator circuit.

If you are running any logic signals in parallel with wires carrying the motor current you will likely get crosstalk from the high current wiring - keep high currents away from sensitive circuitry if at all possible.

Yes I was thinking sort of the same thing, it would be the only explanation. Tomorrow I will measure the peak stall current of the motor and check if all my 12v wiring is separate from the 12v wiring.
I'll keep you posted :slight_smile:

Reversing the motor direction while the motor is under power is going to cause a surge in motor current. Have you considered using an Arduino PWM digital output to drive the mosfet via another opto isolator, instead of the 555 timer IC? That way you could program it to reduce the motor current to zero for a short while before you reverse the direction.

The motor is never reversed when it is under power. the drawer goes open when the relay is powered and when it hits the end switch it turns off(leaving the drawer open). Only when the relay turns off that the motor goes the other way,closing the drawer, so it is never reversed when turning! It checked out the wiring and it turns out the 12v feed of one of the end switches is running next to the arduino. I will redirect that tonight and see what is going to happen.

found it, it was the 12v line that was crossing a 5v signal wire that was messing with my system, now everything is seperate and working :slight_smile:

Tanks!