Advertisement
pleasedontcode

homeAutomation rev_49

Nov 15th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: homeAutomation
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-15 23:44:57
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <DS18B20.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. /* If temperature gets above 10°C, the buzzer will sound. */
  24.  
  25. /****** FUNCTION PROTOTYPES *****/
  26. void setup();
  27. void loop();
  28.  
  29. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  30. const uint8_t temperatureSensor_DS18B20_DQ_PIN_D2 = 2;
  31. const uint8_t buzzerPin = 3;
  32.  
  33. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  34. DS18B20 ds(temperatureSensor_DS18B20_DQ_PIN_D2);
  35.  
  36. void setup()
  37. {
  38.   // Set pin modes
  39.   pinMode(temperatureSensor_DS18B20_DQ_PIN_D2, INPUT);
  40.   pinMode(buzzerPin, OUTPUT);
  41. }
  42.  
  43. void loop()
  44. {
  45.   // Read temperature from DS18B20 sensor
  46.   float temperature = ds.getTempC();
  47.  
  48.   // Check if temperature is above 10°C
  49.   if (temperature > 10)
  50.   {
  51.     // Sound the buzzer
  52.     digitalWrite(buzzerPin, HIGH);
  53.   }
  54.   else
  55.   {
  56.     // Turn off the buzzer
  57.     digitalWrite(buzzerPin, LOW);
  58.   }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement