I am trying to make closed loop a automatic temp controller to heat a thin metal plate using a buck converter, max6675 thermocouple module for temp sensing and a 250 watt halogen lamp. I am giving 10khz pwm signal from pin 9 to IRF540 mosfet and powering the max6675 using 5v and gnd available in arduino. My whole setup worked totally fine a few days ago but when I tried to run the same code again next day, it didn't work. I am facing these issues now:

  1. For troubleshooting I first tried to run buck only at 50% duty cycle to check if it's working properly or not. It's working totally fine but whenever I insert gnd wire of max6675 into gnd pin of Arduino, brightness of bulb decreases suddenly and MOSFET in buck starts heating a lot. I don't know why this is happening. MOSFET is heating only when I insert gnd wire of max6675 into arduino. max6675

  2. Whenever I start serial monitor to see if anything is happening, it somehow starts interfering in the code of my closed loop. I have coded to print two things on serial monitor temp and pwm duty cycle. When it shows temp then duty cycle is zero and if it shows duty cycle then temp shows zero but most of the time both are zero. If bulb starts glowing and I open serial monitor then it switches off the bulb.

I am attaching my code for closed loop programmer. I don't know why this is happening.

#include <PID_v1.h>
#include "max6675.h"
#include <TimerOne.h>

double Setpoint, Input, Output;
int soPin = 4;
int csPin = 5;
int sckPin = 6;

MAX6675 robojax(sckPin, csPin, soPin);

double Kp=.5, Ki=.2, Kd=0;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

void setup()


  Input =robojax.readCelsius() ;
  Setpoint = 100;


void loop()
  Input = robojax.readCelsius();
  Output = map(Output, 0, 255, 0, 1024);
  if( Output< 0)
  {    Output = 0;    }
  if(Output > 950)  
  {    Output = 950;  }

  Timer1.pwm(9, Output);



I am also attaching a crude schematic of my circuit. Someone told me to isolate the gnd of max6675 and mosfet pwm signal gnd. Is it feasible?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.