Advertisement
pleasedontcode

Ultrasonic Monitoring rev_02

Jan 1st, 2024
88
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: Ultrasonic Monitoring
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-01 11:27:27
  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. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Arduino.h>
  27. #include <Ultrasonic.h>
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t myUS_HC_SR04_Echo_PIN_D3 = 3;
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t myUS_HC_SR04_Trigger_PIN_D2 = 2;
  38.  
  39. /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
  40. Ultrasonic ultrasonic(myUS_HC_SR04_Trigger_PIN_D2, myUS_HC_SR04_Echo_PIN_D3);
  41.  
  42. void setup(void)
  43. {
  44.   // put your setup code here, to run once:
  45.   pinMode(myUS_HC_SR04_Echo_PIN_D3, INPUT);
  46.   pinMode(myUS_HC_SR04_Trigger_PIN_D2, OUTPUT);
  47.   Serial.begin(9600);
  48. }
  49.  
  50. void loop(void)
  51. {
  52.   // put your main code here, to run repeatedly:
  53.   unsigned int distance = ultrasonic.read();
  54.  
  55.   if (distance > 30)
  56.   {
  57.     Serial.println("Warning: Overflow!");
  58.   }
  59.   else if (distance < 15)
  60.   {
  61.     Serial.println("Warning: Underflow!");
  62.   }
  63.  
  64.   delay(1000);
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement