EMERGENCY!!! MY CODE made my wires melt

#include<Wire.h>
#include <PID_v1.h>

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Define the aggressive and conservative Tuning Parameters
double aggKp=4, aggKi=0.2, aggKd=1;
double consKp=1, consKi=0.05, consKd=0.25;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);

const long interval = 1000;
unsigned long previousMillis = 0;
const int MPU_addr=0x68;
int16_t axis_X,axis_Y,axis_Z;
int minVal=265;
int maxVal=402;
double x;
double y;
double z;
int Stepping = false;
int Stepping1 = false;
void setup(){

pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
//digitalWrite(7, LOW); //clockwise
//digitalWrite(8, HIGH); //clockwise
digitalWrite(3, HIGH); //disable stepper 1
digitalWrite(4, HIGH); //disable stepper 2

pinMode(12, OUTPUT);
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
int xAng = map(axis_X,minVal,maxVal,-90,90);
int yAng = map(axis_Y,minVal,maxVal,-90,90);
int zAng = map(axis_Z,minVal,maxVal,-90,90);
Input = y;
Setpoint = 177;

//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop(){
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true);
axis_X=Wire.read()<<8|Wire.read();
axis_Y=Wire.read()<<8|Wire.read();
axis_Z=Wire.read()<<8|Wire.read();
int xAng = map(axis_X,minVal,maxVal,-90,90);
int yAng = map(axis_Y,minVal,maxVal,-90,90);
int zAng = map(axis_Z,minVal,maxVal,-90,90);

//x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);
y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
//z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);
/Serial.print("Angle of inclination in X axis = ");
Serial.print(x);
Serial.println((char)176);
/
//Serial.print("Angle of inclination in Y axis= ");
//Serial.print(y);
//Serial.println((char)176);
/Serial.print("Angle of inclination in Z axis= ");
Serial.print(z);
Serial.println((char)176);
/
//Serial.println("-------------------------------------------");
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
Serial.println(y);
}
Input = y;
double gap = abs(Setpoint-Input);
if (gap<0){
//this is for led
digitalWrite(7, LOW); //this is for direction pin of stepper 1
digitalWrite(8, HIGH); //this is for direction pin of stepper 2
Stepping = true;

}
else if (gap>10){
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
Stepping = true;
}

else{
Stepping=false;
digitalWrite(12,LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
if (Stepping == true){
digitalWrite(12,HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);

}

}

Call the Firebrigade !

Please edit your post to add code tags.

Then figure out and correct the wiring error.

Maybe also give the pins sensible, meaningful names.

And use Tools + Auto Format to clean up the piss-poor indenting.

And, delete commented out code. It is NOT part of the problem.

Hi,

I hate to say this but if your wires melted then you are very lucky because you found out one of the safety issues when using microcontrollers or really any kind of circuit. You should really design so that if something goes wrong with the microcontroller the circuit doesnt blow up or catch fire. That's a very important design point. That's why they make fuses and other circuit protection devices so that when something goes wrong the simple device prevents catastrophic secondary failures.
The idea is if it does fail then get it to fail silently, with no secondary mishaps such as exploding caps, transistors, etc., and certainly no burnt wiring :slight_smile:

Code doesn't melt wires. You've got something wired badly.

Draw up a full schematic. This probably should be moved to General Electronics.

This probably should be moved to General Electronics.

But it's fun to bash OP here. 8)

And why is it a 'Emergency' ?

Did you leave it all connected to the power, melting wires, catching fire etc, and hoped you could modify the code in time to stop the impending disaster ?

Or did you simply disconnect the power ?

And why is it a 'Emergency' ?

Sadly, it appears that forum members did not respond quickly enough. We may have lost another one...

Thanks for the reply people:), i thought i had to wait a day or two for an answer; nobody replying my other post:(

#include<Wire.h>
#include <PID_v1.h>

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Define the aggressive and conservative Tuning Parameters
double aggKp=4, aggKi=0.2, aggKd=1;
double consKp=1, consKi=0.05, consKd=0.25;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);

const long interval = 1000;          //interval used to read serial print reading without using delay
unsigned long previousMillis = 0; //serial print without delay
const int MPU_addr=0x68;          //MPU reading?
int16_t axis_X,axis_Y,axis_Z;      //MPU reading
int minVal=265;                         //MPU reading
int maxVal=402;                        //MPU reading
double x;                                   //X reading of MPU
double y;                                   //Y reading of MPU
double z;                                   //Z reading of MPU
int Stepping = false;                  //stop stepper from stepping for first stepper
int Stepping1 = false;                //stop stepper from stepping for second stepper
void setup(){

   
   pinMode(8, OUTPUT);              //dir pin for stepper 1
   pinMode(7, OUTPUT);              //dir pin for stepper 2
   pinMode(3, OUTPUT);              //ena pin for stepper 1
   pinMode(4, OUTPUT);              //ena pin for stepper 2
  
  digitalWrite(3, HIGH);              //disable stepper 1
  digitalWrite(4, HIGH);              //disable stepper 2
  
  
  
  pinMode(12, OUTPUT);             //LED pin
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(9600);
  int xAng = map(axis_X,minVal,maxVal,-90,90);
  int yAng = map(axis_Y,minVal,maxVal,-90,90);
  int zAng = map(axis_Z,minVal,maxVal,-90,90);   //after pinmode to here is all to set up the mpu values
  Input = y;                                                        //PID input
  Setpoint = 177;                                                //PID set point

  //turn the PID on
  myPID.SetMode(AUTOMATIC);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);
  axis_X=Wire.read()<<8|Wire.read();
  axis_Y=Wire.read()<<8|Wire.read();
  axis_Z=Wire.read()<<8|Wire.read();
  int xAng = map(axis_X,minVal,maxVal,-90,90);
  int yAng = map(axis_Y,minVal,maxVal,-90,90);
  int zAng = map(axis_Z,minVal,maxVal,-90,90);  //reading mpu readings
    
    
      
         y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);  //y is value converted to degrees
       
     unsigned long currentMillis = millis();
      if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    Serial.println(y);                                                   //serial print the value
      }
Input = y;      
double gap = abs(Setpoint-Input);     
if (gap<0){
                 //this is for led   
              digitalWrite(7, LOW);    //this is for direction pin of stepper 1
              digitalWrite(8, HIGH);   //this is for direction pin of stepper 2
              Stepping = true;
              
            }
else if (gap>10){
  digitalWrite(7,HIGH);
  digitalWrite(8,LOW);
  Stepping = true;
}
            
      else{
        Stepping=false;
        digitalWrite(12,LOW);
        digitalWrite(3, HIGH);
        digitalWrite(4, HIGH);
      }
     if (Stepping == true){
      digitalWrite(12,HIGH);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
       
      
      } 

            }

please help me ty

People reply to questions that they have knowledge of; I will e.g. stay away from PID in the context of control.

You were asked to draw a schematic and post it; please do so. It can be a scan / photo of a hand-drawn one.

Next check, double check etc your schematic to make sure it is what you want it to be and next check and double/triple check the wiring against the schematic to make sure it is correct.

Thanks for the reply people:), i thought i had to wait a day or two for an answer; nobody replying my other post:(

You have to ask the question first. Topic title sound to me like announcement even though I have to admit very interesting in contrast to others. I was curious how to melt the wires with code. I would like to try it in my laboratory. :o
So ask the question, otherwise Gabriel henceforward stay lost.