0% found this document useful (0 votes)
2 views1 page

Arduino Code

The document is a code snippet for an Arduino program that reads turbidity levels from a sensor and activates a buzzer if the levels exceed a defined threshold. It initializes the necessary pins and sets up serial communication for monitoring. The loop continuously checks the turbidity level and controls the buzzer accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Arduino Code

The document is a code snippet for an Arduino program that reads turbidity levels from a sensor and activates a buzzer if the levels exceed a defined threshold. It initializes the necessary pins and sets up serial communication for monitoring. The loop continuously checks the turbidity level and controls the buzzer accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

// 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
Serial.begin(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)


Serial.print("Turbidity Level: ");
Serial.println(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);
}

You might also like