#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
const int flowSensorPin = A5; // Connect your flow sensor to analog pin A5
const int servoPin = 9; // Connect your servo motor to digital pin 9
Servo myServo;
// Initialize the LCD with its I2C address (modify according to your LCD)
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
myServo.attach(servoPin);
lcd.begin(16, 2); // Initialize the LCD
lcd.print("Flow: ");
}
void loop() {
// Read the flow rate from the analog pin A5
int flowRate = analogRead(flowSensorPin);
// Map the flow rate to the servo angle (adjust these values based on your requirements)
int servoAngle = map(flowRate, 0, 1023, 0, 180);
// Set the servo angle
myServo.write(servoAngle);
// Display flow rate and servo speed on the LCD
lcd.setCursor(6, 0);
lcd.print(flowRate);
lcd.setCursor(0, 1);
lcd.print("Servo Speed: ");
lcd.print(servoAngle);
// Print the flow rate and servo angle to the serial monitor for debugging
Serial.print("Flow Rate: ");
Serial.print(flowRate);
Serial.print(", Servo Angle: ");
Serial.println(servoAngle);
delay(1000); // Adjust the delay based on your requirements
}