Advertisement
pleasedontcode

Fish Pond Monitoring System

Jan 10th, 2024
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 5.21 KB | Source Code | 0 0
  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: Pond_monitoring
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-04 10:30:56
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Ultrasonic sensor measure distance. If distance is */
  21.     /* greater than 30cm print distance and print */
  22.     /* underflow turn on red led turn on servo */
  23. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* Ultrasonic sensor measures distance if distance */
  25.     /* less than 15cm print distance print overflow turn */
  26.     /* red led on turn servo on */
  27. /****** SYSTEM REQUIREMENT 3 *****/
  28.     /* Servo motor turns 180 degrees when on */
  29. /****** SYSTEM REQUIREMENT 4 *****/
  30.     /* ultrasonic sensor if distance is between 16 and 29 */
  31.     /* print distance print optimum level turn on green */
  32.     /* led. */
  33. /****** SYSTEM REQUIREMENT 5 *****/
  34.     /* all readings and actions from the DHT to be */
  35.     /* recorded and carried out in a function called */
  36.     /* water_temp */
  37. /****** SYSTEM REQUIREMENT 6 *****/
  38.     /* all readings and actions from the Ultrasonic */
  39.     /* sensor to be recorded and carried out in a */
  40.     /* function called water_level */
  41. /****** SYSTEM REQUIREMENT 7 *****/
  42.     /* Take readings at intervals of 3 seconds */
  43. /****** SYSTEM REQUIREMENT 8 *****/
  44.     /* DHT measures temperature. If temp is greater than */
  45.     /* 32 degrees celcius print  temp and print high temp */
  46.     /* if temp less than 25 degrees prints temp and print */
  47.     /* low temp else print temp and print optimum temp */
  48. /****** END SYSTEM REQUIREMENTS *****/
  49.  
  50. /****** DEFINITION OF LIBRARIES *****/
  51. #include <Arduino.h>
  52. #include <Ultrasonic.h>
  53. #include <Servo.h>
  54. #include <DHT.h>
  55.  
  56. /****** FUNCTION PROTOTYPES *****/
  57. void setup(void);
  58. void loop(void);
  59. void water_temp(void);
  60. void water_level(void);
  61.  
  62. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  63. const uint8_t myultrasonic_HC_SR04_Echo_PIN_D3 = 3;
  64. const uint8_t myDHT_DHT11_DOUT_PIN_D4 = 4;
  65.  
  66. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  67. const uint8_t myultrasonic_HC_SR04_Trigger_PIN_D2 = 2;
  68. const uint8_t red_LED_PIN_D6 = 6;
  69. const uint8_t red_LED_PIN_D7 = 7;
  70. const uint8_t green_LED_PIN_D8 = 8;
  71.  
  72. /***** DEFINITION OF PWM OUTPUT PINS *****/
  73. const uint8_t myservo_Servomotor_PWMSignal_PIN_D5 = 5;
  74.  
  75. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  76. Ultrasonic ultrasonic(myultrasonic_HC_SR04_Trigger_PIN_D2, myultrasonic_HC_SR04_Echo_PIN_D3);
  77. Servo servo;
  78. DHT dht(myDHT_DHT11_DOUT_PIN_D4, DHT11);
  79.  
  80. void setup(void)
  81. {
  82.   // put your setup code here, to run once:
  83.   pinMode(myultrasonic_HC_SR04_Echo_PIN_D3, INPUT);
  84.   pinMode(myDHT_DHT11_DOUT_PIN_D4, INPUT_PULLUP);
  85.  
  86.   pinMode(myultrasonic_HC_SR04_Trigger_PIN_D2, OUTPUT);
  87.   pinMode(red_LED_PIN_D6, OUTPUT);
  88.   pinMode(red_LED_PIN_D7, OUTPUT);
  89.   pinMode(green_LED_PIN_D8, OUTPUT);
  90.   pinMode(myservo_Servomotor_PWMSignal_PIN_D5, OUTPUT);
  91.  
  92.   servo.attach(myservo_Servomotor_PWMSignal_PIN_D5);
  93.  
  94.   dht.begin();
  95.  
  96.   Serial.begin(9600); // Initialize serial communication
  97. }
  98.  
  99. void loop(void)
  100. {
  101.   // put your main code here, to run repeatedly:
  102.   water_temp();
  103.   water_level();
  104.   delay(3000);
  105. }
  106.  
  107. void water_temp(void)
  108. {
  109.   float temperature = dht.readTemperature();
  110.  
  111.   if (temperature > 32)
  112.   {
  113.     Serial.print("Temperature: ");
  114.     Serial.print(temperature);
  115.     Serial.println("°C - High Temperature");
  116.   }
  117.   else if (temperature < 25)
  118.   {
  119.     Serial.print("Temperature: ");
  120.     Serial.print(temperature);
  121.     Serial.println("°C - Low Temperature");
  122.   }
  123.   else
  124.   {
  125.     Serial.print("Temperature: ");
  126.     Serial.print(temperature);
  127.     Serial.println("°C - Optimum Temperature");
  128.   }
  129. }
  130.  
  131. void water_level(void)
  132. {
  133.   unsigned int distance = ultrasonic.read();
  134.  
  135.   if (distance > 30)
  136.   {
  137.     Serial.print("Distance: ");
  138.     Serial.print(distance);
  139.     Serial.println(" cm - Overflow");
  140.     digitalWrite(red_LED_PIN_D6, HIGH);
  141.     digitalWrite(red_LED_PIN_D7, LOW);
  142.     digitalWrite(green_LED_PIN_D8, LOW);
  143.     servo.write(180);
  144.   }
  145.   else if (distance < 15)
  146.   {
  147.     Serial.print("Distance: ");
  148.     Serial.print(distance);
  149.     Serial.println(" cm - Underflow");
  150.     digitalWrite(red_LED_PIN_D6, LOW);
  151.     digitalWrite(red_LED_PIN_D7, HIGH);
  152.     digitalWrite(green_LED_PIN_D8, LOW);
  153.     servo.write(180);
  154.   }
  155.   else if (distance >= 16 && distance <= 29)
  156.   {
  157.     Serial.print("Distance: ");
  158.     Serial.print(distance);
  159.     Serial.println(" cm - Optimum Level");
  160.     digitalWrite(red_LED_PIN_D6, LOW);
  161.     digitalWrite(red_LED_PIN_D7, LOW);
  162.     digitalWrite(green_LED_PIN_D8, HIGH);
  163.     servo.write(0);
  164.   }
  165.   else
  166.   {
  167.     Serial.print("Distance: ");
  168.     Serial.print(distance);
  169.     Serial.println(" cm");
  170.     digitalWrite(red_LED_PIN_D6, LOW);
  171.     digitalWrite(red_LED_PIN_D7, LOW);
  172.     digitalWrite(green_LED_PIN_D8, LOW);
  173.     servo.write(0);
  174.   }
  175. }
  176.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement