Advertisement
pleasedontcode

"Smart Monitoring" rev_02

Jan 1st, 2024
93
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: "Smart Monitoring"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-01 12:28:36
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Measures temperature     If temperature is greater */
  21.     /* than 27 degrees celsius print "high temp" and turn */
  22.     /* on red LED    if temperature is less than 25 */
  23.     /* degrees celsius print "low temp" and turn on blue */
  24.     /* LED    create this in a function called water_temp */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* Measure distance     If distance is greater than */
  27.     /* 30 cm print "water overflow " and turn buzzer on */
  28.     /* If distance is less than 15 cm print "water */
  29.     /* underflow " and turn buzzer on     create this in */
  30.     /* a function called water_level */
  31. /****** END SYSTEM REQUIREMENTS *****/
  32.  
  33. /****** DEFINITION OF LIBRARIES *****/
  34. #include <Arduino.h>
  35. #include <DHT.h>
  36. #include <Ultrasonic.h>
  37.  
  38. /****** FUNCTION PROTOTYPES *****/
  39. void setup(void);
  40. void loop(void);
  41. void water_temp(void);
  42. void water_level(void);
  43.  
  44. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  45. const uint8_t mydht_DHT11_DOUT_PIN_D2 = 2;
  46. const uint8_t myUS_HC_SR04_Echo_PIN_D4 = 4;
  47.  
  48. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  49. const uint8_t myUS_HC_SR04_Trigger_PIN_D3 = 3;
  50.  
  51. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  52. DHT dht(mydht_DHT11_DOUT_PIN_D2, DHT11);
  53. Ultrasonic ultrasonic(myUS_HC_SR04_Trigger_PIN_D3, myUS_HC_SR04_Echo_PIN_D4);
  54.  
  55. void setup(void)
  56. {
  57.   // put your setup code here, to run once:
  58.   pinMode(mydht_DHT11_DOUT_PIN_D2, INPUT_PULLUP);
  59.   pinMode(myUS_HC_SR04_Echo_PIN_D4, INPUT);
  60.   pinMode(myUS_HC_SR04_Trigger_PIN_D3, OUTPUT);
  61. }
  62.  
  63. void loop(void)
  64. {
  65.   // put your main code here, to run repeatedly:
  66.   water_temp();
  67.   water_level();
  68. }
  69.  
  70. void water_temp(void)
  71. {
  72.   float temp = dht.readTemperature();
  73.  
  74.   if (temp > 27)
  75.   {
  76.     Serial.println("High temperature");
  77.     // Turn on red LED
  78.   }
  79.   else if (temp < 25)
  80.   {
  81.     Serial.println("Low temperature");
  82.     // Turn on blue LED
  83.   }
  84. }
  85.  
  86. void water_level(void)
  87. {
  88.   unsigned int distance = ultrasonic.read();
  89.  
  90.   if (distance > 30)
  91.   {
  92.     Serial.println("Water overflow");
  93.     // Turn on buzzer
  94.   }
  95.   else if (distance < 15)
  96.   {
  97.     Serial.println("Water underflow");
  98.     // Turn on buzzer
  99.   }
  100. }
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement