12v thermostat heater code error


hey all

im having trouble project im doing. meant temperature control 3d print head thats separated printer electrical. first of code adapted greatscotts soldering iron found on instructables, couldn't seem original code work @ , better little better now.


the pot meant set desired temperature, thermo couple (maxx6675) checks temperature of head , arduino meant fire relay turn heater on or off. couple of issues im having code doesn't seem go void loop (the heater turned on in setup , never turns off nor oled display update until press reset button if updatedisplay isn't being read)

code: [select]
#include <spi.h>
#include <wire.h>
#include <max6675.h>
#include <adafruit_gfx.h>
#include <adafruit_ssd1306.h>
#define oled_mosi  11
#define oled_clk   13
#define oled_dc    8
#define oled_cs    10
#define oled_reset 9
#define thermodo 11
#define thermocs 12
#define thermoclk 13
#define potentiometer a3

#define heat 4

float temperature;
int pottemperature;
int counter;
int  heatval = 0;
adafruit_ssd1306 display(oled_mosi, oled_clk, oled_dc, oled_reset, oled_cs);
max6675 thermocouple(thermoclk, thermocs, thermodo);

void setup() {
  display.begin(ssd1306_switchcapvcc);
  pinmode(potentiometer, input);

  pinmode(heat, output);
  digitalwrite(heat, high);
  display.settextsize(1.9);
  display.settextcolor(white);
  counter = 1;
  temperature = thermocouple.readcelsius();
  updatedisplay();
  attachinterrupt(0, zero, 1);
}

void loop() {
}

void zero() {
  counter++;
  if (counter < 2) {
    if (temperature > pottemperature ) {
      digitalwrite(heat,high);
    }
    else {
      digitalwrite(heat, low);
    }
  }

  if (counter == 2) {
    heatval = digitalread(heat);

    detachinterrupt(1);
    temperature = thermocouple.readcelsius();
    updatedisplay();
    counter = 0;
    attachinterrupt(0, zero,1);
  }
}

void updatedisplay() {

  pottemperature = analogread(potentiometer);
  pottemperature = map(pottemperature, 0, 800, 0, 400);
  display.cleardisplay();
  display.setcursor(0, 0);
  display.print("set:");
  display.print(pottemperature);
  display.setcursor(0, 20);
  display.print("tmp:");
  display.print(int(temperature));
  display.display();
 
 
}





this either easy or hard question.
thanks everyone

why using interrupt?


Arduino Forum > Using Arduino > Project Guidance > 12v thermostat heater code error


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts