// Pin definitions
const int turbidityPin = A0; // Analog input pin for turbidity sensor
const int buzzerPin = 8; // Digital output pin for the buzzer
// Threshold for turbidity level (can be adjusted based on sensor calibration)
const int turbidityThreshold = 500; // Adjust this value based on your sensor calibration
void setup() {
// Start the serial communication
[Link](9600);
// Set the buzzer pin as output
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Read the turbidity level from the sensor
int turbidityValue = analogRead(turbidityPin);
// Print the turbidity value to the Serial Monitor (optional)
[Link]("Turbidity Level: ");
[Link](turbidityValue);
// If the turbidity level exceeds the threshold, sound the buzzer
if (turbidityValue > turbidityThreshold) {
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
} else {
digitalWrite(buzzerPin, LOW); // Turn off buzzer
}
// Delay for a short period before the next reading
delay(500);
}