Level System Control

Hi,

This is my first-time post in this forum. I had created a system that able to sense the level of a platform using MPU6050 and Arduino UNO which will control two 3-phase motors through a 2 channels SSR module and two 24Vac contactors. The program is simply detecting the axis of the platform from MPU6050 whenever the push button for ‘UP’/‘DOWN’ is close and send the output ‘HIGH’ to the SSR to turn off the contactor depending on which side the platform is tilted.

The circuitry and program code is attached to illustrate the system

#include <Wire.h>
#include <MPU6050.h>

MPU6050 mpu;

float lTiled = 20;
float rTiled = -20;
int tirak1 = 3;
int tirak2 = 4;
int up = 8;
int down = 10;
int pitch;
int roll;

void setup() 
{
 pinMode(tirak1, OUTPUT);
 pinMode(tirak2, OUTPUT);
 pinMode(up, INPUT);
 pinMode(down, INPUT);
 digitalWrite(up, LOW);
 digitalWrite(down,LOW);
 digitalWrite(tirak1, HIGH);
 digitalWrite(tirak2, HIGH);
 
 Serial.begin(115200);

 Serial.println("Initialize MPU6050");

 while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
 {
   Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
   delay(100);
 }
}

void loop()
{
 digitalWrite(tirak1, HIGH);
 digitalWrite(tirak2, HIGH);
 if(digitalRead(up)==HIGH)
 {
   do
   {
     Monitor();
     if(roll >= lTiled)
     {
       Serial.println(roll);
       Case(0);
       delay(100);
     }else if(roll <= rTiled)
     {
       Serial.println(roll);
       Case(1);
       delay(100);
     }else if(roll <= lTiled || roll >= rTiled)
     {
       Serial.println(roll);
       Case(5);
       delay(100);
     }
   }while(digitalRead(up)==HIGH);
 }

 if(digitalRead(down)==HIGH)
 {
   do
   {
   Monitor();
     if(roll >= lTiled)
     {
       Serial.println(roll);
       Case(2);
       delay(100);
     }
     if(roll <= rTiled)
     {
       Serial.println(roll);
       Case(3);
       delay(100);
     }
     if(roll <= lTiled || roll >= rTiled)
     {
       Serial.println(roll);
       Case(5);
       delay(100);
     }
   }while(digitalRead(down)==HIGH);
 }
}

void Monitor()
{
 
 // Read normalized values 
 Vector normAccel = mpu.readNormalizeAccel();

 // Calculate Pitch & Roll
 //pitch = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis*normAccel.YAxis + normAccel.ZAxis*normAccel.ZAxis))*180.0)/M_PI;
 roll = (atan2(normAccel.YAxis, normAccel.ZAxis)*180.0)/M_PI;
}

void Case(int CASE)
{
 switch (CASE)
 {
   case 0:
     Serial.println("Mark1");
     while(roll > 0)
     {
     digitalWrite(tirak1,LOW);
     digitalWrite(tirak2,HIGH);
       Monitor();
     }
     Serial.println("Reutrn");
   break;
   case 1:
     Serial.println("Mark2");
     while(roll < 0)
     {
     digitalWrite(tirak1,HIGH);
     digitalWrite(tirak2,LOW);
       Monitor();
     }
     Serial.println("Reutrn");
   break;
   case 2:
     Serial.println("Mark3");
     while(roll > 0)
     {
       digitalWrite(tirak1,HIGH);
       digitalWrite(tirak2,LOW);
       Monitor();
     }
     Serial.println("Reutrn");
   break;
   case 3:
       Serial.println("Mark4");
     while(roll < 0)
     {
       digitalWrite(tirak1,LOW);
       digitalWrite(tirak2,HIGH);
       Monitor();
     }
     Serial.println("Reutrn");
   break;
   case 5:
       Monitor();
       Serial.println(roll);
       digitalWrite(tirak1,LOW);
       digitalWrite(tirak2,LOW);
   break;
 }
}

So the result will good when I tested the system with just Arduino UNO; MPU6050; and 2 channels SSR module. But when hookup to the contactors, issues started to show up like, Arduino started to hang or the output keeps on triggering ‘HIGH’ or ‘LOW’.

Below are the points of troubleshooting I had done:

  1. Try with different methods of programs, but the result is still the same.

  2. Shield Arduino and sensor with aluminum foil doesn’t help which I thought it could be EMI interference

  3. Isolate the power supply of SSR from Arduino doesn’t improve.

  4. Place two 10uF 50V E-capacitors between each output of SSR and blow up.

