Guest User

Untitled

a guest
Apr 11th, 2019
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. /*
  2. Thermocouple.
  3.  
  4. Reads a temperature from a thermocouple based
  5. on the MAX6675 driver and displays it in the default Serial.
  6.  
  7. https://github.com/YuriiSalimov/MAX6675_Thermocouple
  8.  
  9. Created by Yurii Salimov, April, 2018.
  10. Released into the public domain.
  11. */
  12. #include <MAX6675_Thermocouple.h>
  13.  
  14. #define SCK_PIN 3
  15. #define CS_PIN 4
  16. #define SO_PIN 5
  17.  
  18. /**
  19. How many readings are taken to determine a mean temperature.
  20. The more values, the longer a calibration is performed,
  21. but the readings will be more accurate.
  22. */
  23. #define READINGS_NUMBER 10
  24.  
  25. /**
  26. Delay time between a temperature readings
  27. from the temperature sensor (ms).
  28. */
  29. #define DELAY_TIME 20
  30.  
  31. MAX6675_Thermocouple* thermocouple = NULL;
  32.  
  33. // the setup function runs once when you press reset or power the board
  34. void setup() {
  35. Serial.begin(9600);
  36. thermocouple = new MAX6675_Thermocouple(
  37. SCK_PIN, CS_PIN, SO_PIN,
  38. READINGS_NUMBER, DELAY_TIME
  39. );
  40. /* or
  41. thermocouple = new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN);
  42. thermocouple->setReadingsNumber(READINGS_NUMBER);
  43. thermocouple->setDelayTime(DELAY_TIME);
  44. */
  45. }
  46.  
  47. // the loop function runs over and over again forever
  48. void loop() {
  49. const double celsius = thermocouple->readCelsius();
  50. const double kelvin = thermocouple->readKelvin();
  51. const double fahrenheit = thermocouple->readFahrenheit();
  52. Serial.print("Temperature: ");
  53. Serial.print(String(celsius) + " C, ");
  54. Serial.print(String(kelvin) + " K, ");
  55. Serial.println(String(fahrenheit) + " F");
  56. delay(500);
  57. }
Add Comment
Please, Sign In to add comment