i will elaborate as much as i can.
6 volts from power supply into v+ in/v- in of the irf520 mosfet
v+ out and v- out from irf520 mosfet go into the red wire of the iron (heater) and black wire of the iron (ground)
the thermocouple max6675 + connection is connected to the blue wire of the iron (heat sensor) and the - connection is connected to the same black wire of the iron (ground) as the wire used for V- out of the mosfet
the code basically sends a HIGH signal to the SIG pin of the mosfet to turn on power to the iron, when this happens the temperature read is zero. when i switch off the power supply to the mosfet input completely the thermocouple read the iron temperature ok. if i measure the voltage while the mosfet signal is LOW i can still see there is voltage but i can't work out why that is since the mosfet is supposed to be turning off output voltage when in LOW. i guess my problem is while there is current to the heater i cannot read the temperature and i am not able to switch off current to the iron completely using the mosfet. I must be doing something wrong. There are tons of projects online from people who built soldering stations.
below is my code:
//-- Libraries include
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "max6675.h" //thermocouple driver
#include "sav_button.h" //buttons library
#include "EEPROM.h" //Memory Storage
#include <SoftPWM_timer.h>
//-- Libraries definition
//-- MAX6675 Thermocouple driver------------
const byte pinTcSO = 7;
const byte pinTcCS = 8;
const byte pinTcCLK = 9;
// -- movement sensor
const byte pinTilt = 12;
MAX6675 tc(pinTcCLK, pinTcCS, pinTcSO);
//-- PushButtons-----------------------------
const byte pinButtonUp = 4;
const byte pinButtonDown = 5;
const byte pinButtonOk = 6;
SButton Up (pinButtonUp, 50, 0, 800, 100);
SButton Down (pinButtonDown, 50, 0, 800, 100);
SButton Ok (pinButtonOk, 50, 1000, 4000, 250);
//-- Types definition
enum myUnits {
CELSIUS,
PERCENT
};
//-- Constatnts definition
#define control 13 // pin that controls the MOSFET
const uint16_t minTemp = 50;//temperature minimum
const uint16_t maxTemp = 500;//temperature maximum
const uint16_t measInterval = 500; //measurement interval ms. Must be over 500
const uint16_t readInterval = 10000; //measurement interval ms. Must be over 500
const uint16_t measSleep = 60000;
const byte shortPressStep = 1; //temperature change step on button's short press
const byte autoPressStep = 5; //temperature change step on button's long press
const int tempAddr = 0; // eeprom addresses
//-- Variables definition
uint16_t reqTemp = 60; //required temperature(celsius) from minTemp to maxTemp in temperature mode
uint16_t standbyTemp = 100;
uint16_t lastTemp;
uint16_t temp; //Heater temperature
uint32_t measTime = millis();
uint32_t readTime = measTime;
uint32_t sleepTime = measTime;
boolean isChanged = false; // is any changes
boolean standBy = true; //standby mode on/off
boolean heatingOn = false;
char messageLine1[21];
char messageLine2[21];
#define SCREEN_ADDRESS 0x27 ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
LiquidCrystal_I2C display(SCREEN_ADDRESS, 16, 2);
void displayTemp(){
display.setCursor(0, 0);
sprintf(messageLine1, "%s ", "TMP:");
display.print(messageLine1);
display.setCursor(8, 0);
sprintf(messageLine1, "%i%c ", temp, (char)223);
display.print(messageLine1);
display.setCursor(0, 1);
sprintf(messageLine2, "%s ", "SET:");
display.print(messageLine2);
display.setCursor(8, 1);
sprintf(messageLine2, "%i%c ", reqTemp, (char)223);
display.print(messageLine2);
}
void displayText(String text, boolean showTemp){
display.setCursor(0, 0);
sprintf(messageLine1, "%-17s", text.c_str());
display.print(messageLine1);
display.setCursor(0, 1);
if (showTemp){
sprintf(messageLine2, "%s ", "TMP:");
display.print(messageLine2);
display.setCursor(8, 1);
sprintf(messageLine2, "%i%c ", temp, (char)223);
display.print(messageLine2);
}else{
display.print(F(" "));
}
}
// Read config from EEPROM
void readConf(){
uint16_t t;
EEPROM.get(tempAddr, t);
if (minTemp<=t && t<=maxTemp) reqTemp = t;
}
//save config to EEPROM
void saveConf(){
EEPROM.put(tempAddr, reqTemp);
displayText("Saved.", false);
isChanged = false;
delay(3000);
}
//set iron temperature
void setTemp(){
if (temp>=reqTemp){
digitalWrite(control,LOW); // Turn the MOSFET Switch OFF
heatingOn = false;
Serial.println("powering off heater ...");
}else {
digitalWrite(control,HIGH); // turn the MOSFET Switch ON
heatingOn = true;
Serial.println("powering on heater ...");
}
}
void unitsUp(byte vStep){
if ((reqTemp + vStep) <= maxTemp) {
reqTemp += vStep;
isChanged = true;
}
}
void unitsDown(byte vStep){
if ((reqTemp - vStep) >= minTemp) {
reqTemp -= vStep;
isChanged = true;
}
}
void standByMode(){
lastTemp = reqTemp;
reqTemp = standbyTemp;
standBy = true;
}
void setup() {
Serial.begin(9600);
pinMode(pinTilt, INPUT_PULLUP);
pinMode(control,OUTPUT);// define control pin as output
Up.begin();
Down.begin();
Ok.begin();
readConf();
display.init();
display.backlight();
//---- Soft PWM-----------------------------------
digitalWrite(control,LOW); // turn the MOSFET Switch ON
//------------------------------------------------
standByMode();
}
void loop() {
if ((millis()-readTime) > readInterval){
Serial.println("checking iron state ...");
readTime = millis();
if (heatingOn == true){
heatingOn = false;
//SoftPWMSet(pinHeater, 0);
digitalWrite(control,LOW); // Turn the MOSFET Switch OFF
Serial.println("turning off iron for reading temp ...");
}else{
temp = tc.readCelsius();
Serial.print("Temp=");
Serial.println(temp);
heatingOn = true;
digitalWrite(control,HIGH); // Turn the MOSFET Switch ON
//SoftPWMSet(pinHeater, 255);
}
}
if ((millis()-measTime) > measInterval){
//temp = tc.readCelsius();
//temp = 200;
measTime = millis();
//setTemp();
if (digitalRead(pinTilt) == LOW){
Serial.println("iron on");
reqTemp = lastTemp;
sleepTime = millis();
standBy = false;
}else{
if ((millis()-sleepTime) > measSleep && standBy == false){
sleepTime = millis();
standByMode();
Serial.println("SLEEPING...");
}
}
if (standBy == false){
displayTemp();
}else{
displayText("STANDBY...", true);
}
}
switch (Up.Loop())
{
case SB_CLICK:
if (standBy == true)
{
reqTemp = lastTemp;
}
sleepTime = millis();
standBy = false;
unitsUp(shortPressStep);
break;
case SB_AUTO_CLICK:
if (standBy == true)
{
reqTemp = lastTemp;
}
sleepTime = millis();
standBy = false;
unitsUp(autoPressStep);
break;
case SB_NONE:
break;
case SB_LONG_CLICK:
break;
}
switch (Down.Loop())
{
case SB_CLICK:
if (standBy == true)
{
reqTemp = lastTemp;
}
sleepTime = millis();
standBy = false;
unitsDown(shortPressStep);
break;
case SB_AUTO_CLICK:
if (standBy == true)
{
reqTemp = lastTemp;
}
sleepTime = millis();
standBy = false;
unitsDown(autoPressStep);
break;
case SB_LONG_CLICK:
break;
case SB_NONE:
break;
}
switch( Ok.Loop() ){
case SB_CLICK:
if (standBy==false && isChanged==true){
saveConf();
}
break;
case SB_LONG_CLICK:
standBy = !standBy;
if (standBy == false){
displayText("Powering on...", false);
reqTemp = lastTemp;
sleepTime = millis();
delay(3000);
}else{
standByMode();
}
break;
case SB_AUTO_CLICK:
break;
case SB_NONE:
break;
}
}
link to the schematic https://hacksterio.s3.amazonaws.com/uploads/attachments/384645/solder_station-13d13ff34fdb4191a518450565d8851d_Mi0esKciMT.png