// Define the pin numbers for easier reference
const int buttonPin = 7; // Button connected to digital pin D7
const int outputPin8 = 8; // Digital pin D8
const int outputPin9 = 9; // Digital pin D9
const int analogPin = A0; // Analog input pin A0
void setup() {
// Configure the digital pins
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP); // Set D7 as input with internal pull-up resistor
pinMode(outputPin8, INPUT); // Set D8 as input
pinMode(outputPin9, OUTPUT); // Set D9 as output
// Initialize D9 to LOW
digitalWrite(outputPin9, LOW);
}
void loop() {
// Continuously monitor the voltage on A0
float voltage = analogRead(analogPin) * (5.0 / 1023.0); // Convert analog reading to voltage
// Check if the button is pressed (buttonPin will read LOW when pressed due to pull-up resistor)
if (digitalRead(buttonPin) == LOW) {
// Monitor A0 until the voltage drops below 1V
while (voltage >= 1.0) {
voltage = analogRead(analogPin) * (5.0 / 1023.0); // Continuously update voltage reading
Serial.println(voltage);
delay(200);
}
// When voltage drops below 1V, set D8 to LOW
digitalWrite(outputPin8, LOW);
}
// If A0 voltage drops below 0.1V, set D9 to HIGH
if (voltage < 0.1) {
digitalWrite(outputPin9, HIGH);
}
// Delay for 1000 milliseconds (1 second)
delay(2000);
digitalWrite(outputPin9, LOW);
}