2

Results of both K-Thermocouple by itself and the whole circuit togetherA diagram of my circuitI have a setup where the Arduino reads input from the k-thermocouple and uses that info to regultate the an output voltage through a potentiometer. I know the potentiometer is not faulty because able to read the output from the wiper when I run the program but for some reason, k-thermocouple is stuck at 0 Celsius. I know that the k-thermocouple is not faulty either because it works accordingly when I run a program specifically by itself.

Does anybody know why there is a problem with how the k-thermocouple is operating in junction with the potentiometer? Here is a declarations of my program.

#include <SPI.h>

// K-couple dependent DigiPot Regulator

#include "SPI.h"
#include "max6675.h"

byte address = 0x10;
int CLK = 13;
int CS = 10;
int SDI = 11;
const int ktcSO = 12;
int ktcCS = 9;
int ktcCLK = 13;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);


int digitalPotWrite(int value) //Everything that happens when the DigiPot is 
called
{
  digitalWrite(CS, LOW); // Chip Select is ACTIVE LOW (so now it's selected)
  SPI.transfer(address);
  SPI.transfer(value);
  digitalWrite(CS, HIGH);
}

void setup() 
{
  SPI.begin();
  pinMode (CLK, OUTPUT);
  pinMode (CS, OUTPUT);
  pinMode (SDI, OUTPUT);
  Serial.begin(9600);
  // give the MAX a little time to settle
  delay(500);
}

void loop() 
{
  if (ktc.readFahrenheit() < 60)  // While it's still in Safe Zone
  {
    digitalPotWrite(255);
    // Show the current temp in C and F
    Serial.print("Deg C = "); 
    Serial.print(ktc.readCelsius());
    Serial.print("\t Deg F = ");
    Serial.print(ktc.readFahrenheit());
    int sensorValue = analogRead(A0);
    float voltage = sensorValue * (5.0 / 1023.0);
    Serial.print("\t V = ");
    Serial.println(voltage);
    int clockValue = analogRead(A1);
    Serial.print("\t Clock = ");
    Serial.println(clockValue);
  }
        if (ktc.readFahrenheit() < 65) // While in Caution Zone
        digitalPotWrite(51);
        else if (ktc.readFahrenheit() < 70)
        digitalPotWrite(102);
        else if (ktc.readFahrenheit() < 75)
        digitalPotWrite(153);
        else if (ktc.readFahrenheit() < 78)
        digitalPotWrite(184);
        else if (ktc.readFahrenheit() < 80) //Getting into Danger Zone
        digitalPotWrite(204);
        else if (ktc.readFahrenheit() < 81)
        digitalPotWrite(214);
        else if (ktc.readFahrenheit() < 82)
        digitalPotWrite(224);
        else if (ktc.readFahrenheit() < 83)
        digitalPotWrite(235);
        else if (ktc.readFahrenheit() < 84)
        digitalPotWrite(245);
        else (ktc.readFahrenheit() < 85); //Complete Shutoff 
        digitalPotWrite(255);
    {
     Serial.print("Deg C = "); 
     Serial.print(ktc.readCelsius());
     Serial.print("\t Deg F = ");
     Serial.print(ktc.readFahrenheit());
     int sensorValue = analogRead(A0);
     float voltage = sensorValue * (5.0 / 1023.0);
     Serial.print("\t V = ");
     Serial.println(voltage);
     int clockValue = analogRead(A1);
     Serial.print("\t Clock = ");
     Serial.println(clockValue);
    }
}

Also, the code I used to test the K-Thermocouple is one that can be found on the internet (with just a little bit of adjustments)...

// Sample Arduino MAX6675 Arduino Sketch

#include "max6675.h"

int ktcSO = 12;
int ktcCS = 9;
int ktcCLK = 13;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);


void setup() {
  Serial.begin(9600);
  // give the MAX a little time to settle
  delay(500);
}

void loop() {
  // basic readout test

   Serial.print("Deg C = "); 
   Serial.print(ktc.readCelsius());
   Serial.print("\t Deg F = ");
   Serial.println(ktc.readFahrenheit());
   int clockValue = analogRead(A1);
    Serial.print("\t Clock = ");
    Serial.println(clockValue);

   delay(500);
}
  • Please edit your question to include a circuit diagram. Which lines do you have pullups on? What do you have connected to MISO, dig. pin 12? Do you have an oscilloscope to check the clock signal during temperature reads, or to check data bits at MISO during reads? – James Waldby - jwpat7 Apr 25 '17 at 0:01
  • Yes, I have MISO connected to pin 12. When I run a program to test the K-Thermocouple itself, I do get a square wave clock signal on the oscilloscope but then when I run the program above, the clock signal is indiscernible. It looks like a complete noise. – Kofi May 4 '17 at 18:10
  • What's attached to A1? Why is clockValue reading differently in the two sketches? – James Waldby - jwpat7 May 8 '17 at 16:46
  • I think that may be the cause of my problem. When I had it hooked up to an oscilloscope, I was getting a pulse wave for the first one but the second one was complete static and indiscernible. This is what leads me to believe that the issue is rooted from the CLK signal of SPI with both the K-Thermocouple and the DigiPot in conjunction. – Kofi May 9 '17 at 3:45
1

The wiring diagram, if accurate, shows a couple of problems.

First, A0 has nothing attached to it, so sensorValue may read in as zero or some small random number.

Second, attaching the digital pot's analog output pin 6, P1W, to the Uno's digital input pin 12 is pointless. Instead connect P1W to whatever it is supposed to control. If you want to handle data from the MCP42X1, connect its pin 13, SDO, to an Uno input.

However, neither of those problems appears to be related to misreading the MAX6675 temperature. I don't know of a good approach to solving that problem, but if I were working with the circuit, would remove the wire between P1W and the Uno's digital pin 12, and would use 12 as the input from the MAX6675; that is, would wire it to d12 instead of d8, and instead of int ktcSO = 8 would say const int ktcSO = 12. Also, I'd probably replace the bit of code

  }
  else
  {
    while (ktc.readFahrenheit() < 85) 
      {

with just a closing }. In the Arduino paradigm, loop() runs repeatedly, and the if–else sequence adequately guards each of the digitalPotWrite() calls.

Note, the digitalPotWrite() function should be defined or declared before any calls to it appear. Instead of placing that function at the end, put it before loop() or before setup().

  • My mistake on the A0. I originally had it there and switched it to D12 sometime during my troubleshooting process. One question tho... I'm assuming your're saying I should replace the highlighted portion with "} loop()" but wouldn't the program get stuck in loop the moment it enters it? – Kofi May 6 '17 at 2:44
  • Looks like I read it wrong. No additional loop. – Kofi May 6 '17 at 2:51
  • jwpat7 So I've applied all the changes that you suggested and the MAX6675 is still not registering any input. Side note: I have P1W connected to A0 so that I can monitor my output and also don't pay any mind to Vdd and Vss. I have them correctly connected in my circuit. – Kofi May 6 '17 at 3:23
  • I added a few lines of code to try and show the clock signals (D13 <--> pin 2) of the MAX6675 when tested by itself and the whole circuit. There is some form of signal output every loop for the MAX6675 test itself but there is no signal when tested for the whole circuit. – Kofi May 6 '17 at 4:01
  • The reason for replacing those five lines of code is that (1) your program will get stuck in the while (ktc.readFahrenheit() < 85) loop if readFahrenheit() isn't working or if you aren't changing the temperature at the sensor. If it's stuck in that while loop, it won't produce any output. And (2), decoupling the rest of loop() from its first 15 lines simplifies figuring out what it is doing. – James Waldby - jwpat7 May 6 '17 at 4:17

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.