Advertisement
sanjiro

Maquina_Cafe_v_18.06.18_beta.ino

Jun 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #include <LiquidCrystal_I2C.h>
  2. #include <Wire.h>
  3. LiquidCrystal_I2C lcd(0x27, 16, 2); // sda to A4 fio laranja
  4. // scl to A5 fio amarelo
  5.  
  6. int ThermistorPin = A0; // blue wire
  7. int Vo;
  8. float R1 = 5000; // 5000 47Kohms
  9. float logR2, R2, T, Tc;
  10. float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
  11. const int ButtonCoffee = 12; // brown wire
  12. const int RelayBoiler = 11; // yellow wire
  13. const int RelayCoffee = 10; // green wire
  14. const int LedPower = 9; // orange wire
  15. int buttonState = 0; // current state of the button
  16. int lastButtonState = 0; // previous state of the button
  17. int ledState = 0; // remember current led state
  18.  
  19. void setup() {
  20.  
  21. lcd.begin();
  22. lcd.backlight();
  23.  
  24. pinMode(ButtonCoffee, INPUT); // brown wire
  25. // resistor is in positive side, "pullup", so RelayCoffee must be low level trigger
  26. pinMode(RelayCoffee, OUTPUT); // green wire
  27. pinMode(RelayBoiler, OUTPUT); // yellow wire
  28. pinMode(LedPower, OUTPUT); // orange wire
  29. digitalWrite (RelayBoiler, LOW);
  30. digitalWrite (RelayCoffee, HIGH); // low level trigger
  31. digitalWrite (LedPower, LOW);
  32. }
  33.  
  34. void loop() {
  35. digitalWrite (LedPower, HIGH);
  36. Boiler();
  37. Coffee();
  38. Error();
  39. }
  40.  
  41. void Boiler() {
  42.  
  43. lcd.setCursor(0,0);
  44. lcd.print("Temperatura: ");
  45. lcd.setCursor(0,1);
  46. lcd.print(Tc,0); //Temp sem decimais
  47. lcd.print(" C ");
  48.  
  49. Vo = analogRead(ThermistorPin);
  50. R2 = R1 * (1023.0 / (float)Vo - 1.0);
  51. logR2 = log(R2);
  52. T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  53. Tc = T - 273.15;
  54. if ( Tc > 0 && Tc < 85 ) // cold
  55. {
  56. digitalWrite (RelayBoiler, HIGH);
  57. }
  58. else if ( Tc > 83 ) // hot
  59. {
  60. digitalWrite (RelayBoiler, LOW);
  61. }
  62. delay(200); // delay between ntc readings
  63. }
  64.  
  65. void Coffee() {
  66. buttonState = digitalRead(ButtonCoffee);
  67. if (buttonState != lastButtonState)
  68. {
  69. if (buttonState == 1)
  70. {
  71. if(ledState == 1) ledState=0;
  72. else ledState=1;
  73. }
  74. lastButtonState = buttonState;
  75. }
  76. digitalWrite(RelayCoffee, ledState);
  77. delay(20); //debouncing
  78. }
  79.  
  80. void Error() {
  81. if ( Tc < 0 ) // error
  82. {
  83. digitalWrite (RelayBoiler, LOW);
  84. digitalWrite (LedPower, LOW);
  85. delay(500);
  86. digitalWrite (LedPower, HIGH);
  87. delay(500);
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement