0% found this document useful (0 votes)
5 views2 pages

Arduino Test final no lcd

Uploaded by

yejixx999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Arduino Test final no lcd

Uploaded by

yejixx999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

const int sensor1Pin = A0; // Analog pin for moisture sensor

const int outputPin1 = 3; // Digital pin for controlling an output (e.g., an


LED)
int moistureValue;

// Sensor 2 Setup
const int sensor2Pin = A1; // Analog pin for moisture sensor
const int outputPin2 = 4; // Digital pin for controlling an output (e.g., an
LED)
int moistureValue2;

// Sensor 3 Setup
const int sensor3Pin = A3; // Analog pin for the water level sensor
const int buzzerPin = 8; // Digital pin for the buzzer
const int threshold = 500; // Threshold for the water level sensor

void setup() {
pinMode(outputPin1, OUTPUT);
pinMode(outputPin2, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
Serial.println("Reading from sensors...");
}

void loop() {
// Reading from Sensor 1
moistureValue = analogRead(sensor1Pin);
moistureValue = map(moistureValue, 550, 10, 0, 100);
Serial.print("Moisture: ");
Serial.print(moistureValue);
Serial.println("%");

if (moistureValue > 0) {
digitalWrite(outputPin1, HIGH); // Turn on the output if moisture value is
above 0
} else {
digitalWrite(outputPin1, LOW); // Turn off the output if moisture value is 0
or below
}

// Reading from Sensor 2


moistureValue2 = analogRead(sensor2Pin);
moistureValue2 = map(moistureValue2, 550, 10, 0, 100);
Serial.print("Moisture: ");
Serial.print(moistureValue2);
Serial.println("%");

if (moistureValue2 > 0) {
digitalWrite(outputPin2, HIGH); // Turn on the output if moisture value is
above 0
} else {
digitalWrite(outputPin2, LOW); // Turn off the output if moisture value is 0
or below
}

// Reading from Sensor 3


int sensor3Value = analogRead(sensor3Pin);
Serial.print("Sensor 3 Value: ");
Serial.println(sensor3Value);
if (sensor3Value < threshold) {
digitalWrite(buzzerPin, HIGH); // Turn buzzer on
} else {
digitalWrite(buzzerPin, HIGH); // Turn buzzer on for 200ms
delay(200);
digitalWrite(buzzerPin, LOW); // Turn buzzer off
delay(200);
}

delay(1000); // Delay for stability


}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy