elektronek

Tomáš Nechyba - udirna

Apr 13th, 2021 (edited)
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2. #include <LiquidCrystal.h>
  3. #include <OneWire.h>
  4. #include <DallasTemperature.h>
  5.  
  6. // Data wire is plugged into port 2 on the Arduino
  7. #define ONE_WIRE_BUS 7
  8.  
  9. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  10. OneWire oneWire(ONE_WIRE_BUS);
  11.  
  12. // Pass our oneWire reference to Dallas Temperature.
  13. DallasTemperature sensors(&oneWire);
  14.  
  15. LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //sets the LCD pins
  16.  
  17. int teplota = 0;
  18. Servo servo_9;
  19.  
  20. void setup()
  21. {
  22.   Serial.begin(9600);//begins serial interface
  23.   lcd.begin(16, 2);
  24.   lcd.setCursor(0, 0);
  25.   lcd.print("Teplomer");
  26.   sensors.begin();
  27.   servo_9.attach(9, 500, 2500);
  28.   pinMode(6, OUTPUT);
  29. }
  30.  
  31. void loop()
  32. {
  33.   sensors.requestTemperatures();
  34.   teplota = sensors.getTempCByIndex(0);
  35.  
  36.   Serial.println(teplota);
  37.   lcd.setCursor(0, 1);
  38.   lcd.print(teplota);
  39.   lcd.print(" C ");
  40.   if (teplota > 80) {
  41.     servo_9.write(1);
  42.   } else {
  43.     if (teplota <= 80) {
  44.       servo_9.write(10);
  45.     } else {
  46.       servo_9.write(0);
  47.     }
  48.     if (teplota <= 78) {
  49.       servo_9.write(20);
  50.     }
  51.     if (teplota <= 75) {
  52.       servo_9.write(35);
  53.     }
  54.     if (teplota <= 73) {
  55.       servo_9.write(45);
  56.     }
  57.     if (teplota <= 70) {
  58.       servo_9.write(50);
  59.     }
  60.     if (teplota <= 65) {
  61.       servo_9.write(80);
  62.     }
  63.   }
  64.   if (teplota < 60) {
  65.     analogWrite(6, 20);
  66.   } else {
  67.     analogWrite(6, 0);
  68.   }
  69.   delay(500);
  70. }
Add Comment
Please, Sign In to add comment