CCCPaste

Flow Monitor rev_160

/********* 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: Flow Monitor
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2023-12-07 00:25:02

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* read flow meter and print on serial monitor. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t flowmeter_YF_S401_OUT_PIN_D4 = 4;

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t VERDE_LED_PIN_D11 = 11;
const uint8_t ROSSO_LED_PIN_D12 = 12;

/****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
Ultrasonic ultrasonic(12, 13); // Initialize Ultrasonic library object with trigger and echo pins

void setup(void)
{
  // put your setup code here, to run once:
  pinMode(flowmeter_YF_S401_OUT_PIN_D4, INPUT);
  pinMode(VERDE_LED_PIN_D11, OUTPUT);
  pinMode(ROSSO_LED_PIN_D12, OUTPUT);
  Serial.begin(9600);
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  int flowValue = digitalRead(flowmeter_YF_S401_OUT_PIN_D4);

  if (flowValue == HIGH) {
    digitalWrite(VERDE_LED_PIN_D11, HIGH);
    digitalWrite(ROSSO_LED_PIN_D12, LOW);
  } else {
    digitalWrite(VERDE_LED_PIN_D11, LOW);
    digitalWrite(ROSSO_LED_PIN_D12, HIGH);
  }

  Serial.print("Flow Meter: ");
  Serial.println(flowValue);

  // Read the distance from the ultrasonic sensor
  unsigned int distance = ultrasonic.read();

  Serial.print("Distance in CM: ");
  Serial.println(distance);

  delay(1000);
}