Arduino Test final
Arduino Test final
// 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 = A2; // 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
}
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
}
and this
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Create an LCD object with I2C address 0x27 (common for many I2C LCDs)
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize the LCD
lcd.begin();
lcd.backlight(); // Turn on the backlight (if applicable)
void loop() {
// Read the moisture levels from the sensors
int sensor1Value = analogRead(sensor1Pin);
int sensor2Value = analogRead(sensor2Pin);
int sensor3Value = analogRead(sensor3Pin);