I really need some expert advice on what I’m doing wrong. What other components/s do I need to add-on or change?

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Each time loop() is ran, are you meaning to reset the positioning of the tirak1?

  void loop()
{
 digitalWrite(tirak1, HIGH);
 digitalWrite(tirak2, HIGH)

Idahowalker:
Each time loop() is ran, are you meaning to reset the positioning of the tirak1?

  void loop()

{
digitalWrite(tirak1, HIGH);
digitalWrite(tirak2, HIGH)

That means that when the output tirak1 and 2 are high, the SSRs are off.

From your fritzy drawing you should not operate properly and definitely be sensitive to noise. You show 5 volts going into the barrel connector, You need a few more volts then 5, I like about 8 to 9, that gives me head room for the regulator and the voltage drop through the reverse bias diode. I am not sure how you assembled it but the contactors emit a lot of EMI, they should be in a separate enclosure or the electronics shielded from it. Why not start by defining the problem with specifications including a flow chart, schematic, power requirements, and EMI requirements. Define what the expected outcome needs to be. Purchase the Arduino cookbook and read it, this will give you some basics. also use the online tutorials and videos available, there are many good ones on this web site. At this point you will be able to define the problem and may have already solved it.

TechnoDrone:
That means that when the output tirak1 and 2 are high, the SSRs are off.

Each time the loop() is ran and before any logic is run the SSR's are, first, turned off. The loop() runs many 100's or 1000's times a second. So, digitalWrite(tirak1, HIGH); is turning off the SSR's 100's or 1000's times a second and then the rest of the code may or may not, also, turn off and on the SSR's for only a few 100's or 1000's times a second..

gilshultz:
From your fritzy drawing you should not operate properly and definitely be sensitive to noise. You show 5 volts going into the barrel connector, You need a few more volts then 5, I like about 8 to 9, that gives me head room for the regulator and the voltage drop through the reverse bias diode. I am not sure how you assembled it but the contactors emit a lot of EMI, they should be in a separate enclosure or the electronics shielded from it. Why not start by defining the problem with specifications including a flow chart, schematic, power requirements, and EMI requirements. Define what the expected outcome needs to be. Purchase the Arduino cookbook and read it, this will give you some basics. also use the online tutorials and videos available, there are many good ones on this web site. At this point you will be able to define the problem and may have already solved it.

Well... I did some research on how to use Arduino and other devices before assembling them. I place all the contactors in the enclosure and the Arduino outside. From what I can tell is the high power contactor coil is messing with the Arduino. So I'm thinking of purchase surge suppressors and install each of the contactors to see whether it help reduce the noise. What do you think?

Each time the loop() is ran and before any logic is run the SSR's are, first, turned off. The loop() runs many 100's or 1000's times a second. So, digitalWrite(tirak1, HIGH); is turning off the SSR's 100's or 1000's times a second and then the rest of the code may or may not, also, turn off and on the SSR's for only a few 100's or 1000's times a second..

so what you said is that I have to place a delay for each loop?

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.

OPs image;


What are you using to drop 24V to 5V.
As stated earlier, the 5V needs to go into the 5V pin, not the DC scoket.

Have you any bypass capacitors on the 5V supply?

What size are the 3 phase motors.

Please DRAW a complete circuit diagram and post an image of you efforts please?
Can you tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

TechnoDrone:
so what you said is that I have to place a delay for each loop?

I did not write ‘anything’ about adding in delay.

What you could do is figure out a way to not change the state of the SSR’s with each loop unless there is a state change. For example, put those 2 lines at the end of setup(). By putting those lines in setup() the initial state of the SSR’s can be realized and then only if the condition changes, in loop (), will the SSR’s change state instead of resetting upon each loop.

Idahowalker:
I did not write 'anything' about adding in delay.

What you could do is figure out a way to not change the state of the SSR's with each loop unless there is a state change. For example, put those 2 lines at the end of setup(). By putting those lines in setup() the initial state of the SSR's can be realized and then only if the condition changes, in loop (), will the SSR's change state instead of resetting upon each loop.

Oh I see... I'll go give it a try... But I doubt that will fix the issue...

TomGeorge:
What are you using to drop 24V to 5V.
As stated earlier, the 5V needs to go into the 5V pin, not the DC scoket.

Have you any bypass capacitors on the 5V supply?

What size are the 3 phase motors.

Please DRAW a complete circuit diagram and post an image of you efforts please?
Can you tell us your electronics, programming, arduino, hardware experience?

Thanks… Tom… :slight_smile:

Hi Tom,

The regulator I use to step down from 24vdc to 5vdc is a D24V10F5 from Pololu.

The motor is 3-phase, 400V, 3A, 0.86 Eff, 1.87 HP(cal)

When you said DC socket, you mean the jack plug? 24vdc come from ADC converter (240Vac to 24Vdc) which the current is 0.63A. I think it may not be enough current.

TechnoDrone:
When you said DC socket, you mean the jack plug? 24vdc come from ADC converter (240Vac to 24Vdc) which the current is 0.63A. I think it may not be enough current.

This schematic will show how to connect your 5V supply to the UNO.


Tom... :slight_smile:

TomGeorge:
This schematic will show how to connect your 5V supply to the UNO.


Tom... :slight_smile:

Hi Tom,

Wow... Just wow... My mind just blown... All the while I'd been using either USB or Jack Plug to supply power to Arduino, never do I know that 5V pin can be use to supply power to the board. But will that stabilize the control signal the contactor?

TechnoDrone:
. But will that stabilize the control signal the contactor?

Try it.
Tom.. :slight_smile:

TomGeorge:
Try it.
Tom.. :slight_smile:

I was thinking about the +5v and vin pin. Wasn't +5v pin meant for power up external module and Vin pin is to power up the arduino?

Hi,
The Vin and the DC plug are the same connection.
They power an internal 5V regulator to power the PCB including the controller IC.
The 5V from the regulator also is connected to the 5V pin on the PCB.

The circuit is designed so you can also feed 5V into the 5V pin and power the PCB without using the DC or Vin terminals.

The Vin and DC voltage need to be above 7V, for the 5V regulator to work, so 5V at Vin will not give you a regulated 5V out at the 5V pin.

Tom... :slight_smile:

TomGeorge:
Hi,
The Vin and the DC plug are the same connection.
They power an internal 5V regulator to power the PCB including the controller IC.
The 5V from the regulator also is connected to the 5V pin on the PCB.

The circuit is designed so you can also feed 5V into the 5V pin and power the PCB without using the DC or Vin terminals.

The Vin and DC voltage need to be above 7V, for the 5V regulator to work, so 5V at Vin will not give you a regulated 5V out at the 5V pin.

Tom... :slight_smile:

Ah... I see... Thanks Tom... I will try it out...