I have made a electric circuit and code to control a 2 relay module board witch is connected to a linear actuator. My project works a expected if there is no linear actuator connected. The problem occurs when i connect the linear actuator. When it's connected the motor can make a small CW and CCW move, but when i make a longer movement and afterwards to the opposite direction the arduino catch fire. The first time my relay board was connected to the 5v of my arduino nano(jumper) and i thought my relay has created a voltage spike dude to the EMF from the relay (it has an diode) and affected back to the 5v on the arduiono. So the second time i have connected a external voltage regulator to the relay board and the same thing happens. I don't know what's caused the problem but i was thinking of a voltage spike(back EMF from motor) that can't be collected by the voltage regulator on the whole system when i switch direct to the other relay in stead of wait a moment before activate the other relay so that both motor wire's are connected together through the ground connection.
facts:
The whole project is powered by a 12V battery.
The arduino nano is supply power (3,3V) to my "svs nachrichtentechnik cx-12r" witch has survived al the situations.
I'm sorry, but your diagrams are completely unintelligible.
the arduino catch fire
The most likely cause of this is that you are trying to power the actuator from current supplied by the Arduino. But as I can't make sense of your diagrams I cannot be sure.
Motors and actuators should have a separate power supply as an Arduino board cannot supply enough current.
Relays are a poor choice for controlling high power motors.
You should be using a motor driver capable of handling the stall current of the motor, which is typically 5-10x the running current. Pololu has a good selection.
I know i made a messy scheme, but what i try to do is to move the motor CW and CCW with the 2 channel relay board. The power at the switching relay contacts to the motor is coming from the general 12v battery. There is a ACS712 current sensor between the cable to the motor and the other stuff is only control input. For completeness I will insert my code below.
//Analog inputs
#define defACS712 A0 //AnalogRead 0 to 5v == int value 0 to 1023, IF ACS712 measure 0A then its output = 2,5V == int value 512
#define defLimitDn A1 //Read negative current limit, scale 0-7A linak motor
#define defLimitUp A2 //Read positive current limit, scale 0-7A linak motor
//Digital inputs
#define defButtonManualDn 2
#define defButtonManualUp 4
#define defRcDn 5
#define defRcUp 6
//Digital outputs
#define defMotorDn 7
#define defMotorUp 8
//Outputs states, #define make that the compiler write the value before it compiles thus get no memory space insteat of using const
#define defRelayOff 1
#define defRelayOn 0
float fActCurrentInput,fCalculatedCurrent,fActLimitDnInput,fCalculatedLimitDn,fActLimitUpInput,fCalculatedLimitUp;
unsigned int uiStepper, uiMemStepper, uiStepCycles;
bool xMotorDn, xMotorUp, xDownCommand, xUpCommand, qxMotorDn, qxMotorUp;
const int iIncorrectMeasurementCycles = 13;
const int iReverseDirectionCycles = 20;
const int iMaxStepCycleCount = 30;
void setup() {
// put your setup code here, to run once:
pinMode(defMotorDn,OUTPUT);
pinMode(defMotorUp,OUTPUT);
pinMode(defButtonManualDn,INPUT_PULLUP);
pinMode(defButtonManualUp,INPUT_PULLUP);
pinMode(defRcDn,INPUT);
pinMode(defRcUp,INPUT);
Serial.begin(9600);
}
void loop() {
//current reading
fActCurrentInput = (analogRead(defACS712));
fCalculatedCurrent = (fActCurrentInput * (5.0 / 1024.0) - 2.5) /0.1; //0.100 V/A
//current limit reading down
fActLimitDnInput = (analogRead(defLimitDn));
fCalculatedLimitDn = (fActLimitDnInput * (7.0 / 1024.0) * -1) /0.1; //negative 0-7A scale
//current limit reading up
fActLimitUpInput = (analogRead(defLimitUp));
fCalculatedLimitUp = (fActLimitUpInput * (7.0 / 1024.0)) /0.1; //0-7A scale
//reading control signals
xDownCommand = !digitalRead(defButtonManualDn) or digitalRead(defRcDn); //Read input and invert state, now it is TRUE when Pressed, and read RcController output
xUpCommand = !digitalRead(defButtonManualUp) or digitalRead(defRcUp); //Read input and invert state, now it is TRUE when Pressed, and read RcController output
if (uiStepper != uiMemStepper) //set uiStepCycles to 0 when stepper change
{
uiStepCycles = 0;
}
if ((uiStepper == uiMemStepper) and (uiStepCycles < iMaxStepCycleCount)) //add every cycle 1 to value uiStepCycles until iMaxStepCycleCount reached to unstress cpu and prevent overflow
{
uiStepCycles += 1;
}
uiMemStepper = uiStepper;
switch (uiStepper){
case 0: // Init/Stop Motor
xMotorUp = false;
xMotorDn = false;
if (xDownCommand == true)
{
uiStepper = 10;
}
else if (xUpCommand == true)
{
uiStepper = 20;
}
break;
case 10: //Motor down
xMotorUp = false;
xMotorDn = true;
if ((uiStepCycles >= iIncorrectMeasurementCycles) and (fCalculatedCurrent < fCalculatedLimitDn)) //Too High negative current, reverse direction!
{
xMotorUp = true;
xMotorDn = false;
uiStepper = 30;
}
else if (xDownCommand == false)// stop motor if no down command given
{
uiStepper = 0;
}
break;
case 20: //Motor Up
xMotorUp = true;
xMotorDn = false;
if ((uiStepCycles >= iIncorrectMeasurementCycles) and (fCalculatedCurrent > fCalculatedLimitUp)) //Too high current, reverse direction!
{
xMotorUp = false;
xMotorDn = true;
uiStepper = 30;
}
else if (xUpCommand == false)// stop motor if no down command given
{
uiStepper = 0;
}
break;
case 30: //Reverse direction
if (uiStepCycles >= iReverseDirectionCycles) //do iReverseDirectionCycles to reverse direction before stop
{
uiStepper = 0;
}
break;
}
//Last Safety Check and inverting output
qxMotorDn = !(xMotorDn and ((uiStepCycles < iIncorrectMeasurementCycles) or (fCalculatedCurrent > fCalculatedLimitDn)));
qxMotorUp = !(xMotorUp and ((uiStepCycles < iIncorrectMeasurementCycles) or (fCalculatedCurrent < fCalculatedLimitUp)));
//Write Motor state to output
digitalWrite(defMotorDn, qxMotorDn);
digitalWrite(defMotorUp, qxMotorUp);
Serial.print("upcommamnd");
Serial.println(xUpCommand);
Serial.print("downcommamnd");
Serial.println(xDownCommand);
Serial.print("uistepper");
Serial.println(uiStepper);
Serial.print("xMotorDn");
Serial.println(xMotorDn);
Serial.print("xMotorUp");
Serial.println(xMotorUp);
Serial.print("qxMotorDn");
Serial.println(qxMotorDn);
Serial.print("qxMotorUp");
Serial.println(qxMotorUp);
Serial.print("uiStepCycles");
Serial.println(uiStepCycles);
Serial.print("torqueUp");
Serial.println(fCalculatedLimitUp);
Serial.print("torqueDn");
Serial.println(fCalculatedLimitDn);
}
What is the thing in the bottom right-hand corner. Post a link to its datasheet. It seems to be fed with a 12v to 5v adapter and by 5v from the Arduino?
Post a link to the datasheet for the 12v to 5v adapter.
The dc regulator in the right-hand corner is just a cheap Chinese regulator (12v to 5v3a). I can't find a datasheet from that but i do have a product page (Robot or human?). In the second attempt i placed this separate regulator (instead of a jumper between jd-vcc and vcc) to opto isolate my 10A 5V 2channel relay (http://modtronix.com/mod-rly2-5v.html). The ACS712 is capable to measure up to 20A and i thought a hall effect sensor would never be able to give a higher voltage than supplied.
I can't see any reason why your Arduino might overheat - but I am not good at spotting that sort of problem without having the problem on my work bench.
Maybe your wiring is ragged and some things are touching that should not be touching.
I think jremington's answer is the solution because a motor driver also prevents the motor to generate energy back to the ground (when mass is moving) by diodes. I think that is happening and this can give the GND and it self temporary also a +12V. I'm going to order a motor driver and see what happens.
I see a CX-12R 433Mhz transceiver module connected to the Nano's 3.3volt pin.
Any idea how much current that module draws.
Seems about the same as the HC-12, which can draw 200mA during transmit.
A Nano has a very weak 3.3volt supply (from the USB<>Serial chip).
30mA is about max I would draw from that pin.
A Nano on 12volt is borderline.
Why don't you power the Nano and the relays from that 5volt buck converter (on the 5volt pin of the Nano).
Leo..
You should never be handling high current on the Arduino board itself - from what I can see you might
be passing the return current from the motors through the Arduino gnd pins? That's very bad.
All high current wiring should be completely separate from the Arduino and sensors etc. There should be a
single shared ground connection between the high current stuff and the low current stuff so no high currents
flow through sensitive areas.
Since i replaced the relay with the motor driver the arduino can endure this. @TomGeorge I can't sent a picture of the mcu anymore because i have trowed the old one away. The linak actuator was actually only the DC motor thence this solution.