Advertisement
pleasedontcode

Flow Monitor rev_160

Dec 6th, 2023
85
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: Flow Monitor
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-07 00:25:02
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* read flow meter and print on serial monitor. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <Ultrasonic.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t flowmeter_YF_S401_OUT_PIN_D4 = 4;
  33.  
  34. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  35. const uint8_t VERDE_LED_PIN_D11 = 11;
  36. const uint8_t ROSSO_LED_PIN_D12 = 12;
  37.  
  38. /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
  39. Ultrasonic ultrasonic(12, 13); // Initialize Ultrasonic library object with trigger and echo pins
  40.  
  41. void setup(void)
  42. {
  43.   // put your setup code here, to run once:
  44.   pinMode(flowmeter_YF_S401_OUT_PIN_D4, INPUT);
  45.   pinMode(VERDE_LED_PIN_D11, OUTPUT);
  46.   pinMode(ROSSO_LED_PIN_D12, OUTPUT);
  47.   Serial.begin(9600);
  48. }
  49.  
  50. void loop(void)
  51. {
  52.   // put your main code here, to run repeatedly:
  53.   int flowValue = digitalRead(flowmeter_YF_S401_OUT_PIN_D4);
  54.  
  55.   if (flowValue == HIGH) {
  56.     digitalWrite(VERDE_LED_PIN_D11, HIGH);
  57.     digitalWrite(ROSSO_LED_PIN_D12, LOW);
  58.   } else {
  59.     digitalWrite(VERDE_LED_PIN_D11, LOW);
  60.     digitalWrite(ROSSO_LED_PIN_D12, HIGH);
  61.   }
  62.  
  63.   Serial.print("Flow Meter: ");
  64.   Serial.println(flowValue);
  65.  
  66.   // Read the distance from the ultrasonic sensor
  67.   unsigned int distance = ultrasonic.read();
  68.  
  69.   Serial.print("Distance in CM: ");
  70.   Serial.println(distance);
  71.  
  72.   delay(1000);
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement