Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2022
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=================================================================
  2. //                  INIT
  3. //=================================================================
  4. #include <Wire.h>
  5. #include <LiquidCrystal_I2C.h>
  6.  
  7. LiquidCrystal_I2C lcd(0x27, 16,2); //
  8.  
  9. const int LED_RED=10;
  10. const int LED_GREEN=11;
  11. const int RELAY=12;
  12.  
  13. //buttons for up and down
  14. const int up_key=3;
  15. const int down_key=2;
  16.  
  17. int SetPoint=28;
  18. int heater = 0;
  19.  
  20. unsigned long previousMillis = 0;
  21. const long interval = 300000;  // 5 minutes
  22. //=================================================================
  23. //                  SETUP
  24. //=================================================================
  25. void setup(){
  26.   Serial.begin(9600);
  27.   //Serial.print("boot \n");
  28.   pinMode(LED_RED,OUTPUT);
  29.   pinMode(LED_GREEN,OUTPUT);  
  30.   pinMode(RELAY,OUTPUT);  
  31.   pinMode(up_key,INPUT);
  32.   pinMode(down_key,INPUT);
  33.  
  34.   digitalWrite(up_key,HIGH);
  35.   digitalWrite(down_key,HIGH);
  36.  
  37.   lcd.init();
  38.   lcd.backlight();
  39.    
  40.   digitalWrite(LED_GREEN,HIGH);  //Green LED Off
  41.   digitalWrite(LED_RED,LOW);     //Red LED On
  42.   digitalWrite(RELAY,LOW);       //Turn off Relay
  43.   delay(2000);
  44.   lcd.clear();
  45.  
  46.   //add special char °
  47.   byte Celsius[8] = {B11100,B10100,B11100,B0000,B00000,B00000,B00000,B00000};
  48.   lcd.createChar(0, Celsius);
  49.  
  50.  
  51. }
  52. //=================================================================
  53. //                  LOOP
  54. //=================================================================  
  55. void loop(){
  56.   double Temperature = ((5.0/1024.0) * analogRead(A0)) * 10;
  57.  
  58.   lcd.setCursor(0,0);
  59.  
  60.   lcd.print("T.  IST: ");    
  61.   //Serial.print("T.  IST: ");
  62.  
  63.   //Serial.print(Temperature);
  64.   //Serial.print('\n');
  65.   lcd.print(Temperature, 0);
  66.  
  67.   lcd.write((uint8_t)0);
  68.   //Serial.print(" C");
  69.   lcd.print("C");
  70.  
  71. //key input
  72.   if(digitalRead(down_key)==LOW)
  73.   {
  74.     if(SetPoint>0)
  75.     {
  76.       SetPoint--;    
  77.     }
  78.   }
  79.   if(digitalRead(up_key)==LOW)
  80.   {
  81.     if(SetPoint<150)
  82.     {
  83.       SetPoint++;
  84.     }
  85.   }
  86.  
  87. //Display Set point on LCD
  88.   lcd.setCursor(0,1);
  89.   lcd.print("T. SOLL: ");
  90.   //Serial.print("T. SOLL: ");
  91.  
  92.   lcd.print(SetPoint);
  93.   //Serial.print(SetPoint);
  94.  
  95.   lcd.write((uint8_t)0);
  96.   //Serial.print(" C");
  97.   lcd.print("C");
  98.  
  99. //Check Temperature is in limit
  100. unsigned long currentMillis = millis();
  101.  
  102.   if (currentMillis - previousMillis >= interval) {
  103.     previousMillis = currentMillis;
  104.  
  105.     if(Temperature > SetPoint)
  106.     {
  107.        digitalWrite(RELAY,LOW);    //Turn off heater
  108.        digitalWrite(LED_RED,LOW);
  109.        digitalWrite(LED_GREEN,HIGH);  //Turn on Green LED
  110.        
  111.       Serial.print("Turn off heater \n");
  112.     }
  113.     else
  114.     {
  115.       digitalWrite(RELAY,HIGH);    //Turn on heater
  116.       digitalWrite(LED_GREEN,LOW);
  117.       digitalWrite(LED_RED,HIGH);  //Turn on RED LED  
  118.      
  119.       Serial.print("Turn on heater \n");
  120.     }
  121.   }
  122.  
  123.     delay(100); //Update at every 100mSeconds
  124. }
  125. //=================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement