Thermocouple Project: Converting Arduino code to Spark and Other Stuff

Hi everyone,

I’m fairly new to coding, and I was wondering if there is anything I have to do to make a code that originated in Arduino work in Spark. The project I am working on is supposed to be able to tell when a machine is on (by sensing a temperature increase) and send that data to a website. It does this by having two thermocouples (One measuring ambient temperature of the room, and the other against the wire to the machine) and send data through the amplifiers, then to the spark and so on.

The actual electronics in this “package” include two lengths of K-type thermocouple, which in turn are attached to two MAX31855 amplifiers (These amplifiers are not connected to each other!). The amplifiers are connected to the Spark Core in this arrangement:

Amp 1 (Amplifier’s port on left, Spark’s on the right)
Vin > 3v3
GND> 3v3
DO> D5
CS> D4

Amp 2
Vin > 3v3
GND> 3v3
DO> D2
CS> D1

(The Vin and GND ports on the Amplifier go to one 3v3 port on the Spark, as the wiring is in a “Y”)

Now for the programming:
Is there any right way of adding a library? When I selected a library in the Build page, I just clicked on “libraries” then found the MAX31855 file and clicked add to application. Is this the correct way of doing this?

Also, how should I reconfigure my program (And possibly design) to account for the different ports on the spark, as originally, this project was prototyped on a Arduino Uno, connected to a wifi shield and DIY amplifier (Too bulky, in other words).

Finally, what method and how can I send this data to a website? I’ll copy/paste my program below.

(Couldn’t paste library, but it’s inside the library tab on the build page. Sorry!)

int thermoDO = 6;
int thermoCS1 = 2;
int thermoCS2 = 3;
int thermoCLK = 5;

Adafruit_MAX31855 thermocouple1(thermoCLK, thermoCS1, thermoDO);
Adafruit_MAX31855 thermocouple2(thermoCLK, thermoCS2, thermoDO);

void setup() {

  Serial.println("MAX31855 test");
  // wait for MAX chip to stabilize

void loop() {
  // basic readout test, just print the current temp
  Serial.print("Internal Temp1 = ");
  Serial.print("Internal Temp2 = ");

  double c = thermocouple1.readCelsius();
  double c2 = thermocouple2.readCelsius();
  if (isnan(c)) {
    Serial.println("Something wrong with thermocouple!");
  else {
    Serial.print("C1 = "); 
    Serial.print("C2 = "); 
  //Serial.print("F = ");


As you can see, the program is still incomplete, so feel free to suggest ideas, or change/add to it. While based on the arduino, it did take the temperatures correctly but could only transmit data to a terminal via a wired connection. Once again, any help is appreciated and I apologize on the n00biness. :smiley: Thanks!

1 Like

If you take a look at the tutorials section of the forum, you’ll find a couple of nice ones which explain how to get your data accessible from the web. This could be done nicely by Spark variables (polling) or even better, by Spark publish (SSE, thus live).
Check it out, I’m sure you’ll find some useful info.
I guess some of the elites can help you further with the more technical stuff :slight_smile:

Good luck, and let us know if you need any more help!

(Would be nice if you could enclose your code between ’ ccp <code> ', which will make it more readable on the forum. Thanks!)


The Shield Shield was made specifically for making Arduino projects plug-n-play for the Spark Core.

You can take a look at the port mappings from here to get suggestions on how to map the ports in your code to Spark Core ports. That should be all it takes.

As for the libraries, yes that is how you add a library to a project on the Spark Web IDE. You might want to check out this github repository from Adafruit for the actual setup() & loop() code to use with these sensors. You can cut and paste that into your main.ino window and write extra code for your second thermocouple.

You can read the values from a webpage using Spark.publish() pretty easily like @Moors7 mentioned.

1 Like