Advertisement
pleasedontcode

"Water Leveler" rev_03

Jan 1st, 2024
94
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: "Water Leveler"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-01 11:38:07
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Measure the distance   If distance is greater than */
  21.     /* 30 cm print "warning overflow"  if distance is */
  22.     /* less than 15cm print "warning underflow" */
  23. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* Ultrasonic sensor to measure distance  If distance */
  25.     /* is more than 30cm print "warning overflow"  If */
  26.     /* distance is less than 30 cm print "warning */
  27.     /* underflow"    create code as a function named */
  28.     /* water_level */
  29. /****** END SYSTEM REQUIREMENTS *****/
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <Arduino.h>
  33. #include <Ultrasonic.h>
  34.  
  35. /********** FUNCTION PROTOTYPES **********/
  36. void setup(void);
  37. void loop(void);
  38. void water_level(void);
  39.  
  40. /********** DEFINITION OF DIGITAL INPUT PINS **********/
  41. const uint8_t myUS_HC_SR04_Echo_PIN_D3 = 3;
  42.  
  43. /********** DEFINITION OF DIGITAL OUTPUT PINS **********/
  44. const uint8_t myUS_HC_SR04_Trigger_PIN_D2 = 2;
  45.  
  46. /********** DEFINITION OF LIBRARIES CLASS INSTANCES **********/
  47. Ultrasonic ultrasonic(myUS_HC_SR04_Trigger_PIN_D2, myUS_HC_SR04_Echo_PIN_D3);
  48.  
  49. void setup(void)
  50. {
  51.   // put your setup code here, to run once:
  52.   pinMode(myUS_HC_SR04_Echo_PIN_D3, INPUT);
  53.   pinMode(myUS_HC_SR04_Trigger_PIN_D2, OUTPUT);
  54.   Serial.begin(9600);
  55. }
  56.  
  57. void loop(void)
  58. {
  59.   // put your main code here, to run repeatedly:
  60.   water_level();
  61.   delay(1000);
  62. }
  63.  
  64. void water_level(void)
  65. {
  66.   int distance = ultrasonic.read();
  67.   Serial.print("Distance in CM: ");
  68.   Serial.println(distance);
  69.  
  70.   if (distance > 30)
  71.   {
  72.     Serial.println("Warning: Overflow");
  73.   }
  74.   else if (distance < 15)
  75.   {
  76.     Serial.println("Warning: Underflow");
  77.   }
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement