Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Pond_monitoring
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-01-04 10:30:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Ultrasonic sensor measure distance. If distance is */
- /* greater than 30cm print distance and print */
- /* underflow turn on red led turn on servo */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* Ultrasonic sensor measures distance if distance */
- /* less than 15cm print distance print overflow turn */
- /* red led on turn servo on */
- /****** SYSTEM REQUIREMENT 3 *****/
- /* Servo motor turns 180 degrees when on */
- /****** SYSTEM REQUIREMENT 4 *****/
- /* ultrasonic sensor if distance is between 16 and 29 */
- /* print distance print optimum level turn on green */
- /* led. */
- /****** SYSTEM REQUIREMENT 5 *****/
- /* all readings and actions from the DHT to be */
- /* recorded and carried out in a function called */
- /* water_temp */
- /****** SYSTEM REQUIREMENT 6 *****/
- /* all readings and actions from the Ultrasonic */
- /* sensor to be recorded and carried out in a */
- /* function called water_level */
- /****** SYSTEM REQUIREMENT 7 *****/
- /* Take readings at intervals of 3 seconds */
- /****** SYSTEM REQUIREMENT 8 *****/
- /* DHT measures temperature. If temp is greater than */
- /* 32 degrees celcius print temp and print high temp */
- /* if temp less than 25 degrees prints temp and print */
- /* low temp else print temp and print optimum temp */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <Ultrasonic.h>
- #include <Servo.h>
- #include <DHT.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void water_temp(void);
- void water_level(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t myultrasonic_HC_SR04_Echo_PIN_D3 = 3;
- const uint8_t myDHT_DHT11_DOUT_PIN_D4 = 4;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t myultrasonic_HC_SR04_Trigger_PIN_D2 = 2;
- const uint8_t red_LED_PIN_D6 = 6;
- const uint8_t red_LED_PIN_D7 = 7;
- const uint8_t green_LED_PIN_D8 = 8;
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t myservo_Servomotor_PWMSignal_PIN_D5 = 5;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- Ultrasonic ultrasonic(myultrasonic_HC_SR04_Trigger_PIN_D2, myultrasonic_HC_SR04_Echo_PIN_D3);
- Servo servo;
- DHT dht(myDHT_DHT11_DOUT_PIN_D4, DHT11);
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(myultrasonic_HC_SR04_Echo_PIN_D3, INPUT);
- pinMode(myDHT_DHT11_DOUT_PIN_D4, INPUT_PULLUP);
- pinMode(myultrasonic_HC_SR04_Trigger_PIN_D2, OUTPUT);
- pinMode(red_LED_PIN_D6, OUTPUT);
- pinMode(red_LED_PIN_D7, OUTPUT);
- pinMode(green_LED_PIN_D8, OUTPUT);
- pinMode(myservo_Servomotor_PWMSignal_PIN_D5, OUTPUT);
- servo.attach(myservo_Servomotor_PWMSignal_PIN_D5);
- dht.begin();
- Serial.begin(9600); // Initialize serial communication
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- water_temp();
- water_level();
- delay(3000);
- }
- void water_temp(void)
- {
- float temperature = dht.readTemperature();
- if (temperature > 32)
- {
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println("°C - High Temperature");
- }
- else if (temperature < 25)
- {
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println("°C - Low Temperature");
- }
- else
- {
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println("°C - Optimum Temperature");
- }
- }
- void water_level(void)
- {
- unsigned int distance = ultrasonic.read();
- if (distance > 30)
- {
- Serial.print("Distance: ");
- Serial.print(distance);
- Serial.println(" cm - Overflow");
- digitalWrite(red_LED_PIN_D6, HIGH);
- digitalWrite(red_LED_PIN_D7, LOW);
- digitalWrite(green_LED_PIN_D8, LOW);
- servo.write(180);
- }
- else if (distance < 15)
- {
- Serial.print("Distance: ");
- Serial.print(distance);
- Serial.println(" cm - Underflow");
- digitalWrite(red_LED_PIN_D6, LOW);
- digitalWrite(red_LED_PIN_D7, HIGH);
- digitalWrite(green_LED_PIN_D8, LOW);
- servo.write(180);
- }
- else if (distance >= 16 && distance <= 29)
- {
- Serial.print("Distance: ");
- Serial.print(distance);
- Serial.println(" cm - Optimum Level");
- digitalWrite(red_LED_PIN_D6, LOW);
- digitalWrite(red_LED_PIN_D7, LOW);
- digitalWrite(green_LED_PIN_D8, HIGH);
- servo.write(0);
- }
- else
- {
- Serial.print("Distance: ");
- Serial.print(distance);
- Serial.println(" cm");
- digitalWrite(red_LED_PIN_D6, LOW);
- digitalWrite(red_LED_PIN_D7, LOW);
- digitalWrite(green_LED_PIN_D8, LOW);
- servo.write(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement