#include <WiFi.h>
const int numLeds = 3;
const int ledPins[numLeds] = {2, 4, 5}; // Pins to which the LEDs are connected
const int numSensors = 4;
const int sensors[numSensors] = {32, 33, 34, 35}; // ADC input pins
int values[numSensors]; // Array to store potentiometer values
int choice = 0; // Variable to store the choice
int total = 0; // Variable to store the total of the values
int percent = 0;
void setup() {
// Set up serial communication
Serial.begin(9600);
// Set the LED pins as outputs
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Read ADC values from all sensors
for (int j = 0; j < numSensors; j++) {
values[j] = analogRead(sensors[j]);
}
// Add the sensor values
total = values[0] + values[1] + values[2] + values[3];
percent = map(total,0,16383,0,100);
// Print the total to the serial console
Serial.printf("The value is: %d %% \n", percent);
// Determine the choice based on the potentiometer values
if (percent > 70) {
Serial.println("Heavy");
choice = 1;
} else if (percent <30) {
Serial.println("Drizzle");
choice = 2;
} else {
Serial.println("Medium");
choice = 3;
}
// Turn on the appropriate LEDs based on the choice
switch (choice) {
case 1:
// Turn on all LEDs
for (int k = 0; k < 3; k++) { // Loop 10 times
digitalWrite(ledPins[2], HIGH); // Turn the LED on
delay(500); // Delay for 1 second
digitalWrite(ledPins[2], LOW); // Turn the LED off
delay(500); // Delay for 1 second
}
break;
case 2:
// Turn on only the first and second LEDs
for (int k = 0; k < 3; k++) { // Loop 10 times
digitalWrite(ledPins[0], HIGH); // Turn the LED on
delay(500); // Delay for 1 second
digitalWrite(ledPins[0], LOW); // Turn the LED off
delay(500); // Delay for 1 second
}
break;
case 3:
// Turn on only the third LED
for (int k = 0; k < 3; k++) { // Loop 10 times
digitalWrite(ledPins[1], HIGH); // Turn the LED on
delay(500); // Delay for 1 second
digitalWrite(ledPins[1], LOW); // Turn the LED off
delay(500); // Delay for 1 second
}
break;
}
delay(1000); // Delay for 1 second
}