Advertisement
pleasedontcode

Sensor Monitoring rev_02

Jan 1st, 2024
96
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: Sensor Monitoring
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-01 13:09:29
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Ultrasonic sensor Measures distance If distance is */
  21.     /* greater than 30 cm print "water overflow " and */
  22.     /* turn buzzer on If distance is less than 15 cm */
  23.     /* print "water underflow " and turn buzzer on create */
  24.     /* this in a function called water_level. */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* DHT11 sensors measures temperature   If temp is */
  27.     /* greater than 27 degrees celsius print "high temp" */
  28.     /* and turn red led on. If temp is less than 25 */
  29.     /* degrees celcius print "low temp" and turn blue led */
  30.     /* on. Create this in a function called "water_temp" */
  31. /****** END SYSTEM REQUIREMENTS *****/
  32.  
  33. /****** DEFINITION OF LIBRARIES *****/
  34. #include <Arduino.h>
  35. #include <Ultrasonic.h>
  36. #include <DHT.h>
  37.  
  38. /****** FUNCTION PROTOTYPES *****/
  39. void setup(void);
  40. void loop(void);
  41. void water_level(void);
  42. void water_temp(void);
  43.  
  44. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  45. const uint8_t myUS_HC_SR04_Echo_PIN_D5 = 5;
  46. const uint8_t myDHT_DHT22_DOUT_PIN_D8 = 8;
  47.  
  48. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  49. const uint8_t myUS_HC_SR04_Trigger_PIN_D4 = 4;
  50. const uint8_t buzzer_PIN = 9;
  51. const uint8_t red_LED_PIN = 10;
  52. const uint8_t blue_LED_PIN = 11;
  53.  
  54. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  55. Ultrasonic ultrasonic(myUS_HC_SR04_Trigger_PIN_D4, myUS_HC_SR04_Echo_PIN_D5);
  56. DHT dht(myDHT_DHT22_DOUT_PIN_D8, DHT22);
  57.  
  58. void setup(void)
  59. {
  60.   // put your setup code here, to run once:
  61.   pinMode(myUS_HC_SR04_Echo_PIN_D5, INPUT);
  62.   pinMode(myUS_HC_SR04_Trigger_PIN_D4, OUTPUT);
  63.   pinMode(buzzer_PIN, OUTPUT);
  64.   pinMode(red_LED_PIN, OUTPUT);
  65.   pinMode(blue_LED_PIN, OUTPUT);
  66.  
  67.   dht.begin();
  68.  
  69.   Serial.begin(9600);
  70. }
  71.  
  72. void loop(void)
  73. {
  74.   // put your main code here, to run repeatedly:
  75.   water_level();
  76.   water_temp();
  77.   delay(1000);
  78. }
  79.  
  80. void water_level(void)
  81. {
  82.   unsigned int distance = ultrasonic.read();
  83.  
  84.   if (distance > 30)
  85.   {
  86.     Serial.println("Water Overflow");
  87.     digitalWrite(buzzer_PIN, HIGH);
  88.   }
  89.   else if (distance < 15)
  90.   {
  91.     Serial.println("Water Underflow");
  92.     digitalWrite(buzzer_PIN, HIGH);
  93.   }
  94.   else
  95.   {
  96.     digitalWrite(buzzer_PIN, LOW);
  97.   }
  98. }
  99.  
  100. void water_temp(void)
  101. {
  102.   float temperature = dht.readTemperature();
  103.  
  104.   if (temperature > 27)
  105.   {
  106.     Serial.println("High Temperature");
  107.     digitalWrite(red_LED_PIN, HIGH);
  108.     digitalWrite(blue_LED_PIN, LOW);
  109.   }
  110.   else if (temperature < 25)
  111.   {
  112.     Serial.println("Low Temperature");
  113.     digitalWrite(red_LED_PIN, LOW);
  114.     digitalWrite(blue_LED_PIN, HIGH);
  115.   }
  116.   else
  117.   {
  118.     digitalWrite(red_LED_PIN, LOW);
  119.     digitalWrite(blue_LED_PIN, LOW);
  120.   }
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement